Solved ReadProcessMemory - 2nd try.

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

jeneves

Newbie
Full Member
Aug 27, 2015
22
122
0
Hello all!

Im trying to read my HP max/current from a Game.

I used Cheat Engine and i think i don't have any offset, since i found green address:

0083E1B4 - current hp
0083E1B8 - max

Now i double clicked on this, and checked the base offset of the game:

blablabla.exe+43E1B4

In my code i included:

C++:
		unsigned long hp_pointer = 0x0083E1B4;
		unsigned long hp_base = 0x43E1B4;
		unsigned long hp_address;
		DWORD buffer;

		DWORD i;
		for (i = 0; i <= 1000; i++) {
			ReadProcessMemory(hProc, (LPVOID)(hp_base + hp_pointer), (LPVOID)&buffer, sizeof(buffer), 0);
			Console::WriteLine(buffer.ToString());
			Sleep(1000);
		}
But i'm not getting my HP number, I'm getting some random numbers. Can i get any help?

Thanks.
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
Hello all!

Im trying to read my HP max/current from a Game.

I used Cheat Engine and i think i don't have any offset, since i found green address:

0083E1B4 - current hp
0083E1B8 - max

Now i double clicked on this, and checked the base offset of the game:

blablabla.exe+43E1B4

In my code i included:

C++:
		unsigned long hp_pointer = 0x0083E1B4;
		unsigned long hp_base = 0x43E1B4;
		unsigned long hp_address;
		DWORD buffer;

		DWORD i;
		for (i = 0; i <= 1000; i++) {
			ReadProcessMemory(hProc, (LPVOID)(hp_base + hp_pointer), (LPVOID)&buffer, sizeof(buffer), 0);
			Console::WriteLine(buffer.ToString());
			Sleep(1000);
		}
But i'm not getting my HP number, I'm getting some random numbers. Can i get any help?

Thanks.
If your address is "0083E1B4 - current hp" or "blablabla.exe+43E1B4" then "hp_base + hp_pointer" is definitly wrong.
C++:
unsigned long hp_pointer = 0x0083E1B4;
unsigned long hp_offset = 0x43E1B4;
should be something like
C++:
unsigned long process_base = 0x00400000; //or "blablabla.exe"
unsigned long hp_base = 0x43E1B4;
If you now add those together you get the correct address.

And just use DWORD instead of unsigned long. It's just not that much to write xD
 
Last edited:

jeneves

Newbie
Full Member
Aug 27, 2015
22
122
0
Excelent, worked like a charm!

One question, if i put this on a loop to keep checking my HP (i will make auto-potion) the application usually stop to process and don't even update the text label.


In that case, to avoid this kind of process issue, should i use threads?

here's my code:


C++:
DWORD base_pointer = 0x00400000;
		//CURRENT HP
		DWORD current_hp_pointer = 0x43E1B4;
		// MAX HP
		DWORD max_hp_pointer = 0x43E1B8;
		DWORD buffer_current_hp, buffer_max_hp;
		
		//while (rag = true) {
			ReadProcessMemory(hProc, (LPVOID)(base_pointer + current_hp_pointer), (LPVOID)&buffer_current_hp, sizeof(buffer_current_hp), 0);
			ReadProcessMemory(hProc, (LPVOID)(base_pointer + max_hp_pointer), (LPVOID)&buffer_max_hp, sizeof(buffer_max_hp), 0);
			hp_value_label->Text = buffer_current_hp + L"/" + buffer_max_hp;
		//}
 

jeneves

Newbie
Full Member
Aug 27, 2015
22
122
0
I only know the concept behind thread, but one question before i start to study this topic. I should use the thread only for this While block or for the entire program?

At this moment i have a Windows Form (CLI/c++) that contains 2 buttons (start /stop), the Start button basically keep the looping to update my HP/SP on the game. Based on this, i will define some criterias (%) to heal myself automatically.
 

jeneves

Newbie
Full Member
Aug 27, 2015
22
122
0
Ok guys! I got my threading working!

Maybe my code isn't the best in terms of performance.

Can you guys check please?

My function:

C++:
public: System::Void CheckMyHP()
	{

	

		while (rag = true) {

		// READING HP
		ReadProcessMemory(hProc, (LPVOID)(base_pointer + current_hp_pointer), (LPVOID)&buffer_current_hp, sizeof(buffer_current_hp), 0);
		ReadProcessMemory(hProc, (LPVOID)(base_pointer + max_hp_pointer), (LPVOID)&buffer_max_hp, sizeof(buffer_max_hp), 0);
		hp_value_label->Text = buffer_current_hp + L"/" + buffer_max_hp;
		// READING SP
		// READING HP
		ReadProcessMemory(hProc, (LPVOID)(base_pointer + current_sp_pointer), (LPVOID)&buffer_current_sp, sizeof(buffer_current_sp), 0);
		ReadProcessMemory(hProc, (LPVOID)(base_pointer + max_sp_pointer), (LPVOID)&buffer_max_sp, sizeof(buffer_max_sp), 0);
		sp_value_label->Text = buffer_current_sp + L"/" + buffer_max_sp;
		}
	}
My thread :

C++:
	Thread^ thr1 = gcnew Thread(gcnew ThreadStart(this,&MyForm::CheckMyHP));
		thr1->Start();
