Skip to content

Commit

Permalink
Alternate way to add debug menu
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Dec 14, 2020
1 parent 064dc14 commit 72f751d
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cyberpunk_patch/src/unlock_menu_patch.cpp
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");
}

0 comments on commit 72f751d

Please sign in to comment.