diff --git a/cyberpunk_patch/src/unlock_menu_patch.cpp b/cyberpunk_patch/src/unlock_menu_patch.cpp index 405d5490..fcbcfa26 100644 --- a/cyberpunk_patch/src/unlock_menu_patch.cpp +++ b/cyberpunk_patch/src/unlock_menu_patch.cpp @@ -1,14 +1,31 @@ #include "Image.h" #include +#include -void UnlockMenuPatch(Image* apImage) +void HookIsFinal(void* a, uint64_t* b, char* c) +{ + (*b)++; + if (c) + *c = 0; +} + +using TRegisterScriptFunction = void(void* a, uint64_t hash, uint64_t hash2, void* func); +TRegisterScriptFunction* RealRegisterScriptFunction = nullptr; + +void HookRegisterScriptFunction(void* a, uint64_t hash, uint64_t hash2, void* func) { - uint8_t* pAddress = nullptr; + if (hash == 0x7515013363B1C987ull) + func = &HookIsFinal; + RealRegisterScriptFunction(a, hash, hash2, func); +} + +void UnlockMenuPatch(Image* apImage) +{ if (apImage->version == Image::MakeVersion(1, 4)) { - pAddress = reinterpret_cast(apImage->base_address + 0x207c4b); + RealRegisterScriptFunction = reinterpret_cast(apImage->base_address + 0x224C70); } else { @@ -16,10 +33,6 @@ void UnlockMenuPatch(Image* apImage) return; } - DWORD oldProtect = 0; - VirtualProtect(pAddress, 8, PAGE_EXECUTE_WRITECOPY, &oldProtect); - *pAddress = 0; - VirtualProtect(pAddress, 8, oldProtect, nullptr); - + Mhook_SetHook(reinterpret_cast(&RealRegisterScriptFunction), &HookRegisterScriptFunction); spdlog::info("\tUnlock menu patch: success"); }