mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-06 00:19:22 +02:00
Added account. Added u128 type to types.h.
This commit is contained in:
parent
cb123dd579
commit
a405bc4827
@ -25,6 +25,7 @@ extern "C" {
|
||||
|
||||
#include <switch/services/sm.h>
|
||||
#include <switch/services/fs.h>
|
||||
#include <switch/services/account.h>
|
||||
#include <switch/services/applet.h>
|
||||
#include <switch/services/binder.h>
|
||||
#include <switch/services/bsd.h>
|
||||
|
6
nx/include/switch/services/account.h
Normal file
6
nx/include/switch/services/account.h
Normal file
@ -0,0 +1,6 @@
|
||||
Result accountInitialize(void);
|
||||
void accountExit(void);
|
||||
Handle accountGetSessionService(void);
|
||||
|
||||
/// 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.
|
||||
Result accountGetActiveUser(u128 *userID, bool *account_selected);
|
@ -18,10 +18,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint8_t u8; ///< 8-bit unsigned integer
|
||||
typedef uint16_t u16; ///< 16-bit unsigned integer
|
||||
typedef uint32_t u32; ///< 32-bit unsigned integer
|
||||
typedef uint64_t u64; ///< 64-bit unsigned integer
|
||||
typedef uint8_t u8; ///< 8-bit unsigned integer
|
||||
typedef uint16_t u16; ///< 16-bit unsigned integer
|
||||
typedef uint32_t u32; ///< 32-bit unsigned integer
|
||||
typedef uint64_t u64; ///< 64-bit unsigned integer
|
||||
typedef __uint128_t u128; ///< 128-bit unsigned integer
|
||||
|
||||
typedef int8_t s8; ///< 8-bit signed integer
|
||||
typedef int16_t s16; ///< 16-bit signed integer
|
||||
|
72
nx/source/services/account.c
Normal file
72
nx/source/services/account.c
Normal file
@ -0,0 +1,72 @@
|
||||
#include <string.h>
|
||||
#include <switch.h>
|
||||
|
||||
static Handle g_accountServiceSession = INVALID_HANDLE;
|
||||
|
||||
Result accountInitialize(void) {
|
||||
if (g_accountServiceSession != INVALID_HANDLE) return MAKERESULT(MODULE_LIBNX, LIBNX_ALREADYINITIALIZED);
|
||||
|
||||
Result rc = 0;
|
||||
|
||||
rc = smGetService(&g_accountServiceSession, "acc:u1");
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void accountExit(void)
|
||||
{
|
||||
if (g_accountServiceSession == INVALID_HANDLE) return;
|
||||
|
||||
if (g_accountServiceSession != INVALID_HANDLE) {
|
||||
svcCloseHandle(g_accountServiceSession);
|
||||
g_accountServiceSession = INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
Handle accountGetSessionService(void) {
|
||||
return g_accountServiceSession;
|
||||
}
|
||||
|
||||
Result accountGetActiveUser(u128 *userID, bool *account_selected) {
|
||||
if (g_accountServiceSession == INVALID_HANDLE) return MAKERESULT(MODULE_LIBNX, LIBNX_NOTINITIALIZED);
|
||||
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 4;
|
||||
|
||||
Result rc = ipcDispatch(g_accountServiceSession);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcCommandResponse r;
|
||||
ipcParseResponse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u128 userID;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && userID) {
|
||||
*userID = resp->userID;
|
||||
if (account_selected) {
|
||||
*account_selected = 0;
|
||||
if (*userID != 0) *account_selected = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user