mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 21:02:39 +02:00
Add psel (playerSelect) support (#335)
* Add psel (playerSelect) support
This commit is contained in:
parent
d94be49cb3
commit
3925e92828
@ -125,6 +125,7 @@ extern "C" {
|
|||||||
#include "switch/applets/album_la.h"
|
#include "switch/applets/album_la.h"
|
||||||
#include "switch/applets/friends_la.h"
|
#include "switch/applets/friends_la.h"
|
||||||
#include "switch/applets/pctlauth.h"
|
#include "switch/applets/pctlauth.h"
|
||||||
|
#include "switch/applets/psel.h"
|
||||||
#include "switch/applets/error.h"
|
#include "switch/applets/error.h"
|
||||||
#include "switch/applets/swkbd.h"
|
#include "switch/applets/swkbd.h"
|
||||||
#include "switch/applets/web.h"
|
#include "switch/applets/web.h"
|
||||||
|
120
nx/include/switch/applets/psel.h
Normal file
120
nx/include/switch/applets/psel.h
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
/**
|
||||||
|
* @file psel.h
|
||||||
|
* @brief Wrapper for using playerSelect (user selection applet).
|
||||||
|
* @author XorTroll
|
||||||
|
* @copyright libnx Authors
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "../types.h"
|
||||||
|
#include "../services/applet.h"
|
||||||
|
#include "../services/acc.h"
|
||||||
|
|
||||||
|
/// playerSelect UI modes.
|
||||||
|
typedef enum {
|
||||||
|
PselUiMode_SelectUser = 0, ///< Simple user selection (new users cannot be created).
|
||||||
|
PselUiMode_UserCreation = 1, ///< Only user creation (the user is later returned).
|
||||||
|
PselUiMode_EnsureNsaAvailable = 2, ///< EnsureNsaAvailable
|
||||||
|
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;
|
||||||
|
|
||||||
|
/// UI settings for playerSelect.
|
||||||
|
typedef struct {
|
||||||
|
u32 mode; ///< UI mode, see \ref PselUiMode.
|
||||||
|
u32 dialogType; ///< Dialog type
|
||||||
|
AccountUid invalidUserList[ACC_USER_LIST_SIZE]; ///< List of \ref AccountUid user IDs which will be disabled.
|
||||||
|
u8 unk_x88[0x8]; ///< Unknown.
|
||||||
|
u8 networkServiceRequired; ///< Whether the user needs to be linked to a Nintendo account.
|
||||||
|
u8 unk_x91[0x2]; ///< 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 unk_x95[0xb]; ///< Unknown.
|
||||||
|
} PselUiSettings;
|
||||||
|
|
||||||
|
/// Result data sent after execution.
|
||||||
|
typedef struct {
|
||||||
|
u32 result; ///< Result code.
|
||||||
|
AccountUid userId; ///< Selected \ref AccountUid.
|
||||||
|
} PselResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates a new UI config for playerSelect applet with the specified mode.
|
||||||
|
* @param ui PseluiSettings struct.
|
||||||
|
* @param mode playerSelect UI mode.
|
||||||
|
*/
|
||||||
|
Result pselUiCreate(PselUiSettings *ui, PselUiMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a user to the user list of the applet.
|
||||||
|
* @param ui PselUiSettings struct.
|
||||||
|
* @param user_id user ID.
|
||||||
|
* @note The users will be treated as invalid users for user selection mode, and as the input user for other modes.
|
||||||
|
*/
|
||||||
|
void pselUiAddUser(PselUiSettings *ui, AccountUid *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
|
||||||
|
*/
|
||||||
|
NX_CONSTEXPR void pselUiSetAllowUserCreation(PselUiSettings *ui, bool flag) {
|
||||||
|
if(ui->mode == PselUiMode_SelectUser) {
|
||||||
|
ui->allowUserCreation = flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets whether users need to be linked to a Nintendo account.
|
||||||
|
* @param ui PselUiSettings struct.
|
||||||
|
* @param flag Flag value.
|
||||||
|
*/
|
||||||
|
NX_CONSTEXPR void pselUiSetNetworkServiceRequired(PselUiSettings *ui, bool flag) {
|
||||||
|
ui->networkServiceRequired = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets whether selection can be skipped (with a new button)
|
||||||
|
* @param ui PselUiSettings struct.
|
||||||
|
* @param flag Flag value.
|
||||||
|
*/
|
||||||
|
NX_CONSTEXPR void pselUiSetSkipEnabled(PselUiSettings *ui, bool flag) {
|
||||||
|
ui->skipEnabled = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shows playerSelect applet with the specified UI settings.
|
||||||
|
* @param ui PselUiSettings struct.
|
||||||
|
* @param out_user Selected user ID.
|
||||||
|
* @note If user skips (see \ref pselUiSetSkipEnabled) this will return successfully but the output ID will be 0.
|
||||||
|
*/
|
||||||
|
Result pselUiShow(PselUiSettings *ui, AccountUid *out_user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shows playerSelect applet to select a user.
|
||||||
|
* @param out_user Returned selected user ID.
|
||||||
|
*/
|
||||||
|
Result pselShowUserSelector(AccountUid *out_user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shows playerSelect applet to create a user.
|
||||||
|
* @param out_user Returned created user ID.
|
||||||
|
*/
|
||||||
|
Result pselShowUserCreator(AccountUid *out_user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shows playerSelect applet to change a user's icon.
|
||||||
|
* @param user Input user ID.
|
||||||
|
*/
|
||||||
|
Result pselShowIconEditor(AccountUid *user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shows playerSelect applet to change a user's nickname.
|
||||||
|
* @param user Input user ID.
|
||||||
|
*/
|
||||||
|
Result pselShowNicknameEditor(AccountUid *user);
|
92
nx/source/applets/psel.c
Normal file
92
nx/source/applets/psel.c
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "types.h"
|
||||||
|
#include "result.h"
|
||||||
|
#include "services/applet.h"
|
||||||
|
#include "services/acc.h"
|
||||||
|
#include "applets/libapplet.h"
|
||||||
|
#include "applets/psel.h"
|
||||||
|
#include "runtime/hosversion.h"
|
||||||
|
|
||||||
|
Result pselUiCreate(PselUiSettings *ui, PselUiMode mode) {
|
||||||
|
memset(ui, 0, sizeof(PselUiSettings));
|
||||||
|
ui->mode = mode;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pselUiAddUser(PselUiSettings *ui, AccountUid *user_id) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < ACC_USER_LIST_SIZE; i++) {
|
||||||
|
|
||||||
|
if(!accountUidIsValid(&ui->invalidUserList[i])) {
|
||||||
|
__builtin_memcpy(&ui->invalidUserList[i], user_id, sizeof(AccountUid));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 _pselGetLaVersion() {
|
||||||
|
u32 ver = 0;
|
||||||
|
u32 hosver = hosversionGet();
|
||||||
|
if(hosver >= MAKEHOSVERSION(9,0,0)) {
|
||||||
|
ver = 0x20000;
|
||||||
|
}
|
||||||
|
return ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pselUiShow(PselUiSettings *ui, AccountUid *out_user) {
|
||||||
|
Result rc = 0;
|
||||||
|
LibAppletArgs args;
|
||||||
|
u32 la_ver = _pselGetLaVersion();
|
||||||
|
libappletArgsCreate(&args, la_ver);
|
||||||
|
PselResult res;
|
||||||
|
size_t reply_size;
|
||||||
|
|
||||||
|
rc = libappletLaunch(AppletId_playerSelect, &args, ui, sizeof(PselUiSettings), &res, sizeof(res), &reply_size);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
if (res.result != 0) rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit);
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
if(out_user) *out_user = res.userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pselShowUserSelector(AccountUid *out_user) {
|
||||||
|
PselUiSettings ui;
|
||||||
|
Result rc = pselUiCreate(&ui, PselUiMode_SelectUser);
|
||||||
|
if(R_SUCCEEDED(rc)) {
|
||||||
|
rc = pselUiShow(&ui, out_user);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pselShowUserCreator(AccountUid *out_user) {
|
||||||
|
PselUiSettings ui;
|
||||||
|
Result rc = pselUiCreate(&ui, PselUiMode_UserCreation);
|
||||||
|
if(R_SUCCEEDED(rc)) {
|
||||||
|
rc = pselUiShow(&ui, out_user);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pselShowIconEditor(AccountUid *user) {
|
||||||
|
PselUiSettings ui;
|
||||||
|
Result rc = pselUiCreate(&ui, PselUiMode_IconEditor);
|
||||||
|
if(R_SUCCEEDED(rc)) {
|
||||||
|
pselUiAddUser(&ui, user);
|
||||||
|
rc = pselUiShow(&ui, NULL);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result pselShowNicknameEditor(AccountUid *user) {
|
||||||
|
PselUiSettings ui;
|
||||||
|
Result rc = pselUiCreate(&ui, PselUiMode_NicknameEditor);
|
||||||
|
if(R_SUCCEEDED(rc)) {
|
||||||
|
pselUiAddUser(&ui, user);
|
||||||
|
rc = pselUiShow(&ui, NULL);
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user