From ced4f16ee1f63fc402eb14e8d0c25b146b6a8da4 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 18 Dec 2018 21:45:13 -0500 Subject: [PATCH] Fixed+enabled appletSetTerminateResult and added it to applet.h. --- nx/include/switch/services/applet.h | 3 ++ nx/source/services/applet.c | 74 +++++++++++++++-------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 013b6483..f36ca7e3 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -143,6 +143,9 @@ Result appletPopLaunchParameter(AppletStorage *s, AppletLaunchParameterKind kind Result appletGetDesiredLanguage(u64 *LanguageCode); +/// Only available with AppletType_*Application. +Result appletSetTerminateResult(Result res); + /// Gets whether video recording is supported. /// See also \ref appletInitializeGamePlayRecording. Result appletIsGamePlayRecordingSupported(bool *flag); diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 63017d1c..dff826e7 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -79,7 +79,6 @@ static Result _appletSetOperationModeChangedNotification(u8 flag); static Result _appletSetPerformanceModeChangedNotification(u8 flag); static Result _appletSelfExit(void); -//static Result _appletSetTerminateResult(Result res); static Result _appletExitProcessAndReturn(void); @@ -307,7 +306,7 @@ void appletExit(void) } else { if (_appletIsApplication()) { - //_appletSetTerminateResult(0); + //appletSetTerminateResult(0); _appletSelfExit(); } if (__nx_applet_type == AppletType_LibraryApplet) @@ -828,6 +827,43 @@ Result appletGetDesiredLanguage(u64 *LanguageCode) { return _appletCmdNoInOut64(&g_appletIFunctions, LanguageCode, 21); } +Result appletSetTerminateResult(Result res) { + IpcCommand c; + ipcInitialize(&c); + + if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication()) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + struct { + u64 magic; + u64 cmd_id; + Result res; + } *raw; + + raw = serviceIpcPrepareHeader(&g_appletIFunctions, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 22; + raw->res = res; + + Result rc = serviceIpcDispatch(&g_appletIFunctions); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + } *resp; + + serviceIpcParse(&g_appletIFunctions, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + Result appletBeginBlockingHomeButton(s64 val) { IpcCommand c; ipcInitialize(&c); @@ -1424,40 +1460,6 @@ Result appletSetScreenShotImageOrientation(s32 val) { return rc; } -/*static Result _appletSetTerminateResult(Result res) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - Result res; - } *raw; - - raw = serviceIpcPrepareHeader(&g_appletISelfController, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 22; - raw->res = res; - - Result rc = serviceIpcDispatch(&g_appletISelfController); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_appletISelfController, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -}*/ - Result appletCreateManagedDisplayLayer(u64 *out) { return _appletCmdNoInOut64(&g_appletISelfController, out, 40); }