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 


Changing Addr passed into __thiscall always contain my value

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
LongBeardedLion
Expert Cheater
Reputation: 0

Joined: 10 Apr 2020
Posts: 172

PostPosted: Thu Jun 18, 2020 11:42 pm    Post subject: Changing Addr passed into __thiscall always contain my value Reply with quote

(images below)

I've been beating my head against the wall with this. And i will not quit. Smile
So i have my __thiscall function that changes my unit stance. And im able to call it.
As you know __thiscall functions take one object as an argument in the ECX, and the others are pushed into the stack.
So when i call my function. The ECX is the player object and its always the same. And it has one more argument pushed into the stack. So its 2 parameters only, the ECX and an ESP+4. As you can see in the image below v.
This is the function in ida:

int __thiscall sub_58AAA0(void *this, int a2)

But the problem here is. Everytime the function is called the ADDRESS that points to the value where my unit stance is, changes everytime, but not the value inside it, it remains the same for the corresponding type of unit and stance you commanded, in this case int a2 is 131B74E8 and points to 12 01 01 05.
However the next time i call the function it will be 11223344 (random), but yet containing the same value that defines the stance of my unit.
So I cant call the function because i cant guess the address that seems to be randomly generated? I mean i called it and it worked, but i simply used the previous address that still had the same value. And it only works a few times and then it either crashes or stops working.
Changing the stance of the unit will change the value in the random address to 12 01 02 05 . So that byte in bold is the byte that defines the stance. Yet the 12 01 02 05 seems to define the unit.
I also found the pointer that points to this address that changes. Image below v.

So my questions are:

1. How is this random address generated. How can i find how and what generates that address. And how can i generate it myself and call the function if that is possible?

2. Knowing that probably just writting a random address in the memory with that value 12 01 01 05 will probably still work. Can i call the function somehow by simulate/writting on another address by injection? Or thats not the way to go?



2.jpg
 Description:
Breakpoint at the start of the function. ECX is player object (remains the same everytime). ESP+4 is the address that points to the value with my 12 01 01 (stance) 05 (unit)
 Filesize:  584.63 KB
 Viewed:  1052 Time(s)

2.jpg



3.jpg
 Description:
Pointer that points to the address that contains the values 12 01 01 (stance) 05 (unit) and is passed into the function as the second argument int a2, in the ESP+4.
 Filesize:  228.95 KB
 Viewed:  1052 Time(s)

3.jpg


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

Joined: 06 Jul 2014
Posts: 4300

PostPosted: Fri Jun 19, 2020 10:19 am    Post subject: Reply with quote

LongBeardedLion wrote:
How is this random address generated. How can i find how and what generates that address. And how can i generate it myself and call the function if that is possible?
Look at what the caller is doing. It could be a few callers up the callstack.

LongBeardedLion wrote:
Knowing that probably just writting a random address in the memory with that value 12 01 01 05 will probably still work. Can i call the function somehow by simulate/writting on another address by injection?
Code:
newmem:
  mov ecx,[thing1]
  push thing2
  call addressOfFunction
  //...

thing1:
  dd something
thing2:
  db 12 01 01 05
Inject this some place where one of the game's threads will run this, or create your own thread. If you do the latter, you may need a bit more code to make it "correct" (no memory leak, safe dealloc). See this post for a couple ways.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
LongBeardedLion
Expert Cheater
Reputation: 0

Joined: 10 Apr 2020
Posts: 172

PostPosted: Sat Jun 20, 2020 12:03 pm    Post subject: Reply with quote

Thank you. Thats what i did. I basically injected assembly that uses another address where i have that same code. The problem is this code changes from unit to unit. And my actual fear is if this code is actually connected to some other task or function and if its needed for the code to be in a specific place where its offsets lead to other values that are needed. Thats what i worry about. But so far its working.

Additionally, I figured out a pointer that has two of the main bytes for each unit. So all i will have to do is grab those bytes and associate them with the other 2 bytes and i have the 4 bytes. Still it intrigues me how the game creates a new address that contains this same value every time i change the stance of the unit.

But if this way works then its ok. Perhaps im just having noob delusions. I can imagine some things must be impossible. Or very hard to do.

For example the more i go up on this sequence of functions, the more it gets complicated. With loops and calls to obscure places of the code, and getting values from addresses that are probably written into the memory by other functions. Thats probably the line where its just better to make a new game yourself than trying to hack such complex stuff.
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 Gamehacking 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