Skip to content

Commit 25fe193

Browse files
authored
Update CCore.cpp
1 parent 7dc5dc1 commit 25fe193

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Client/core/CCore.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName)
7575
return Win32LoadLibraryA(fileName);
7676
}
7777

78+
template <typename T>
79+
inline void PatchMemory(std::uintptr_t address, const T& value)
80+
{
81+
DWORD oldProtect;
82+
VirtualProtect(reinterpret_cast<void*>(address), sizeof(T), PAGE_EXECUTE_READWRITE, &oldProtect);
83+
std::memcpy(reinterpret_cast<void*>(address), value, sizeof(T));
84+
VirtualProtect(reinterpret_cast<void*>(address), sizeof(T), oldProtect, &oldProtect);
85+
}
86+
7887
CCore::CCore()
7988
{
8089
// Initialize the global pointer
@@ -836,14 +845,7 @@ void CCore::ApplyHooks()
836845
{
837846
WriteDebugEvent("CCore::ApplyHooks");
838847

839-
constexpr char newDocumentPath[] = "MTA San Andreas User Files";
840-
void* ducumentPathAddress = (void*)0x8747A9;
841-
HANDLE currentProcess = GetCurrentProcess();
842-
843-
DWORD oldProtect;
844-
VirtualProtectEx(currentProcess, ducumentPathAddress, 32, PAGE_EXECUTE_READWRITE, &oldProtect);
845-
WriteProcessMemory(currentProcess, ducumentPathAddress, newDocumentPath, sizeof(newDocumentPath), nullptr);
846-
VirtualProtectEx(currentProcess, ducumentPathAddress, 32, oldProtect, &oldProtect);
848+
PatchMemory(0x8747A9, "MTA San Andreas User Files");
847849

848850
// Create our hooks.
849851
m_pDirectInputHookManager->ApplyHook();

0 commit comments

Comments
 (0)