2021-01-01 01:39:28 +01:00
|
|
|
#include <wums.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <whb/log_udp.h>
|
|
|
|
#include <coreinit/debug.h>
|
|
|
|
#include <coreinit/title.h>
|
|
|
|
#include <sysapp/title.h>
|
|
|
|
#include <string>
|
|
|
|
#include "utils/logger.h"
|
|
|
|
#include "utils/StringTools.h"
|
|
|
|
#include "FSFileReplacements.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "FileUtils.h"
|
|
|
|
#include "FSDirReplacements.h"
|
2021-01-17 13:57:57 +01:00
|
|
|
#include "RPXLoading.h"
|
2021-01-01 01:39:28 +01:00
|
|
|
|
|
|
|
#include <romfs_dev.h>
|
2021-01-17 13:57:57 +01:00
|
|
|
#include <coreinit/cache.h>
|
|
|
|
#include <nn/act.h>
|
2021-01-01 01:39:28 +01:00
|
|
|
|
|
|
|
WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader");
|
|
|
|
|
|
|
|
WUMS_INITIALIZE(args) {
|
|
|
|
WHBLogUdpInit();
|
|
|
|
DEBUG_FUNCTION_LINE("Patch functions");
|
2021-01-17 13:57:57 +01:00
|
|
|
// we only patch static functions, we don't need re-patch them and every launch
|
2021-01-01 01:39:28 +01:00
|
|
|
FunctionPatcherPatchFunction(fs_file_function_replacements, fs_file_function_replacements_size);
|
|
|
|
FunctionPatcherPatchFunction(fs_dir_function_replacements, fs_dir_function_replacements_size);
|
2021-01-17 13:57:57 +01:00
|
|
|
FunctionPatcherPatchFunction(rpx_utils_function_replacements, rpx_utils_function_replacements_size);
|
2021-01-01 01:39:28 +01:00
|
|
|
DEBUG_FUNCTION_LINE("Patch functions finished");
|
|
|
|
gIsMounted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WUMS_APPLICATION_ENDS() {
|
|
|
|
DEBUG_FUNCTION_LINE("bye bye from rpx loader");
|
|
|
|
if (gIsMounted) {
|
|
|
|
romfsUnmount("rom");
|
|
|
|
gIsMounted = false;
|
2021-01-17 13:57:57 +01:00
|
|
|
DCFlushRange(&gIsMounted, sizeof(gIsMounted));
|
2021-01-01 01:39:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WUMS_APPLICATION_STARTS() {
|
|
|
|
uint32_t upid = OSGetUPID();
|
|
|
|
if (upid != 2 && upid != 15) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WHBLogUdpInit();
|
|
|
|
if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) {
|
2021-01-17 13:57:57 +01:00
|
|
|
DEBUG_FUNCTION_LINE("gTryToReplaceOnNextLaunch, gReplacedRPX and gIsMounted to FALSE");
|
|
|
|
gReplacedRPX = false;
|
2021-01-01 01:39:28 +01:00
|
|
|
gTryToReplaceOnNextLaunch = false;
|
|
|
|
gIsMounted = false;
|
2021-01-17 13:57:57 +01:00
|
|
|
DCFlushRange(&gReplacedRPX, sizeof(gReplacedRPX));
|
|
|
|
DCFlushRange(&gTryToReplaceOnNextLaunch, sizeof(gTryToReplaceOnNextLaunch));
|
|
|
|
DCFlushRange(&gIsMounted, sizeof(gIsMounted));
|
2021-01-01 01:39:28 +01:00
|
|
|
} else {
|
|
|
|
if (gTryToReplaceOnNextLaunch) {
|
|
|
|
gCurrentHash = StringTools::hash(gLoadedBundlePath);
|
|
|
|
|
2021-01-17 13:57:57 +01:00
|
|
|
nn::act::Initialize();
|
|
|
|
nn::act::SlotNo slot = nn::act::GetSlotNo();
|
|
|
|
nn::act::Finalize();
|
|
|
|
|
2021-01-01 01:39:28 +01:00
|
|
|
std::string basePath = StringTools::strfmt("/vol/external01/wiiu/apps/save/%08X", gCurrentHash);
|
|
|
|
std::string common = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/common", gCurrentHash);
|
2021-01-17 13:57:57 +01:00
|
|
|
std::string user = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/%08X", gCurrentHash, 0x80000000 | slot);
|
2021-01-01 01:39:28 +01:00
|
|
|
|
|
|
|
strncpy(gSavePath,basePath.c_str(), 255);
|
2021-01-17 13:57:57 +01:00
|
|
|
memset(gWorkingDir, 0, sizeof(gWorkingDir));
|
|
|
|
DCFlushRange(gWorkingDir, sizeof(gWorkingDir));
|
2021-01-01 01:39:28 +01:00
|
|
|
|
|
|
|
CreateSubfolder(common.c_str());
|
|
|
|
CreateSubfolder(user.c_str());
|
|
|
|
DEBUG_FUNCTION_LINE("Created %s and %s", common.c_str(), user.c_str());
|
|
|
|
if (romfsMount("rom", gLoadedBundlePath, RomfsSource_FileDescriptor_CafeOS) == 0) {
|
|
|
|
DEBUG_FUNCTION_LINE("MOUNTED!");
|
|
|
|
gIsMounted = true;
|
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE("MOUNTED FAILED %s", gLoadedBundlePath);
|
|
|
|
gIsMounted = false;
|
|
|
|
}
|
2021-01-17 13:57:57 +01:00
|
|
|
gReplacedRPX = true;
|
|
|
|
DCFlushRange(&gReplacedRPX, sizeof(gReplacedRPX));
|
|
|
|
DCFlushRange(&gIsMounted, sizeof(gIsMounted));
|
|
|
|
DCFlushRange(&gTryToReplaceOnNextLaunch, sizeof(gTryToReplaceOnNextLaunch));
|
2021-01-01 01:39:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|