Added accountGetPreselectedUser.

This commit is contained in:
yellows8 2018-12-15 21:50:27 -05:00
parent 41e75d0b7d
commit f61e9237e6
3 changed files with 41 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;
}