Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello; I've been trying to get this code to work but all it does is give me weird numbers;

C++
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main()
{
				static int base = 0x00509B74;
				static int health = 0xF8;
				const int value = 100;

				HWND window = FindWindow(0, ("AssaultCube"));
				DWORD pid = GetWindowThreadProcessId(window, &pid);
				HANDLE hproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

				int localplayer;
				ReadProcessMemory(hproc, (LPCVOID*)(base), &localplayer, (DWORD)sizeof(int), NULL);
				cout << localplayer << endl;
				int address = localplayer + health;
				cout << address << endl;

			 WriteProcessMemory(hproc, (LPCVOID*)base, &value, (DWORD)sizeof(int), NULL);

			
				_getch();
				return 0;
}


the output is:
-858993460
-858993212

I'm testing this on a game called AssaultCube and the value I should get is 100(I think).

What I have tried:

I've just tried tweaking the code to see if the result would come close to what I am expecting I don't really know what else there is to try. Maybe I am adding the addresses wrong or maybe the base isn't the base at all ?
Posted
Updated 4-Apr-16 2:46am

1 solution

You should check the return values of all API functions. It is very probable that one of them fails. If so, call GetLastError() to know why it fails.

See also the OpenProcess function (Windows)[^]:
Quote:
To open a handle to another local process and obtain full access rights, you must enable the SeDebugPrivilege privilege. For more information, see Changing Privileges in a Token.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900