I'm trying to learn and understand how readproccessmemory work. When I'm using cheat engine to find the static values, it's an success. I can close the game, use my address and offset, and get the correct value every time. However, when I'm trying to execute this in C++, it never returns the correct value?
This is what my code looks like,
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
// Base Address
DWORD BaseAddress = 0x50F4F4;
// Health
DWORD healthOfset = 0xf8;
DWORD healthAddress = (DWORD)(BaseAddress+healthOfset);
int health = 0;
HWND hwnd;
DWORD pid;
HANDLE phandle;
hwnd = FindWindow(NULL,"AssaultCube");
if(hwnd)
{
cout << "Game was found.\n" << endl;
GetWindowThreadProcessId(hwnd,&pid);
phandle = OpenProcess(PROCESS_ALL_ACCESS,0,pid);
if(phandle)
{
// Read Health
ReadProcessMemory(phandle,(PCVOID)healthAddress, &health, sizeof(health),0);
cout << "Health: " << health << endl;
}
} else {
cout << "Game not found." << endl;
}
return 0;
}
The above code returns:
Game was found.
Health: -1
This is what cheat engine is giving me,
http:/ / image.prntscr.com/image/b3660e76b0174f9794c4322108cb9eab . png (not allowed to post links)
Am i doing this completely wrong?