Support reloading the appliation when running a .wuhb

This commit is contained in:
Maschell 2022-09-05 20:07:16 +02:00
parent bade403102
commit 1422cec156
3 changed files with 30 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/ios.h> #include <coreinit/ios.h>
#include <coreinit/title.h>
#include <cstring> #include <cstring>
#include <mocha/mocha.h> #include <mocha/mocha.h>
#include <mutex> #include <mutex>
@ -15,6 +16,7 @@
#include <romfs_dev.h> #include <romfs_dev.h>
#include <rpxloader/rpxloader.h> #include <rpxloader/rpxloader.h>
#include <string> #include <string>
#include <sysapp/title.h>
#include <wuhb_utils/utils.h> #include <wuhb_utils/utils.h>
std::mutex fileReaderListMutex; std::mutex fileReaderListMutex;
@ -88,12 +90,33 @@ DECL_FUNCTION(FSStatus, RPX_FSCloseFile, FSClient *client, FSCmdBlock *block, FS
DECL_FUNCTION(void, Loader_ReportWarn) { 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[] = { function_replacement_data_t rpx_utils_function_replacements[] = {
REPLACE_FUNCTION_VIA_ADDRESS(Loader_ReportWarn, 0x32002f74, 0x01002f74), 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_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_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_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_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); 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(); OSMemoryBarrier();
return RPX_LOADER_RESULT_SUCCESS; return RPX_LOADER_RESULT_SUCCESS;

View File

@ -47,6 +47,7 @@ typedef struct RPXLoader_ReplacementInformation_t {
RPXReplacementInfo rpxReplacementInfo; RPXReplacementInfo rpxReplacementInfo;
ContentReplacementInfo contentReplacementInfo; ContentReplacementInfo contentReplacementInfo;
ContentReplacementWithFallback contentReplacementWithFallbackInfo; ContentReplacementWithFallback contentReplacementWithFallbackInfo;
char lastFileLoaded[0x280];
} RPXLoader_ReplacementInformation; } RPXLoader_ReplacementInformation;
extern RPXLoader_ReplacementInformation gReplacementInfo; extern RPXLoader_ReplacementInformation gReplacementInfo;

View File

@ -84,6 +84,10 @@ WUMS_APPLICATION_STARTS() {
gReplacementInfo.rpxReplacementInfo.isRPXReplaced = true; 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() && if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) == OSGetTitleID() &&
strlen(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) > 0) { strlen(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) > 0) {
uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath); uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath);