diff --git a/nx/include/switch/services/acc.h b/nx/include/switch/services/acc.h index 35480055..a387b168 100644 --- a/nx/include/switch/services/acc.h +++ b/nx/include/switch/services/acc.h @@ -8,6 +8,8 @@ #include "../types.h" #include "sm.h" +#define ACC_USER_LIST_SIZE 8 + typedef struct { Service s; } AccountProfile; @@ -33,6 +35,15 @@ Result accountInitialize(void); void accountExit(void); Service* accountGetService(void); +/// Get the total number of user profiles +Result accountGetUserCount(s32* user_count); + +/** + * @brief Get a list of all user IDs + * @param userIDs Pointer to array of user IDs, array must be exactly size 8 + */ +Result accountListAllUsers(u128* userIDs); + /// Get the userID for the currently active user. The output userID is only valid when the output account_selected==1, otherwise no user is currently selected. /// An user is only selected when the user-account selection applet was used to select an user at least once before. Result accountGetActiveUser(u128 *userID, bool *account_selected); diff --git a/nx/source/services/acc.c b/nx/source/services/acc.c index 8c5d04b8..30d91a93 100644 --- a/nx/source/services/acc.c +++ b/nx/source/services/acc.c @@ -33,6 +33,81 @@ Service* accountGetService(void) { return &g_accSrv; } +Result accountGetUserCount(s32* user_count) +{ + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 0; + + Result rc = serviceIpcDispatch(&g_accSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u32 user_count; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc)) { + *user_count = resp->user_count; + } + } + + return rc; +} + +Result accountListAllUsers(u128* userIDs) +{ + IpcCommand c; + ipcInitialize(&c); + + Result rc=0; + + size_t bufsize = ACC_USER_LIST_SIZE * sizeof(u128); + + ipcAddRecvStatic(&c, userIDs, bufsize, 0); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 2; + + rc = serviceIpcDispatch(&g_accSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + Result accountGetActiveUser(u128 *userID, bool *account_selected) { IpcCommand c;