From a17c73e7832643cbbfdca03536b3e9b2814ee2a9 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 13 Aug 2019 19:06:39 -0400 Subject: [PATCH] Added appletGetMainAppletStorageId, appletGetDesirableKeyboardLayout, appletGetIndirectLayerProducerHandle, and appletGetCurrentApplicationId. --- nx/include/switch/services/applet.h | 29 ++++++++++++++++++++ nx/source/services/applet.c | 42 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 15fcc0df..523b7d3d 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -12,6 +12,7 @@ #include "../services/pdm.h" #include "../services/caps.h" #include "../services/pm.h" +#include "../services/fs.h" #include "../kernel/tmem.h" #include "../kernel/event.h" #include "../nacp.h" @@ -1379,6 +1380,13 @@ Result appletGetCallerAppletIdentityInfo(AppletIdentityInfo *info); */ Result appletGetMainAppletApplicationControlProperty(NacpStruct *nacp); +/** + * @brief Gets the FsStorageId for the MainApplet. + * @note Only available with AppletType_LibraryApplet on [2.0.0+]. + * @param[out] storageId FsStorageId + */ +Result appletGetMainAppletStorageId(FsStorageId *storageId); + /** * @brief Gets an array of \ref AppletIdentityInfo for the CallerStack. * @note Only available with AppletType_LibraryApplet on [3.0.0+]. @@ -1395,6 +1403,20 @@ Result appletGetCallerAppletIdentityInfoStack(AppletIdentityInfo *stack, s32 cou */ Result appletGetNextReturnDestinationAppletIdentityInfo(AppletIdentityInfo *info); +/** + * @brief Gets the DesirableKeyboardLayout previously set by \ref appletSetDesirableKeyboardLayout. An error is returned when it's not set. + * @note Only available with AppletType_LibraryApplet on [4.0.0+]. + * @param[out] layout Output layout. + */ +Result appletGetDesirableKeyboardLayout(u32 *layout); + +/** + * @brief Gets the IndirectLayerProducerHandle. + * @note Only available with AppletType_LibraryApplet on [2.0.0+]. + * @param[out] out Output IndirectLayerProducerHandle. + */ +Result appletGetIndirectLayerProducerHandle(u64 *out); + /** * @brief Gets the DesiredLanguage for the MainApplet. * @note Only available with AppletType_LibraryApplet on [4.0.0+]. @@ -1402,6 +1424,13 @@ Result appletGetNextReturnDestinationAppletIdentityInfo(AppletIdentityInfo *info */ Result appletGetMainAppletApplicationDesiredLanguage(u64 *LanguageCode); +/** + * @brief Gets the titleID for the currently running Application. + * @note Only available with AppletType_LibraryApplet on [8.0.0+]. + * @param[out] titleID Output titleID, 0 when no Application is running. + */ +Result appletGetCurrentApplicationId(u64 *titleID); + /** * @brief Exits the current applet. Same as \ref appletHolderRequestExit except this is for the current applet. * @note Only available with AppletType_LibraryApplet on [6.0.0+]. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 849242ff..850d7a0e 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -12,6 +12,7 @@ #include "services/caps.h" #include "services/pm.h" #include "services/sm.h" +#include "services/fs.h" #include "runtime/env.h" #include "runtime/hosversion.h" #include "nacp.h" @@ -4140,6 +4141,20 @@ Result appletGetMainAppletApplicationControlProperty(NacpStruct *nacp) { return rc; } +Result appletGetMainAppletStorageId(FsStorageId *storageId) { + u8 tmp=0; + Result rc=0; + + if (__nx_applet_type != AppletType_LibraryApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + rc = _appletCmdNoInOutU8(&g_appletILibraryAppletSelfAccessor, &tmp, 16); + if (R_SUCCEEDED(rc) && storageId) *storageId = tmp; + return rc; +} + Result appletGetCallerAppletIdentityInfoStack(AppletIdentityInfo *stack, s32 count, s32 *total_out) { if (__nx_applet_type != AppletType_LibraryApplet) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); @@ -4192,6 +4207,24 @@ Result appletGetNextReturnDestinationAppletIdentityInfo(AppletIdentityInfo *info return _appletGetIdentityInfo(&g_appletILibraryAppletSelfAccessor, info, 18); } +Result appletGetDesirableKeyboardLayout(u32 *layout) { + if (__nx_applet_type != AppletType_LibraryApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoInOut32(&g_appletILibraryAppletSelfAccessor, layout, 19); +} + +Result appletGetIndirectLayerProducerHandle(u64 *out) { + if (__nx_applet_type != AppletType_LibraryApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoInOut64(&g_appletILibraryAppletSelfAccessor, out, 40); +} + Result appletGetMainAppletApplicationDesiredLanguage(u64 *LanguageCode) { if (__nx_applet_type != AppletType_LibraryApplet) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); @@ -4201,6 +4234,15 @@ Result appletGetMainAppletApplicationDesiredLanguage(u64 *LanguageCode) { return _appletCmdNoInOut64(&g_appletILibraryAppletSelfAccessor, LanguageCode, 60); } +Result appletGetCurrentApplicationId(u64 *titleID) { + if (__nx_applet_type != AppletType_LibraryApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(8,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoInOut64(&g_appletILibraryAppletSelfAccessor, titleID, 70); +} + Result appletRequestExitToSelf(void) { if (__nx_applet_type != AppletType_LibraryApplet) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);