mirror of
https://github.com/wiiu-env/FunctionPatcherModule.git
synced 2025-01-07 23:50:44 +01:00
Fix patching dynamic function in WUMS_INITIALIZE hooks
This commit is contained in:
parent
5b87a89650
commit
ced1e27b53
@ -11,7 +11,6 @@
|
|||||||
WUMS_MODULE_EXPORT_NAME("homebrew_functionpatcher");
|
WUMS_MODULE_EXPORT_NAME("homebrew_functionpatcher");
|
||||||
WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
|
WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
|
||||||
|
|
||||||
|
|
||||||
void UpdateFunctionPointer() {
|
void UpdateFunctionPointer() {
|
||||||
// We need the real MEMAllocFromDefaultHeapEx/MEMFreeToDefaultHeap function pointer to force-allocate memory on the default heap.
|
// We need the real MEMAllocFromDefaultHeapEx/MEMFreeToDefaultHeap function pointer to force-allocate memory on the default heap.
|
||||||
// Our custom heap doesn't work (yet) for threads and causes an app panic.
|
// Our custom heap doesn't work (yet) for threads and causes an app panic.
|
||||||
@ -38,9 +37,14 @@ void UpdateFunctionPointer() {
|
|||||||
OSDynLoad_Release(coreinitModule);
|
OSDynLoad_Release(coreinitModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t gDoFunctionResets;
|
||||||
|
|
||||||
WUMS_INITIALIZE() {
|
WUMS_INITIALIZE() {
|
||||||
UpdateFunctionPointer();
|
UpdateFunctionPointer();
|
||||||
|
|
||||||
|
// don't reset the patch status on the first launch.
|
||||||
|
gDoFunctionResets = false;
|
||||||
|
|
||||||
memset(gJumpHeapData, 0, JUMP_HEAP_DATA_SIZE);
|
memset(gJumpHeapData, 0, JUMP_HEAP_DATA_SIZE);
|
||||||
gJumpHeapHandle = MEMCreateExpHeapEx((void *) (gJumpHeapData), JUMP_HEAP_DATA_SIZE, 1);
|
gJumpHeapHandle = MEMCreateExpHeapEx((void *) (gJumpHeapData), JUMP_HEAP_DATA_SIZE, 1);
|
||||||
if (gJumpHeapHandle == nullptr) {
|
if (gJumpHeapHandle == nullptr) {
|
||||||
@ -81,6 +85,14 @@ WUMS_APPLICATION_STARTS() {
|
|||||||
|
|
||||||
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
|
||||||
|
|
||||||
|
// Avoid resetting the patch status of function on the first start.
|
||||||
|
// WUMS_INITIALIZE & WUMS_APPLICATION_STARTS are called during the same application => the .rpl won't get reloaded.
|
||||||
|
// If the .rpl won't get reloaded, old patches will still be present. This can be an issue if a module patches a
|
||||||
|
// dynamic function in WUMS_INITIALIZE, which is called right before the first time this function will be called.
|
||||||
|
// This reset code would mark it as unpatched, while the code is actually still patched, leading to patching an
|
||||||
|
// already patched function.
|
||||||
|
// To avoid this issues, the need to skip the reset status part the first time.
|
||||||
|
if (gDoFunctionResets) {
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Reset patch status");
|
DEBUG_FUNCTION_LINE_VERBOSE("Reset patch status");
|
||||||
// Reset all dynamic functions
|
// Reset all dynamic functions
|
||||||
for (auto &cur : gPatchedFunctions) {
|
for (auto &cur : gPatchedFunctions) {
|
||||||
@ -99,6 +111,8 @@ WUMS_APPLICATION_STARTS() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
gDoFunctionResets = true;
|
||||||
|
|
||||||
OSMemoryBarrier();
|
OSMemoryBarrier();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user