Discuss C++ RealTime reading data best practice

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

PandoraBytes

Newbie
Nov 2, 2015
4
62
0
Hello I have successfully read data from game via c++. Now I need to read it in real time. I have two concerns
1) Do I use infinite while loop?
C++:
while(gameOn) {
ReadAddress(1); //Example
ReadAddress(2); //Example
ReadAddress(3); //Example
ReadAddress(4); //Example
....
ReadAddress(100); //Example
Sleep(200);
}
2) As you can see one while loop will end up reading alot of game values. Since the value is consecutive (I am suspecting it is a structure), should I just read 100 bytes and parse it?? So the option is reading 100 byte once and process the data accordingly or reading 1 byte each time for 100 times.

By the way here is my read function

C++:
int Process::memoryReadByte(int memoryAddress) {
	unsigned char buffer = 0;
	SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 1
	SIZE_T NumberOfBytesActuallyRead;
	BOOL succeed = ReadProcessMemory(hProcess, (LPCVOID)(baseAddress + memoryAddress), &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
	if (!succeed || NumberOfBytesActuallyRead != NumberOfBytesToRead) {
		return 0;
	}
	return buffer;
}
So is infinite while loop good? I don't want to make my game laggy. Infinite while loop sounds scary :S
On second thought, I should post this in c++ section.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,185
78,998
2,399
Infinite loop with a sleep in it is fine. If the data is in a structure you want to do as few ReadProcessMemory calls as possible. You would do ReadProcessMemory(hProcess, address, &buffer, sizeof(structure), &numberofbytesread)

If you don't need the majority of the structure it is fine to read 1 variable at a time for the most part
 

Lukor

ded
Meme Tier VIP
Fleep Tier Donator
Dec 13, 2013
494
5,753
25
Like Rake described most data is structured (eg player, weapon, ...).

In case you read a players data it is advised to create a structure (with reclass available in one of my threads) to make it easy to read and write by using a class.
It will automatically hide unused memory and enable you to use all interesting memory like this: myData->health

EDIT:
Sorry... missed that it is external...
You wont be able to write directly, but you can still cast your buffer to the structure type and read the values instead of using health = data[24];
However you can change the buffer (using the structure) and write it back into the process memory.
 
Last edited:
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