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 


Choosing between mov and readmem()

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

Joined: 30 Aug 2021
Posts: 45

PostPosted: Wed Mar 02, 2022 10:04 am    Post subject: Choosing between mov and readmem() Reply with quote

Does anyone have opinions on which of the following is better? Both work exactly as expected. Looking for inputs on potential breakages, maintenance issues and/or optimization. Many of my tables have 50+ cheats and have been working without many complaints from users for approximately a year.

1) My current code for finding the base address for all cheats in a game. I was new to assembly and AA when I copied this from a helpful person.
Code:
aobscanmodule(xp,$process,8B 81 BC 01 00 00)
alloc(newmem,$100)
alloc(CharAdr,4) // CharAdr will store the base address for all pointers

label(code)
label(return)
registersymbol(xp)
registersymbol(CharAdr)

newmem:
  mov [CharAdr],ecx
code:
  mov eax,[ecx+000001BC] // ecx holds the base address in this instance. Large parts of the game itself use this kind of base+offset notation for values.
  jmp return
xp:
  jmp newmem
  nop
return:


Over time, I started looking for a different way to find the base address, one that wouldn't replace the code. Why? My tables are so freakin' large that I don't want to mess up working code by mistake. So all new development takes place in a separate development table. If the bytes are replaced, I can't use the same AOB. I either have to use define() and specify a hard-coded address, or search for a different AOB (there are plenty of viable AOBs to choose from, but it's not nice to have to keep track of several of them). So I used define() for a long time.

2) Now I have come up with this new code:
Code:
aobscanmodule(xp,$process,03 05 * * * * 0F BE 84 30)
alloc(CharAdr,4)
registersymbol(CharAdr)

CharAdr:
  readmem(xp+2,4)
// add eax,[01F8FBC0] // eax is then used by the game for offsets for various values.


In the first approach, I use CharAdr as the pointer for offsets.
In the second approach, I have to use [CharAdr] as the pointer instead.

Is there any downside to this? Since no bytes are replaced, I can open as many instances of the table as my computer will allow and all of them can attach simultaneously to the game. Of course, that's only theoretical. The most I have ever needed to attach is 3 instances. Smile

Thanks all

_________________
It's not cheating. It's playing by my rules.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Wed Mar 02, 2022 10:46 am    Post subject: Reply with quote

The only real issue is that it won't work for a 64 bit process, because of how addresses are stored in instructions using the instruction's address as part of how the address is calculated. But for 32 bit processes it works fine.
_________________
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4703

PostPosted: Wed Mar 02, 2022 12:29 pm    Post subject: Reply with quote

Those are two different types of instructions: the first is using a register and the second is using a hard-coded address. Both of your methods for finding the address being accessed are fine for their respective instructions.

You can get a hard-coded address in a 64-bit process, but you might have to account for RIP-relative addressing using Lua.

gibberishh wrote:
If the bytes are replaced, I can't use the same AOB.
Many people combine scripts into one and use flags to toggle individual options.
And please don't try to attach multiple instances of CE to the same process. I can't think of any good reason to do that.

gibberishh wrote:
In the first approach, I use CharAdr as the pointer for offsets.
In the second approach, I have to use [CharAdr] as the pointer instead.
That distinction is meaningless as it only pertains to the different semantics of the instructions accessing data. In general, both scripts do the same thing: store the address being accessed in memory you allocated.
_________________
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
sbryzl
Master Cheater
Reputation: 6

Joined: 25 Jul 2016
Posts: 252

PostPosted: Wed Mar 02, 2022 4:33 pm    Post subject: Reply with quote

You don't even have to allocate any memory. You already have a base pointer in xp as soon as the aob scan is complete. You can just create a pointer with a base of xp+2.
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