From 10826dda1346ac9650c7daf0326337f3d3678aba Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 15 Dec 2018 17:31:36 -0500 Subject: [PATCH] Added appletPopLaunchParameter. --- nx/include/switch/services/applet.h | 14 ++++++++++ nx/source/services/applet.c | 42 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 3d33d9ae..bbb7de41 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -49,6 +49,12 @@ typedef enum { AppletFocusHandlingMode_Max, //< Number of focus handling modes } AppletFocusHandlingMode; +typedef enum { + AppletLaunchParameterKind_Application = 1, ///< Application-specific LaunchParameter + AppletLaunchParameterKind_PreselectedUser = 2, ///< account PreselectedUser + AppletLaunchParameterKind_Unknown = 3, ///< Unknown if used by anything? +} AppletLaunchParameterKind; + /// applet hook function. typedef void (*AppletHookFn)(AppletHookType hook, void* param); @@ -77,6 +83,14 @@ AppletType appletGetAppletType(void); void appletNotifyRunning(u8 *out); Result appletCreateManagedDisplayLayer(u64 *out); +/** + * @brief Pops a LaunchParameter AppletStorage, the storage will be removed from sysmodule state during this. + * @param s Output storage. + * @param kind See \ref AppletLaunchParameterKind. + * @note Can only be used in Applications. + */ +Result appletPopLaunchParameter(AppletStorage *s, AppletLaunchParameterKind kind); + Result appletGetDesiredLanguage(u64 *LanguageCode); /// Gets whether video recording is supported. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index a62cce21..751d473a 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -719,6 +719,48 @@ Result appletGetAppletResourceUserId(u64 *out) { // IFunctions +Result appletPopLaunchParameter(AppletStorage *s, AppletLaunchParameterKind kind) { + IpcCommand c; + ipcInitialize(&c); + + if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication()) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + struct { + u64 magic; + u64 cmd_id; + u32 kind; + } *raw; + + raw = serviceIpcPrepareHeader(&g_appletIFunctions, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 1; + raw->kind = kind; + + 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; + + if (R_SUCCEEDED(rc)) { + memset(s, 0, sizeof(AppletStorage)); + serviceCreateSubservice(&s->s, &g_appletIFunctions, &r, 0); + } + } + + return rc; +} + Result appletGetDesiredLanguage(u64 *LanguageCode) { if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication()) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);