From c484b33995e9e709b7f9b1dd3501bc596d7a07e1 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 16 Jul 2019 18:20:29 -0400 Subject: [PATCH] Use InitializeApplicationInfo in accountInitialize when initializing with acc:u0. Handle cleanup on failure in accountInitialize. --- nx/source/services/acc.c | 46 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/nx/source/services/acc.c b/nx/source/services/acc.c index c58dcd8f..4e00d5c5 100644 --- a/nx/source/services/acc.c +++ b/nx/source/services/acc.c @@ -5,10 +5,13 @@ #include "services/acc.h" #include "services/sm.h" #include "services/applet.h" +#include "runtime/hosversion.h" static Service g_accSrv; static u64 g_refCnt; +static Result _accountInitializeApplicationInfo(void); + Result accountInitialize(void) { Result rc=0; @@ -19,7 +22,12 @@ Result accountInitialize(void) return 0; rc = smGetService(&g_accSrv, "acc:u1"); - if (R_FAILED(rc)) rc = smGetService(&g_accSrv, "acc:u0"); + if (R_FAILED(rc)) { + rc = smGetService(&g_accSrv, "acc:u0"); + if (R_SUCCEEDED(rc)) rc = _accountInitializeApplicationInfo(); + } + + if (R_FAILED(rc)) accountExit(); return rc; } @@ -34,6 +42,42 @@ Service* accountGetServiceSession(void) { return &g_accSrv; } +static Result _accountInitializeApplicationInfo(void) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 pid_placeholder; + } *raw; + + ipcSendPid(&c); + + raw = serviceIpcPrepareHeader(&g_accSrv, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = hosversionBefore(6,0,0) ? 100 : 140; + raw->pid_placeholder = 0; + + Result rc = serviceIpcDispatch(&g_accSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + } *resp; + + serviceIpcParse(&g_accSrv, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + Result accountGetUserCount(s32* user_count) { IpcCommand c;