-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,38 @@ | ||
#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 | ||
{ | ||
spdlog::warn("\tUnlock menu patch: failed, unknown version"); | ||
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"); | ||
} |