From f61e9237e666f776414294e786df70f629fe5b73 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 15 Dec 2018 21:50:27 -0500 Subject: [PATCH] Added accountGetPreselectedUser. --- nx/include/switch/services/acc.h | 4 ++++ nx/include/switch/services/applet.h | 1 + nx/source/services/acc.c | 36 +++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/nx/include/switch/services/acc.h b/nx/include/switch/services/acc.h index e9067313..7a48003e 100644 --- a/nx/include/switch/services/acc.h +++ b/nx/include/switch/services/acc.h @@ -63,3 +63,7 @@ Result accountProfileGetImageSize(AccountProfile* profile, size_t* image_size); Result accountProfileLoadImage(AccountProfile* profile, void* buf, size_t len, size_t* image_size); void accountProfileClose(AccountProfile* profile); + +/// Gets the userID which was selected by the profile-selector applet (if any), prior to launching the currently running Application title. This can only be used once under the current process, under an Application title. +Result accountGetPreselectedUser(u128 *userID); + diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 0973d684..d65396da 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -87,6 +87,7 @@ Result appletCreateManagedDisplayLayer(u64 *out); * @param s Output storage. * @param kind See \ref AppletLaunchParameterKind. * @note Can only be used in Applications. + * @note See also acc.h \ref accountGetPreselectedUser (wrapper for appletPopLaunchParameter etc). */ Result appletPopLaunchParameter(AppletStorage *s, AppletLaunchParameterKind kind); diff --git a/nx/source/services/acc.c b/nx/source/services/acc.c index 93b8e2e8..68d136ef 100644 --- a/nx/source/services/acc.c +++ b/nx/source/services/acc.c @@ -4,6 +4,7 @@ #include "arm/atomics.h" #include "services/acc.h" #include "services/sm.h" +#include "services/applet.h" static Service g_accSrv; static u64 g_refCnt; @@ -325,3 +326,38 @@ void accountProfileClose(AccountProfile* profile) { serviceClose(&profile->s); } +Result accountGetPreselectedUser(u128 *userID) { + Result rc=0; + AppletStorage storage; + s64 tmpsize=0; + + struct { + u32 magicnum;//These two fields must match fixed values. + u8 unk_x4; + u8 pad[3]; + u128 userID; + u8 unk_x18[0x70];//unused + } PACKED storagedata; + + memset(&storagedata, 0, sizeof(storagedata)); + + rc = appletPopLaunchParameter(&storage, AppletLaunchParameterKind_PreselectedUser); + + if (R_SUCCEEDED(rc)) { + rc = appletStorageGetSize(&storage, &tmpsize); + if (R_SUCCEEDED(rc) && tmpsize < sizeof(storagedata)) + rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); + + if (R_SUCCEEDED(rc)) rc = appletStorageRead(&storage, 0, &storagedata, sizeof(storagedata)); + + appletStorageClose(&storage); + + if (R_SUCCEEDED(rc) && (storagedata.magicnum!=0xc79497ca || storagedata.unk_x4!=1)) + rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); + + if (R_SUCCEEDED(rc) && userID) *userID = storagedata.userID; + } + + return rc; +} +