Alternate way to add debug menu
#include "Image.h"
#include <spdlog/spdlog.h>
+#include <mhook-lib/mhook.h>
-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<uint8_t*>(apImage->base_address + 0x207c4b);
+ RealRegisterScriptFunction = reinterpret_cast<TRegisterScriptFunction*>(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<void**>(&RealRegisterScriptFunction), &HookRegisterScriptFunction);
spdlog::info("\tUnlock menu patch: success");
}
