Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] Weird results when adding offsets to pointer

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
logicallysynced
Newbie cheater
Reputation: 0

Joined: 30 Mar 2016
Posts: 16

PostPosted: Sat Apr 02, 2016 10:00 am    Post subject: [C#] Weird results when adding offsets to pointer Reply with quote

Hi all,

I'm having a bit of an odd encounter with one of my pointer calculations. Basically what is happening is that I'm trying to add 2 offsets to an address to return my pointer.

The base address is FEA1D75 and I'm fetching that correctly within my C# application.

Now when I add this address manually in Cheat Engine as a pointer and add the offsets 8 and 0 to it, it returns the value of 03B99B88. Which is the value I need.

However when I try to replicate this in my C# application, when I add the first offset the value jumps all the way to C5048DFF and then when I add the second, it seems to just give me a return value of 0.

The C# code in case it's useful is:

Code:

//the variable `season_ptr` returns FEA1D75
IntPtr ptrv_2 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(season_ptr, 0x08), 4, out bytesRead), 0); //returns C5048DFF (should return 03B99B80)
IntPtr ptrv_3 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(ptrv_2, 0x0), 4, out bytesRead), 0); //returns 0 (should return 03B99B88)


I use the same code format for all my other pointers and don't seem to have any problems with it, they all return values correctly except for this one.

Any help would be much appreciated.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Apr 02, 2016 10:08 am    Post subject: Reply with quote

Is this a 64-bit game?

What does CE say the second address on the jump is?
Back to top
View user's profile Send private message
logicallysynced
Newbie cheater
Reputation: 0

Joined: 30 Mar 2016
Posts: 16

PostPosted: Sat Apr 02, 2016 11:30 am    Post subject: Reply with quote

Zanzer wrote:
Is this a 64-bit game?

What does CE say the second address on the jump is?


I believe the game runs as x86.

CE tells me the address pointer is:

Code:

FEA1D75 = FEA1D75
FEA1D75+8 = 03B99B80
03B99B88+0 = 03B99B88


Which is the correct values.
But in C# I'm getting something like:

Code:

FEA1D75 = FEA1D75
FEA1D75+8 = C5048DFF
C5048DFF+0 = 0
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Apr 02, 2016 11:55 am    Post subject: Reply with quote

Judging by the values you posted from CE, it looks like the correct address is:
Code:
[[FEA1D75]+8]+0

But your code is retrieving:
Code:
[[FEA1D75+8]+0]

Try:
Code:
IntPtr ptrv_2 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(season_ptr, 0x0), 4, out bytesRead), 0);
IntPtr ptrv_3 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(ptrv_2, 0x8), 4, out bytesRead), 0);
Back to top
View user's profile Send private message
logicallysynced
Newbie cheater
Reputation: 0

Joined: 30 Mar 2016
Posts: 16

PostPosted: Sat Apr 02, 2016 7:18 pm    Post subject: Reply with quote

Zanzer wrote:
Judging by the values you posted from CE, it looks like the correct address is:
Code:
[[FEA1D75]+8]+0

But your code is retrieving:
Code:
[[FEA1D75+8]+0]

Try:
Code:
IntPtr ptrv_2 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(season_ptr, 0x0), 4, out bytesRead), 0);
IntPtr ptrv_3 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(ptrv_2, 0x8), 4, out bytesRead), 0);



If I reverse them like you mentioned, I get the following invalid values:

Code:
FC1D75 -> FC1D75
FC1D75+0 -> 47737C4
47737C4+8 -> 3771228
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Apr 02, 2016 9:50 pm    Post subject: Reply with quote

Post a screenshot of CE's pointer definition and the results of your C# code.
Back to top
View user's profile Send private message
logicallysynced
Newbie cheater
Reputation: 0

Joined: 30 Mar 2016
Posts: 16

PostPosted: Sat Apr 02, 2016 10:23 pm    Post subject: Reply with quote

Zanzer wrote:
Post a screenshot of CE's pointer definition and the results of your C# code.


Alright I'm pretty sure this is what you want. Sorry for the paint mix and match, it's the best I had to work with. I provided the results and code of both offset arrangements too.



CT_valid.png
 Description:
 Filesize:  24.28 KB
 Viewed:  6298 Time(s)

CT_valid.png



Csharp_invalid.png
 Description:
 Filesize:  65.74 KB
 Viewed:  6298 Time(s)

Csharp_invalid.png


Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Apr 02, 2016 10:27 pm    Post subject: Reply with quote

Code:
IntPtr ptrv_2 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(season_ptr, 0x0), 4, out bytesRead), 0);
IntPtr ptrv_3 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(ptrv_2, 0x0), 4, out bytesRead), 0);
IntPtr ptrv_4 = IntPtr.Add(ptrv_3, 0x8);
Back to top
View user's profile Send private message
logicallysynced
Newbie cheater
Reputation: 0

Joined: 30 Mar 2016
Posts: 16

PostPosted: Sat Apr 02, 2016 10:43 pm    Post subject: Reply with quote

Zanzer wrote:
Code:
IntPtr ptrv_2 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(season_ptr, 0x0), 4, out bytesRead), 0);
IntPtr ptrv_3 = (IntPtr)BitConverter.ToInt32(ReadMemory(myProcess, IntPtr.Add(ptrv_2, 0x0), 4, out bytesRead), 0);
IntPtr ptrv_4 = IntPtr.Add(ptrv_3, 0x8);


Excellent. You are amazing! Thank you that works great
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites