You are misinterpreting what Cheat Engine is showing you.
In your code, 0x707B6D0 + 0x80 + 0x78 + 0x98 + 0x50 + 0x18
equals 0x707B8C8
, which is NOWHERE even close to the value of 0x0EC1A3F0
that you are trying to reach.
What you need to do instead is:
First, read a pointer that is stored at the base address 0x707B6D0
(the value read is 0x128BFBB0
).
Then, add 0x18
to that pointer (0x128BFBB0 + 0x18 = 0x128BFBC8
) and read a new pointer at that address (the value read is 0x128564D0
).
Then, add 0x50
to that pointer (0x128564D0 + 0x50 = 0x12856520
) and read a new pointer at that address (the value read is 0x0F2EC940
).
Then, add 0x98
to that pointer (0x0F2EC940 + 0x98 = 0x0F2EC9D8
) and read a new pointer at that address (the value read is 0x0F2EB2B0
).
Then, add 0x78
to that pointer (0x0F2EB2B0 + 0x78 = 0x0F2EB328
) and read a new pointer at that address (the value read is 0x0EC1A370
).
Then, add 0x80
to that pointer (0x0EC1A370 + 0x80 = 0x0EC1A3F0
), and write your data to that address.
Try something more like this:
#include <iostream>
#include <stdexcept>
#include <memory>
#include <windows.h>
DWORD_PTR readPointerFromProc(HANDLE hProc, DWORD_PTR baseAddr)
{
DWORD ptr;
if (!ReadProcessMemory(hProc, reinterpret_cast<LPVOID>(baseAddr), &ptr, sizeof(ptr), NULL);
throw std::runtime_error("Cannot read from process !");
return ptr;
}
void WriteIntToProc(HANDLE hProc, DWORD_PTR baseAddr, int value)
{
if (!WriteProcessMemory(hProc, reinterpret_cast<LPVOID>(baseAddr), &value, sizeof(value), NULL);
throw std::runtime_error("Cannot write to process !");
}
struct HandleDeleter
{
typedef HANDLE pointer;
void operator()(HANDLE handle) const { CloseHandle(handle); }
};
int main()
{
int newValue = 10;
try
{
HWND hwnd = FindWindowA(NULL, "RESIDENT EVIL 2");
if (!hwnd)
throw std::runtime_error("Process window not found !");
DWORD pId = 0;
GetWindowThreadProcessId(hwnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, pId);
if (!hProc)
throw std::runtime_error("Cannot open process !");
std::unique_ptr<HANDLE, HandleDeleter> hProc_deleter(hProc);
DWORD_PTR ptr = readPointerFromProc(hProc, 0x707B6D0);
ptr = readPointerFromProc(hProc, ptr + 0x18);
ptr = readPointerFromProc(hProc, ptr + 0x50);
ptr = readPointerFromProc(hProc, ptr + 0x98);
ptr = readPointerFromProc(hProc, ptr + 0x78);
writeIntToProc(hProc, ptr + 0x80, newValue);
}
catch (const std::exception &e)
{
std::cerr << e.what() << std::endl;
return 0;
}
std::cout << "Success !" << std::endl;
return 0;
}