From 1422cec15609b012734c909121ed2f3f60f8b390 Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 5 Sep 2022 20:07:16 +0200 Subject: [PATCH] Support reloading the appliation when running a .wuhb --- src/RPXLoading.cpp | 25 +++++++++++++++++++++++++ src/globals.h | 1 + src/main.cpp | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/src/RPXLoading.cpp b/src/RPXLoading.cpp index ef6afe5..46c2347 100644 --- a/src/RPXLoading.cpp +++ b/src/RPXLoading.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include std::mutex fileReaderListMutex; @@ -88,12 +90,33 @@ DECL_FUNCTION(FSStatus, RPX_FSCloseFile, FSClient *client, FSCmdBlock *block, FS DECL_FUNCTION(void, Loader_ReportWarn) { } +RPXLoaderStatus RL_PrepareLaunchFromSD(const char *bundle_path); + +DECL_FUNCTION(void, OSRestartGame, int argc, char *argv[]) { + if (OSGetTitleID() == _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) && + strlen(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) == 0) { + RL_PrepareLaunchFromSD(gReplacementInfo.lastFileLoaded); + } + real_OSRestartGame(argc, argv); +} + +DECL_FUNCTION(void, _SYSLaunchTitleWithStdArgsInNoSplash, uint64_t titleId, void *u1) { + if (titleId == _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) && + titleId == OSGetTitleID() && + strlen(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) == 0) { + RL_PrepareLaunchFromSD(gReplacementInfo.lastFileLoaded); + } + real__SYSLaunchTitleWithStdArgsInNoSplash(titleId, u1); +} + function_replacement_data_t rpx_utils_function_replacements[] = { REPLACE_FUNCTION_VIA_ADDRESS(Loader_ReportWarn, 0x32002f74, 0x01002f74), REPLACE_FUNCTION_VIA_ADDRESS_FOR_PROCESS(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44, FP_TARGET_PROCESS_HOME_MENU), REPLACE_FUNCTION_FOR_PROCESS(RPX_FSOpenFile, LIBRARY_COREINIT, FSOpenFile, FP_TARGET_PROCESS_HOME_MENU), REPLACE_FUNCTION_FOR_PROCESS(RPX_FSReadFile, LIBRARY_COREINIT, FSReadFile, FP_TARGET_PROCESS_HOME_MENU), REPLACE_FUNCTION_FOR_PROCESS(RPX_FSCloseFile, LIBRARY_COREINIT, FSCloseFile, FP_TARGET_PROCESS_HOME_MENU), + REPLACE_FUNCTION(OSRestartGame, LIBRARY_COREINIT, OSRestartGame), + REPLACE_FUNCTION(_SYSLaunchTitleWithStdArgsInNoSplash, LIBRARY_SYSAPP, _SYSLaunchTitleWithStdArgsInNoSplash), }; uint32_t rpx_utils_function_replacements_size = sizeof(rpx_utils_function_replacements) / sizeof(function_replacement_data_t); @@ -241,6 +264,8 @@ RPXLoaderStatus RL_PrepareLaunchFromSD(const char *bundle_path) { } } + strncpy(gReplacementInfo.lastFileLoaded, bundle_path, sizeof(gReplacementInfo.lastFileLoaded) - 2); + OSMemoryBarrier(); return RPX_LOADER_RESULT_SUCCESS; diff --git a/src/globals.h b/src/globals.h index 58c87c4..e1b3366 100644 --- a/src/globals.h +++ b/src/globals.h @@ -47,6 +47,7 @@ typedef struct RPXLoader_ReplacementInformation_t { RPXReplacementInfo rpxReplacementInfo; ContentReplacementInfo contentReplacementInfo; ContentReplacementWithFallback contentReplacementWithFallbackInfo; + char lastFileLoaded[0x280]; } RPXLoader_ReplacementInformation; extern RPXLoader_ReplacementInformation gReplacementInfo; diff --git a/src/main.cpp b/src/main.cpp index 8577880..3a50838 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,6 +84,10 @@ WUMS_APPLICATION_STARTS() { gReplacementInfo.rpxReplacementInfo.isRPXReplaced = true; } + if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { + gReplacementInfo.lastFileLoaded[0] = '\0'; + } + if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) == OSGetTitleID() && strlen(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) > 0) { uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath);