Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 00:53

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Help] reading memory c++

Discussion on [Help] reading memory c++ within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Feb 2015
Posts: 15
Received Thanks: 5
[Help] reading memory c++

Hello Epvpers!

I have a little problem with my simple and stupid farm bot for a game.
The bot need to read current Hp and the map ID.

These are my functions for doing so.
Code:
DWORD getCurrentHp()
{
	return *(DWORD*)(*(DWORD*)hpBaseAdress + hpOffset);
}

DWORD getCurrentMapID()
{
	return *(DWORD*)(*(DWORD*)mapBaseAddress);
}
And I use them like so:
Code:
//HP

DWORD currHp2 = getCurrentHp();
if (currHp2 != currHp)
{
	char hp[10];
	sprintf_s(Hp, "%i", currHp2);
	SetWindowText(GetDlgItem(HackInterface, hpEdit), hp);
	currHp = currHp2;
}
if (currHp < hpLimit)
{
        //restore hp.
}
And this works like a charm, my problem comes when I try to read the map ID.
Code:
//Map ID

DWORD currMapID = getCurrentMapID();
char mapID[10];
sprintf_s(mapID, "%i", currMapID);
SetWindowText(GetDlgItem(HackInterface, mapEdit), mapID);
This is code from my dll which I inject into the game.
I know that the HP is from an INT and technically the mapID is an byte, but it doesn't matter if I make the address a byte/2 byte or 4 byte in cheat engine, the value stays the same.

My game crashes when I inject the dll and tries to get the mapID.
So, any hints on what I do wrong? :P
NutellaJunkie is offline  
Old 03/04/2015, 19:37   #2
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,137
Received Thanks: 573
Well I dont know that much about how CheatEngine works, but why dont you just use a Byte instead of a Double Word?
Lets take this example, this might be your memory:

...0011 0111 1001 0110 1011 0111 0011 1001 1101 1000 10...
|A1| |A2| |A3| |A4| |A5|

And A1..5 are the Adresses. If you take a a DWord from A1 than you got
0011 1001 1011 0111 1001 0110 0011 0111 Which is equal to 968332855
or you take a Byte than you got 0011 0111 which is equal to 55

i mean you read more Memory than the value has allocated, so you read anything that is near that pointer also in the Dword. This cant go well
warfley is offline  
Old 03/04/2015, 19:53   #3
 
elite*gold: 0
Join Date: Feb 2015
Posts: 15
Received Thanks: 5
Quote:
Originally Posted by warfley View Post
Well I dont know that much about how CheatEngine works, but why dont you just use a Byte instead of a Double Word?
Lets take this example, this might be your memory:

...0011 0111 1001 0110 1011 0111 0011 1001 1101 1000 10...
|A1| |A2| |A3| |A4| |A5|

And A1..5 are the Adresses. If you take a a DWord from A1 than you got
0011 1001 1011 0111 1001 0110 0011 0111 Which is equal to 968332855
or you take a Byte than you got 0011 0111 which is equal to 55

i mean you read more Memory than the value has allocated, so you read anything that is near that pointer also in the Dword. This cant go well
I know I do, my code is far from optimized :P

But I have tried to use:
Code:
BYTEgetCurrentMapID()
{
	return *(BYTE*)(*(BYTE*)mapBaseAddress);
}
But the game still crashes :/
NutellaJunkie is offline  
Old 03/04/2015, 20:10   #4





 
Omdi's Avatar
 
elite*gold: 1371
Join Date: Apr 2010
Posts: 13,806
Received Thanks: 15,055
You should verify whether mapBaseAddress is valid or not.

Regardless of the validity check:
Code:
return *(BYTE*)mapBaseAddress;
Omdi is offline  
Thanks
1 User
Old 03/04/2015, 22:17   #5
 
elite*gold: 0
Join Date: Mar 2010
Posts: 360
Received Thanks: 132
since you are injecting a DLL, you are already in the context of the game.
This said, you can just grab any valid address. You just have to typecast it.

*(BYTE*)mapBaseAddress

if you want to access a structure which leads to another address (which hold a byte, you would cast the base address to DWORD (since addresses are stored as DWORDS) and then cast the result to BYTE.

like

*(BYTE*)(*(DWORD*)mapBaseAddress + someoffset)


I'm not sure how to properly check an address, but this is my way

Code:
DWORD address = *(DWORD*)(0x00C5FCC4);
if (!address) {return NULL;}
Daifoku is offline  
Thanks
1 User
Old 03/04/2015, 22:37   #6
 
elite*gold: 0
Join Date: Feb 2015
Posts: 15
Received Thanks: 5
Quote:
Originally Posted by Omdihar View Post
You should verify whether mapBaseAddress is valid or not.

Regardless of the validity check:
Code:
return *(BYTE*)mapBaseAddress;
Validation is for Über programmers, which I'm not :P
But the code worked like a charm, thanks

Quote:
Originally Posted by Daifoku View Post
since you are injecting a DLL, you are already in the context of the game.
This said, you can just grab any valid address. You just have to typecast it.

*(BYTE*)mapBaseAddress

if you want to access a structure which leads to another address (which hold a byte, you would cast the base address to DWORD (since addresses are stored as DWORDS) and then cast the result to BYTE.

like

*(BYTE*)(*(DWORD*)mapBaseAddress + someoffset)


I'm not sure how to properly check an address, but this is my way

Code:
DWORD address = *(DWORD*)(0x00C5FCC4);
if (!address) {return NULL;}
Thanks for clarifying, I learned something
NutellaJunkie is offline  
Reply


Similar Threads Similar Threads
Help with memory reading. C++.
06/12/2010 - Aion - 0 Replies
Hello people, I'm kinda new to memory reading in c++. Been doing similiar stuff, and done some other stuff like packet hacks etc but anyway, to the issue. I get weird values from AION when reading. And I'm prolly going about this totally wrong so I'll post you the code and hopefully some kind soul out there will point me in the right direction. int address = 0xA82424; int value; DWORD pid; if(!GameWindow) {
C++ Memory Reading
01/02/2010 - C/C++ - 4 Replies
huhu ich wollte jetzt von Autoit auf C++ umsteigen ... nun weis ich nur leider nicht wie die befehle fürs process id und memory aulesen usw bei c++ sind :) hat da jmd ne kleine übersicht oder sowas .. wäre toll x) mfg karl
Memory reading etc.
06/18/2008 - General Coding - 11 Replies
-
Memory reading help...
02/10/2007 - Conquer Online 2 - 1 Replies
Hi, I need to read the amount of arrows on an archer (0-500). I have the pointer and offset, and i can get the right number in cheat engine, however whenever i try to read it from autohotkey i always get 0. Don't know why. I've always read 4 byte data before so i don't really know if i have the right code for 2 byte data. Here's the autohotkey code ExtInt&#40;ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4&#41;; From AutoHotKey Help { Loop %pSize% result += *&#40;&pSource +...
Help with Reading Memory
01/28/2007 - Conquer Online 2 - 1 Replies
Hello, I've been programming my own Program, but im now busy with the hardest stuff, and i'm writing in VB.NET 2005 who can help me with a simple Example to read a memory adress and this convert to an TEXT label? the basic is:



All times are GMT +1. The time now is 00:54.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.