Also, i declared hProc as a public HANDLE, since I failed when trying to call the thread for a function with parameters :/ Seems that i can only pass "Object^ object" to the thread, not sure.
 

Obsta

Jr.Hacker
Meme Tier VIP
Jan 27, 2014
394
2,978
17
Ok guys! I got my threading working!

Maybe my code isn't the best in terms of performance.

Can you guys check please?
.
Put a 1ms sleep in your while loop or it will cause the thread to attempt to force itself into every free cpu cycle(Did i say that right?).
anyway it'll drop the CPU load by like 60%. Watch it in task manager and see for yourself.

A good rule of thumb is whenever you use While(), include a Sleep(1);
 

jeneves

Newbie
Full Member
Aug 27, 2015
22
122
0
Put a 1ms sleep in your while loop or it will cause the thread to attempt to force itself into every free cpu cycle(Did i say that right?).
anyway it'll drop the CPU load by like 60%. Watch it in task manager and see for yourself.

A good rule of thumb is whenever you use While(), include a Sleep(1);
I will do that, thanks for the tip.

BTW, imagine that i have a GUI, and this thread is uploading my hp/sp during this while. A part from that, i have a button to stop this process, in this button, im only changing the bool value to false, so my while will stop.

Now, in terms of thread, when i want force the while to stop, should i include any command to finalize this thread or this is automatically? I mean, something related to free the CPU in order to gain more performance in my code.

Thanks sir!
 

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51
I will do that, thanks for the tip.

BTW, imagine that i have a GUI, and this thread is uploading my hp/sp during this while. A part from that, i have a button to stop this process, in this button, im only changing the bool value to false, so my while will stop.

Now, in terms of thread, when i want force the while to stop, should i include any command to finalize this thread or this is automatically? I mean, something related to free the CPU in order to gain more performance in my code.

Thanks sir!
After your routine has exited due to the break in the while, the thread will no longer exist.


I'd actually wonder if your program doesn't crash in your new created thread.

Another thing:
You can use ParameterizedThreadStart to pass a pointer to an own structure to your new created thread, which you can, in the thread, read the values from.
 

Obsta

Jr.Hacker
Meme Tier VIP
Jan 27, 2014
394
2,978
17
I will do that, thanks for the tip.

BTW, imagine that i have a GUI, and this thread is uploading my hp/sp during this while. A part from that, i have a button to stop this process, in this button, im only changing the bool value to false, so my while will stop.

Now, in terms of thread, when i want force the while to stop, should i include any command to finalize this thread or this is automatically? I mean, something related to free the CPU in order to gain more performance in my code.

Thanks sir!
Assuming your logical flow is correct, it should execute fine.

1. Set global bool to false.
2. Current while iteration will complete and break out on the false boolean.
3. Thread will naturally complete its job and destroy itself.
4. Verify all threads are closed at the end of your main thread application using Threading.Thread.join() or w/e depending on which langauge you're using
 

jeneves

Newbie
Full Member
Aug 27, 2015
22
122
0
After your routine has exited due to the break in the while, the thread will no longer exist.


I'd actually wonder if your program doesn't crash in your new created thread.

Another thing:
You can use ParameterizedThreadStart to pass a pointer to an own structure to your new created thread, which you can, in the thread, read the values from.

Yup that was one of the point that I had some difficult. For example in my Thread Function, one of the functions that are being executed is ReadProcessMemory, and this requires a Handle as the first parameter.

Based on that, i tried to use ParameterizedThreadStart to send my "Handle hProc" to the thread function, but I must admit that i tried so many times without success that i decided to declare my HANDLE hProc as public in the scope of my class, so I didn't had to use ParameterizedThreadStart. But, if you can clarify me on this, should be great. Thank you.
 

jeneves

Newbie
Full Member
Aug 27, 2015
22
122
0
Assuming your logical flow is correct, it should execute fine.

1. Set global bool to false.
2. Current while iteration will complete and break out on the false boolean.
3. Thread will naturally complete its job and destroy itself.
4. Verify all threads are closed at the end of your main thread application using Threading.Thread.join() or w/e depending on which langauge you're using

That was actually mt secound doubt (a part from ParameterizedThreadStart).

1. I have my bool var as public on my class:

C++:
public:
		bool rag = false;
		HANDLE hProc;
2. Ok
3. I didn't know that the thread desotry itself.
4. I don't really understand where to put the threading join. Maybe when I break the while looping? I'm using CLI/C++ because c++ does not support GUI anymore. (ps: I'm knew to c++ and cli also)

Thanks for helping.
 

Obsta

Jr.Hacker
Meme Tier VIP
Jan 27, 2014
394
2,978
17
That was actually mt secound doubt (a part from ParameterizedThreadStart).

1. I have my bool var as public on my class:

C++:
public:
		bool rag = false;
		HANDLE hProc;
2. Ok
3. I didn't know that the thread desotry itself.
4. I don't really understand where to put the threading join. Maybe when I break the while looping? I'm using CLI/C++ because c++ does not support GUI anymore. (ps: I'm knew to c++ and cli also)

Thanks for helping.
Towards the end of Main(), before your return. Think of thread.join() as a cleanup method that makes sure all threads have exited.
 
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