fix(account-settings): Don't re-add function patches on every application boot

libfunctionpatcher stuff is persistent from plugin init time to plugin teardown time. but the memory replacements DO need to happen on every launch, so rearrange things a bit.
This commit is contained in:
Ash Logan 2024-12-17 15:13:39 +11:00
parent 23728c4288
commit 38f1b1848e
3 changed files with 27 additions and 28 deletions

View File

@ -166,6 +166,7 @@ static void Inkay_Initialize(bool apply_patches) {
patchDNS();
patchEshop();
patchOlvApplet();
patchAccountSettings();
install_matchmaking_patches();
} else {
DEBUG_FUNCTION_LINE("FunctionPatcher_InitLibrary failed");
@ -218,10 +219,7 @@ WUMS_APPLICATION_STARTS() {
setup_olv_libs();
peertopeer_patch();
matchmaking_notify_titleswitch();
if (isAccountSettingsTitle()) {
patchAccountSettings();
}
hotpatchAccountSettings();
}
WUMS_APPLICATION_ENDS() {

View File

@ -52,7 +52,13 @@ const char wave_original[] = "saccount.nintendo.net";
const char wave_new[] = "saccount.pretendo.cc";
bool isAccountSettingsTitle();
static bool isAccountSettingsTitle() {
return (OSGetTitleID() != 0 && (
OSGetTitleID() == ACCOUNT_SETTINGS_TID_J ||
OSGetTitleID() == ACCOUNT_SETTINGS_TID_U ||
OSGetTitleID() == ACCOUNT_SETTINGS_TID_E
));
}
static std::optional<FSFileHandle> rootca_pem_handle{};
std::vector<PatchedFunctionHandle> account_patches;
@ -104,15 +110,25 @@ DECL_FUNCTION(FSStatus, FSCloseFile_accSettings, FSClient *client, FSCmdBlock *b
return real_FSCloseFile_accSettings(client, block, handle, errorMask);
}
bool isAccountSettingsTitle() {
return (OSGetTitleID() != 0 && (
OSGetTitleID() == ACCOUNT_SETTINGS_TID_J ||
OSGetTitleID() == ACCOUNT_SETTINGS_TID_U ||
OSGetTitleID() == ACCOUNT_SETTINGS_TID_E
));
bool patchAccountSettings() {
account_patches.reserve(3);
auto add_patch = [](function_replacement_data_t repl, const char *name) {
PatchedFunctionHandle handle = 0;
if (FunctionPatcher_AddFunctionPatch(&repl, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("Inkay/Account: Failed to patch %s!", name);
}
account_patches.push_back(handle);
};
add_patch(REPLACE_FUNCTION_FOR_PROCESS(FSOpenFile_accSettings, LIBRARY_COREINIT, FSOpenFile, FP_TARGET_PROCESS_GAME), "FSOpenFile_accSettings");
add_patch(REPLACE_FUNCTION_FOR_PROCESS(FSReadFile_accSettings, LIBRARY_COREINIT, FSReadFile, FP_TARGET_PROCESS_GAME), "FSReadFile_accSettings");
add_patch(REPLACE_FUNCTION_FOR_PROCESS(FSCloseFile_accSettings, LIBRARY_COREINIT, FSCloseFile, FP_TARGET_PROCESS_GAME), "FSCloseFile_accSettings");
return true;
}
bool patchAccountSettings() {
bool hotpatchAccountSettings() {
if(!isAccountSettingsTitle()) {
return false;
}
@ -134,20 +150,6 @@ bool patchAccountSettings() {
return false;
}
account_patches.reserve(3);
auto add_patch = [](function_replacement_data_t repl, const char *name) {
PatchedFunctionHandle handle = 0;
if (FunctionPatcher_AddFunctionPatch(&repl, &handle, nullptr) != FUNCTION_PATCHER_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("Inkay/Account: Failed to patch %s!", name);
}
account_patches.push_back(handle);
};
add_patch(REPLACE_FUNCTION_FOR_PROCESS(FSOpenFile_accSettings, LIBRARY_COREINIT, FSOpenFile, FP_TARGET_PROCESS_GAME), "FSOpenFile_accSettings");
add_patch(REPLACE_FUNCTION_FOR_PROCESS(FSReadFile_accSettings, LIBRARY_COREINIT, FSReadFile, FP_TARGET_PROCESS_GAME), "FSReadFile_accSettings");
add_patch(REPLACE_FUNCTION_FOR_PROCESS(FSCloseFile_accSettings, LIBRARY_COREINIT, FSCloseFile, FP_TARGET_PROCESS_GAME), "FSCloseFile_accSettings");
return true;
}

View File

@ -15,7 +15,6 @@
#pragma once
bool isAccountSettingsTitle();
bool patchAccountSettings();
bool hotpatchAccountSettings();
void unpatchAccountSettings();