From 06d38571b446a48a95aa34dc18a29198f5a5e008 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 15 Dec 2020 22:10:28 -0500 Subject: [PATCH] libapplet: Added the new 11.0 funcs. --- nx/include/switch/applets/libapplet.h | 20 +++++++++++++++ nx/source/applets/libapplet.c | 36 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/nx/include/switch/applets/libapplet.h b/nx/include/switch/applets/libapplet.h index 9592499d..0935e1a0 100644 --- a/nx/include/switch/applets/libapplet.h +++ b/nx/include/switch/applets/libapplet.h @@ -7,6 +7,7 @@ #pragma once #include "../types.h" #include "../services/applet.h" +#include "../services/acc.h" /// CommonArguments typedef struct { @@ -114,3 +115,22 @@ Result libappletRequestHomeMenu(void); /// Equivalent to entering "System Update" under System Settings. When leaving this, it returns to the main Home Menu. Result libappletRequestJumpToSystemUpdate(void); +/** + * @brief Wrapper for \ref appletPushToGeneralChannel, see appletPushToGeneralChannel regarding the requirements for using this. + * @note Only available on [11.0.0+]. + * @param[in] application_id ApplicationId + * @param[in] uid \ref AccountUid + * @param[in] buffer Input buffer. + * @param[in] size Input buffer size. + * @param[in] sender LaunchApplicationRequestSender + */ +Result libappletRequestToLaunchApplication(u64 application_id, AccountUid uid, const void* buffer, size_t size, u32 sender); + +/** + * @brief Wrapper for \ref appletPushToGeneralChannel, see appletPushToGeneralChannel regarding the requirements for using this. + * @note Only available on [11.0.0+]. + * @param[in] uid \ref AccountUid + * @param[in] application_id Optional ApplicationId, can be 0. + */ +Result libappletRequestJumpToStory(AccountUid uid, u64 application_id); + diff --git a/nx/source/applets/libapplet.c b/nx/source/applets/libapplet.c index d5f1197c..4d03e863 100644 --- a/nx/source/applets/libapplet.c +++ b/nx/source/applets/libapplet.c @@ -1,6 +1,7 @@ #include #include "libapplet_internal.h" #include "arm/counter.h" +#include "runtime/hosversion.h" static bool g_libappletJumpFlag; @@ -171,3 +172,38 @@ Result libappletRequestJumpToSystemUpdate(void) { return _libappletQlaunchRequest(storagedata, sizeof(storagedata)); } +Result libappletRequestToLaunchApplication(u64 application_id, AccountUid uid, const void* buffer, size_t size, u32 sender) { + if (hosversionBefore(11,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Result rc=0; + u32 tmp=size; + AppletStorage s={0}; + u8 storagedata[0x10] = {0x53, 0x41, 0x4d, 0x53, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; + + rc = appletCreateStorage(&s, 0x800); + if (R_FAILED(rc)) return rc; + + rc = appletStorageWrite(&s, 0, &storagedata, sizeof(storagedata)); + if (R_SUCCEEDED(rc)) rc = appletStorageWrite(&s, sizeof(storagedata), &sender, sizeof(sender)); + if (R_SUCCEEDED(rc)) rc = appletStorageWrite(&s, sizeof(storagedata)+sizeof(u32), &application_id, sizeof(application_id)); + if (R_SUCCEEDED(rc)) rc = appletStorageWrite(&s, sizeof(storagedata)+sizeof(u32)+sizeof(u64), &uid, sizeof(AccountUid)); + if (R_SUCCEEDED(rc)) rc = appletStorageWrite(&s, sizeof(storagedata)+sizeof(u32)+sizeof(u64)+sizeof(AccountUid), &tmp, sizeof(tmp)); + if (R_SUCCEEDED(rc)) rc = appletStorageWrite(&s, sizeof(storagedata)+sizeof(u32)+sizeof(u64)+sizeof(AccountUid)+sizeof(tmp), buffer, tmp); + if (R_FAILED(rc)) { + appletStorageClose(&s); + return rc; + } + return appletPushToGeneralChannel(&s); +} + +Result libappletRequestJumpToStory(AccountUid uid, u64 application_id) { + if (hosversionBefore(11,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + u8 storagedata[0x28] = {0x53, 0x41, 0x4d, 0x53, 0x01, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; + memcpy(&storagedata[0x10], &uid, sizeof(uid)); + memcpy(&storagedata[0x20], &application_id, sizeof(application_id)); + return _libappletQlaunchRequest(storagedata, sizeof(storagedata)); +} +