From f49e8cb2174c89f81bc1d050c8e3a3332ae38dde Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 30 Jul 2019 20:03:24 -0400 Subject: [PATCH] Added struct LibAppletInfo. Added appletHolderGetLibraryAppletInfo and appletGetLibraryAppletInfo. --- nx/include/switch/services/applet.h | 20 +++++++++++++ nx/source/services/applet.c | 46 +++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 265baa10..c1dc9d6b 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -196,6 +196,12 @@ typedef struct { LibAppletExitReason exitreason; ///< Set by \ref appletHolderJoin using the output from cmd GetResult, see \ref LibAppletExitReason. } AppletHolder; +/// LibraryAppletInfo +typedef struct { + AppletId appletId; ///< \ref AppletId + LibAppletMode mode; ///< \ref LibAppletMode +} LibAppletInfo; + /// IdentityInfo typedef struct { AppletId appletId; ///< \ref AppletId @@ -759,6 +765,13 @@ Result appletHolderPushInteractiveInData(AppletHolder *h, AppletStorage *s); */ Result appletHolderPopInteractiveOutData(AppletHolder *h, AppletStorage *s); +/** + * @brief Gets the \ref LibAppletInfo for the specified LibraryApplet. + * @param h AppletHolder object. + * @param[out] info \ref LibAppletInfo + */ +Result appletHolderGetLibraryAppletInfo(AppletHolder *h, LibAppletInfo *info); + // (ILibraryAppletCreator ->) IStorage /** @@ -1014,6 +1027,13 @@ Result appletGetGpuErrorDetectedSystemEvent(Event *out_event); // ILibraryAppletSelfAccessor +/** + * @brief Gets the \ref LibAppletInfo for the current LibraryApplet. + * @note Only available with AppletType_LibraryApplet. + * @param[out] info \ref LibAppletInfo + */ +Result appletGetLibraryAppletInfo(LibAppletInfo *info); + /** * @brief Gets the \ref AppletIdentityInfo for the MainApplet. * @note Only available with AppletType_LibraryApplet. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index b332ec2c..f9e25809 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -990,6 +990,41 @@ static Result _appletCmdNoInOutStorage(Service* srv, AppletStorage* s, u64 cmd_i return _appletGetSession(srv, &s->s, cmd_id); } +static Result _appletGetLibraryAppletInfo(Service* srv, LibAppletInfo *info, u64 cmd_id) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = serviceIpcPrepareHeader(srv, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = cmd_id; + + Result rc = serviceIpcDispatch(srv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + LibAppletInfo info; + } *resp; + + serviceIpcParse(srv, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && info) memcpy(info, &resp->info, sizeof(LibAppletInfo)); + } + + return rc; +} + static Result _appletGetIdentityInfo(Service* srv, AppletIdentityInfo *info, u64 cmd_id) { IpcCommand c; ipcInitialize(&c); @@ -2289,6 +2324,10 @@ Result appletHolderPopInteractiveOutData(AppletHolder *h, AppletStorage *s) { return _appletCmdNoInOutStorage(&h->s, s, 104); } +Result appletHolderGetLibraryAppletInfo(AppletHolder *h, LibAppletInfo *info) { + return _appletGetLibraryAppletInfo(&h->s, info, 120); +} + // (ILibraryAppletCreator ->) IStorage Result appletCreateStorage(AppletStorage *s, s64 size) { @@ -3399,6 +3438,13 @@ static Result _appletExitProcessAndReturn(void) { return _appletCmdNoIO(&g_appletILibraryAppletSelfAccessor, 10); } +Result appletGetLibraryAppletInfo(LibAppletInfo *info) { + if (__nx_applet_type != AppletType_LibraryApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletGetLibraryAppletInfo(&g_appletILibraryAppletSelfAccessor, info, 11); +} + Result appletGetMainAppletIdentityInfo(AppletIdentityInfo *info) { if (__nx_applet_type != AppletType_LibraryApplet) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);