mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 10:32:15 +02:00
Add more input fields and UI modes, refactor names
This commit is contained in:
parent
56e51e37d1
commit
2413bef818
@ -1,69 +1,87 @@
|
|||||||
/**
|
/**
|
||||||
* @file psel.h
|
* @file psel.h
|
||||||
* @brief Wrapper for using playerSelect applet (user selection applet).
|
* @brief Wrapper for using playerSelect (user selection applet).
|
||||||
* @author XorTroll
|
* @author XorTroll
|
||||||
* @copyright libnx Authors
|
* @copyright libnx Authors
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "../services/applet.h"
|
#include "../services/applet.h"
|
||||||
#include "../services/set.h"
|
#include "../services/acc.h"
|
||||||
|
|
||||||
// playerSelect applet modes. There are more of them related to network accounts.
|
// playerSelect UI modes.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PselMode_Normal = 0, ///< Simple user selection (new users cannot be created).
|
PselUiMode_SelectUser = 0, ///< Simple user selection (new users cannot be created).
|
||||||
PselMode_UserCreation = 1, ///< Only user creation (the user is later returned).
|
PselUiMode_UserCreation = 1, ///< Only user creation (the user is later returned).
|
||||||
PselMode_ForStarter = 5, ///< Mode "starter" uses to register the console's first user on the initial setup
|
PselUiMode_EnsureNsaAvailable = 2, ///< EnsureNsaAvailable
|
||||||
} PselMode;
|
PselUiMode_IconEditor = 3, ///< IconEditor
|
||||||
|
PselUiMode_NicknameEditor = 4, ///< NicknameEditor
|
||||||
|
PselUiMode_ForStarter = 5, ///< Mode "starter" uses to register the console's first user on the initial setup
|
||||||
|
PselUiMode_NetworkServiceAccountRegistration = 8, ///< NetworkServiceAccountRegistration
|
||||||
|
PselUiMode_NintendoAccountNnidLinker = 9, ///< NintendoAccountNnidLinker
|
||||||
|
PselUiMode_LicenseRequirementsForNetworkService = 10, ///< LicenseRequirementsForNetworkService
|
||||||
|
PselUiMode_NaLoginTest = 12, ///< NaLoginTest
|
||||||
|
} PselUiMode;
|
||||||
|
|
||||||
// Config data for playerSelect applet.
|
// UI settings for playerSelect.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 mode; ///< Mode, see \ref PselMode.
|
u32 mode; ///< UI mode, see \ref PselUiMode.
|
||||||
u8 unk1[0x8f]; ///< Unknown
|
u32 dialogType; ///< Dialog type
|
||||||
u8 userCreationFlag; ///< If set, a new user can be created and chosen (for ::PselMode_Normal).
|
u128 invalidUserList[ACC_USER_LIST_SIZE]; ///< List of user IDs which will be disabled.
|
||||||
u8 omitOptionFlag; ///< If set, an "Omit" button is shown.
|
u8 unk1[8]; ///< Unknown.
|
||||||
u8 unk2[11]; ///< Unknown
|
u8 networkServiceRequired; ///< Whether the user needs to be linked to a Nintendo account.
|
||||||
} PselUserSelectionConfig;
|
u8 unk2[2]; ///< Unknown.
|
||||||
|
u8 allowUserCreation; ///< (With ::PselUiMode_SelectUser) enables the option to create a new user.
|
||||||
|
u8 skipEnabled; ///< Enables the option to skip user selection (a new button is shown)
|
||||||
|
u8 unk3[11]; ///< Unknown.
|
||||||
|
} PselUiSettings;
|
||||||
|
|
||||||
// Result data returned after execution.
|
// Result data sent after execution.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 result; ///< Result (0 = Success, 2 = Failure)
|
u32 result; ///< Result code.
|
||||||
u128 userId; ///< UUID of selected user
|
u128 userId; ///< Selected user ID.
|
||||||
} PselResult;
|
} PselResult;
|
||||||
|
|
||||||
// Config holder structure.
|
|
||||||
typedef struct {
|
|
||||||
PselUserSelectionConfig config; ///< User selection config
|
|
||||||
} PselConfig;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new config for playerSelect applet with the specified mode.
|
* @brief Creates a new UI config for playerSelect applet with the specified mode.
|
||||||
* @param c PselConfig struct.
|
* @param ui PseluiSettings struct.
|
||||||
* @param mode playerSelect applet mode.
|
* @param mode playerSelect UI mode.
|
||||||
*/
|
*/
|
||||||
Result pselConfigCreate(PselConfig *c, PselMode mode);
|
Result pselUiCreate(PselUiSettings *ui, PselUiMode mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the UserCreation flag.
|
* @brief Adds a user to the invalid user list (these users will be blacklisted in the applet)
|
||||||
* @param c PselConfig struct.
|
* @param ui PselUiSettings struct.
|
||||||
|
* @param user_id user ID.
|
||||||
|
*/
|
||||||
|
void pselUiAddInvalidUser(PselUiSettings *ui, u128 user_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets whether users can be created in the applet
|
||||||
|
* @param ui PselUiSettings struct.
|
||||||
|
* @param flag Flag value.
|
||||||
|
* @note Only used for ::PselUiMode_SelectUser
|
||||||
|
*/
|
||||||
|
void pselUiSetAllowUserCreation(PselUiSettings *ui, bool flag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets whether users need to be linked to a Nintendo account.
|
||||||
|
* @param ui PselUiSettings struct.
|
||||||
* @param flag Flag value.
|
* @param flag Flag value.
|
||||||
*/
|
*/
|
||||||
static inline void pselConfigSetUserCreationFlag(PselConfig *c, bool flag) {
|
void pselUiSetNetworkServiceRequired(PselUiSettings *ui, bool flag);
|
||||||
c->config.userCreationFlag = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the OmitOption flag.
|
* @brief Sets whether selection can be skipped (with a new button)
|
||||||
* @param c PselConfig struct.
|
* @param ui PselUiSettings struct.
|
||||||
* @param flag Flag value.
|
* @param flag Flag value.
|
||||||
*/
|
*/
|
||||||
static inline void pselConfigSetOmitOptionFlag(PselConfig *c, bool flag) {
|
void pselUiSetSkipEnabled(PselUiSettings *ui, bool flag);
|
||||||
c->config.omitOptionFlag = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Shows the applet with the specified config.
|
* @brief Shows the applet with the specified UI settings.
|
||||||
* @param c PselConfig struct.
|
* @param ui PselUiSettings struct.
|
||||||
* @param out_uid Output user ID.
|
* @param out_uid Selected user ID.
|
||||||
|
* @note If user skips (see \ref pselUiSetSkipEnabled) this will return successfully but the output ID will be 0.
|
||||||
*/
|
*/
|
||||||
Result pselConfigShow(PselConfig *c, u128 *out_uid);
|
Result pselUiShow(PselUiSettings *ui, u128 *out_user);
|
@ -7,24 +7,59 @@
|
|||||||
#include "applets/psel.h"
|
#include "applets/psel.h"
|
||||||
#include "runtime/hosversion.h"
|
#include "runtime/hosversion.h"
|
||||||
|
|
||||||
Result pselConfigCreate(PselConfig *c, PselMode mode) {
|
Result pselUiCreate(PselUiSettings *ui, PselUiMode mode) {
|
||||||
memset(c, 0, sizeof(PselConfig));
|
memset(ui, 0, sizeof(PselUiSettings));
|
||||||
c->config.mode = mode;
|
ui->mode = mode;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result pselConfigShow(PselConfig *c, u128 *out_uid) {
|
void pselUiAddInvalidUser(PselUiSettings *ui, u128 user_id) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < ACC_USER_LIST_SIZE; i++) {
|
||||||
|
|
||||||
|
if(ui->invalidUserList[i] == 0) {
|
||||||
|
__builtin_memcpy(&ui->invalidUserList[i], &user_id, sizeof(user_id));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pselUiSetAllowUserCreation(PselUiSettings *ui, bool flag) {
|
||||||
|
if(ui->mode == PselUiMode_SelectUser) {
|
||||||
|
ui->allowUserCreation = flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pselUiSetNetworkServiceRequired(PselUiSettings *ui, bool flag) {
|
||||||
|
ui->networkServiceRequired = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pselUiSetSkipEnabled(PselUiSettings *ui, bool flag) {
|
||||||
|
ui->skipEnabled = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 _pselGetLaVersion() {
|
||||||
|
u32 ver = 0;
|
||||||
|
u32 hosver = hosversionGet();
|
||||||
|
if(hosver >= MAKEHOSVERSION(9,0,0)) {
|
||||||
|
ver = 0x20000;
|
||||||
|
}
|
||||||
|
return ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pselUiShow(PselUiSettings *ui, u128 *out_user) {
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
LibAppletArgs args;
|
LibAppletArgs args;
|
||||||
libappletArgsCreate(&args, 0);
|
u32 la_ver = _pselGetLaVersion();
|
||||||
|
libappletArgsCreate(&args, la_ver);
|
||||||
PselResult res;
|
PselResult res;
|
||||||
size_t reply_size;
|
size_t reply_size;
|
||||||
|
|
||||||
rc = libappletLaunch(AppletId_playerSelect, &args, &c->config, sizeof(c->config), &res, sizeof(res), &reply_size);
|
rc = libappletLaunch(AppletId_playerSelect, &args, ui, sizeof(PselUiSettings), &res, sizeof(res), &reply_size);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
if (R_FAILED(res.result)) rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit);
|
if (R_FAILED(res.result)) rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit);
|
||||||
if (R_SUCCEEDED(rc)) *out_uid = res.userId;
|
if (R_SUCCEEDED(rc)) *out_user = res.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
Loading…
Reference in New Issue
Block a user