Solved Failing to read memory. c++

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

The Dab

Newbie
Full Member
Aug 19, 2017
25
198
0
I have to values, Player_Base, and prioffset. I am trying to write my current ammo in game to the ammo integer I defined. But whenever I do so it always comes back with 0 as my ammo, which it is not. I tried adding prioffset to Player_Base but still came back with nothing, So my question is how do I read a pointer.



C++:
#include <iostream>
#include <Windows.h>

using namespace std;

int ammo;
const DWORD Player_Base = 0x51E20C;
const DWORD prioffset = 0x150;

int main()
{
	HWND hwnd = FindWindowA(NULL, "AssaultCube");
	if (hwnd == NULL)
	{
		cout << "Can't Find Game: Closing" << endl;
		Sleep(3000);
		exit(-1);
	}
	else
	{
		DWORD procID;
		GetWindowThreadProcessId(hwnd, &procID);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
		if (procID = NULL)
		{
			cout << "Cannot Obtain ProcID: Closing";
			Sleep(3000);
			exit(-1);
		}
		else {
		ReadProcessMemory(handle, (PBYTE*)(Player_Base + prioffset), &ammo, sizeof(int), 0);
		cout << ammo << endl;

		}
	}
}
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,073
78,998
2,371
I have to values, Player_Base, and prioffset. I am trying to write my current ammo in game to the ammo integer I defined. But whenever I do so it always comes back with 0 as my ammo, which it is not. I tried adding prioffset to Player_Base but still came back with nothing, So my question is how do I read a pointer.
#1 use cpp instead of code in your tags for C++ syntax highlighting.

The address you used for Player_Base is a dynamic address which will change everytime you run the game so it won't work after this, so use the player base pointer, read from it once to get to the dynamic address of the local player object. Then add the ammo offset and read. The offset you posted is not the primary ammo offset, it is the assault rifle ammo. If you change guns it won't work. In the player object is a pointer to current weapon, you should use that instead then offset into the ammo of that gun. I did not add that to this code currently. I changed your DWORDs for address arithmetic to uintptr_t. uintptr_t is a typedef that resolves to the correct size of a pointer based on whether you're compiling for x86 or x64 and you should move forward with using it. Also in your RPM call you used (PBYTE*), PBYTE is a typedef for "BYTE*" so you are making that a double pointer which is wrong so I removed the extra * for you. Also your sizeof() for the number of bytes to read, I recommend using sizeof(thedestinationBufferIdentifier), it's more good for u

Here is fixed and tested code for you:
C++:
#include <iostream>
#include <Windows.h>

using namespace std;

int ammo = 0;
const uintptr_t Player_Base_Ptr = 0x50f4f4;
uintptr_t Player_Base = 0;
const uintptr_t prioffset = 0x150;

int main()
{
	HWND hwnd = FindWindowA(NULL, "AssaultCube");
	if (hwnd == NULL)
	{
		cout << "Can't Find Game: Closing" << endl;
		Sleep(3000);
		exit(-1);
	}
	else
	{
		DWORD procID;
		GetWindowThreadProcessId(hwnd, &procID);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
		if (procID = NULL)
		{
			cout << "Cannot Obtain ProcID: Closing";
			Sleep(3000);
			exit(-1);
		}
		else 
		{
			ReadProcessMemory(handle, (PBYTE)(Player_Base_Ptr), &Player_Base, sizeof(Player_Base), 0);
			ReadProcessMemory(handle, (PBYTE)(Player_Base + prioffset), &ammo, sizeof(ammo), 0);
			cout << ammo << endl;
			cin.get();
		}
	}
}
Hit the thanks button or donate if you luv me
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods