CSGO reading memory

Posts 1–9 of 9 · Page 1 of 1
CSGO reading memory
Hello guys!
I have been trying some memory management and I have stumbled upon a problem. I believe the offset for health is wrong. I am trying to read health.

Thanks in advance!

Code:
#include <iostream>
#include <Windows.h>

using namespace std;



int main()
{
	HWND hwnd = FindWindow(NULL, ("Counter-Strike: Global Offensive"));
	if (hwnd == 0)
	{
		cout << "Window not found.\n";
		system("PAUSE");
	}
	else
	{
		cout << "Window found.\n";
		
		DWORD pId;

		GetWindowThreadProcessId(hwnd, &pId);

		HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);

		if (!hProc)
		{
			cout << "Could not open process";
			system("PAUSE");
		}
		else
		{
			cout << "Process opened\n";
			
			
			DWORD pointer = 0x00A30504;
			DWORD pointed;
			WORD offset = 0x000000FC;
			int currentHealth;
			

			ReadProcessMemory(hProc, (LPCVOID)(pointer), &pointed, 4, NULL);
			ReadProcessMemory(hProc, (LPCVOID)(pointed + offset), &currentHealth, 4, NULL);

			cout << "Current Health is: " << currentHealth;
			system("PAUSE");
		}
	}
	
	
	return 0;
}
Your "pointer" isn't a complete pointer, it's an offset. You need the base address of the module client.dll and add the pointer onto it, then read that address. After that you can add your health offset onto it. Your offsets are fine.
Quote Originally Posted by WasserEsser View Post
Your "pointer" isn't a complete pointer, it's an offset. You need the base address of the module client.dll and add the pointer onto it, then read that address. After that you can add your health offset onto it. Your offsets are fine.
So something like:
DWORD pointer = 0x00A30504;
DWORD pointed;
WORD offset = 0x000000FC;
DWORD address; //address will be here

ReadProcessMemory(hProc, (LPCVOID)(pointer + address), &pointed, 4, NULL);
ReadProcessMemory(hProc, (LPCVOID)(pointed + offset), &currentHealth, 4, NULL);
Quote Originally Posted by samlarenskoog View Post
So something like:
DWORD pointer = 0x00A30504;
DWORD pointed;
WORD offset = 0x000000FC;
DWORD address; //address will be here

ReadProcessMemory(hProc, (LPCVOID)(pointer + address), &pointed, 4, NULL);
ReadProcessMemory(hProc, (LPCVOID)(pointed + offset), ¤tHealth, 4, NULL);
Exactly, though you have to get the base address of the dll ( client.dll ) on runtime, which can change on every restart of the game.
Your best way to do this externally is to use the TlHelp32.h API, which can also replace your way of getting the process id of your process.

Take a look at Process32First / Process32Next and Module32First / Module32Next.
Quote Originally Posted by WasserEsser View Post
Exactly, though you have to get the base address of the dll ( client.dll ) on runtime, which can change on every restart of the game.
Your best way to do this externally is to use the TlHelp32.h API, which can also replace your way of getting the process id of your process.

Take a look at Process32First / Process32Next and Module32First / Module32Next.
Is this good code to get base client or is there an easier way? (not my code)
static bool GetModuleAddy()
{
Process[] p = Process.GetProcessByName(process);

if (p.Length > 0)
{
foreach(ProcessModule m in p[0].Modules)
{
if (m.ModuleName == "client.dll")
{
bClient = (int)m.BaseAddress;
return true;
}
}
return true;
}
else
{
return false;
}
}
Quote Originally Posted by samlarenskoog View Post
Is this good code to get base client or is there an easier way? (not my code)
static bool GetModuleAddy()
{
Process[] p = Process.GetProcessByName(process);

if (p.Length > 0)
{
foreach(ProcessModule m in p[0].Modules)
{
if (m.ModuleName == "client.dll")
{
bClient = (int)m.BaseAddress;
return true;
}
}
return true;
}
else
{
return false;
}
}
The code you've mentioned is written in C# while your code is written in C++.
Quote Originally Posted by WasserEsser View Post
Exactly, though you have to get the base address of the dll ( client.dll ) on runtime, which can change on every restart of the game.
Your best way to do this externally is to use the TlHelp32.h API, which can also replace your way of getting the process id of your process.

Take a look at Process32First / Process32Next and Module32First / Module32Next.
is the base address static? And how do I get the address, is it available somewhere online?
Quote Originally Posted by samlarenskoog View Post
is the base address static? And how do I get the address, is it available somewhere online?
The base address is not static.

As said before, take a look at the TlHelp32 API, specifically Process32First / Process32Next to iterate the processes and getting the process id of csgo through PROCESSENTRY32 structⓘ.

After that you can iterate the modules of the process with Module32First / Module32Next and get the base address from the modBaseAddr member of the MODULEENTRY32 structⓘ.
1 week has passed and no further replies have been made by the OP. Assuming solved.

/Closed.
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us