As the title states, I am having some trouble getting my cheat to work with static addresses and offsets. Here's my code:
Code:
int main()
{
int newAmmoValue = 999;
HWND hWnd = FindWindow(0, "AssaultCube");
if (hWnd == 0) {
cout << "Cannot find window." << endl;
Sleep(5000);
} else {
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);
if (!hProc) {
cout << "Cannot open process." << endl;
Sleep(5000);
} else {
static int LMGoffset = 0x150;
int PlayerBase = 0x00509B74;
int LmgAddress= PlayerBase + LMGoffset;
int success = WriteProcessMemory(hProc, (LPVOID)LmgAddress, &newAmmoValue, (DWORD)sizeof(newAmmoValue), NULL);
if (success > 0) {
cout << "Success." << endl;
Sleep(5000);
}
else {
cout << "Failure." << endl;
Sleep(5000);
}
CloseHandle(hProc);
}
}
}
I bolded "LmgAmmo" in the code, because that is where I am running into trouble. With the code the way it is right now, I get a full execution of the code and get "Success." returned to me, but the value associated with LmgAddress is not changed. If I replace LmgAddress with a dynamic address I find using cheat engine, my code works to change the ammo. But for some reason when I replace that address with the static address + offset it will not change the value in game. If I go into cheat engine and input the static address with the offset, I can change the ammo from there like normal, so I'm not sure why it is not working in my code.