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
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(); patchDNS();
patchEshop(); patchEshop();
patchOlvApplet(); patchOlvApplet();
patchAccountSettings();
install_matchmaking_patches(); install_matchmaking_patches();
} else { } else {
DEBUG_FUNCTION_LINE("FunctionPatcher_InitLibrary failed"); DEBUG_FUNCTION_LINE("FunctionPatcher_InitLibrary failed");
@ -218,10 +219,7 @@ WUMS_APPLICATION_STARTS() {
setup_olv_libs(); setup_olv_libs();
peertopeer_patch(); peertopeer_patch();
matchmaking_notify_titleswitch(); matchmaking_notify_titleswitch();
hotpatchAccountSettings();
if (isAccountSettingsTitle()) {
patchAccountSettings();
}
} }
WUMS_APPLICATION_ENDS() { WUMS_APPLICATION_ENDS() {

View file

@ -52,7 +52,13 @@ const char wave_original[] = "saccount.nintendo.net";
const char wave_new[] = "saccount.pretendo.cc"; 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{}; static std::optional<FSFileHandle> rootca_pem_handle{};
std::vector<PatchedFunctionHandle> account_patches; 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); return real_FSCloseFile_accSettings(client, block, handle, errorMask);
} }
bool isAccountSettingsTitle() { bool patchAccountSettings() {
return (OSGetTitleID() != 0 && ( account_patches.reserve(3);
OSGetTitleID() == ACCOUNT_SETTINGS_TID_J ||
OSGetTitleID() == ACCOUNT_SETTINGS_TID_U || auto add_patch = [](function_replacement_data_t repl, const char *name) {
OSGetTitleID() == ACCOUNT_SETTINGS_TID_E 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()) { if(!isAccountSettingsTitle()) {
return false; return false;
} }
@ -134,20 +150,6 @@ bool patchAccountSettings() {
return false; 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; return true;
} }

View file

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