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 


problem with readmem writing to the wrong address

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
fluckyourusername
How do I cheat?
Reputation: 0

Joined: 01 May 2020
Posts: 3

PostPosted: Fri May 01, 2020 5:29 pm    Post subject: problem with readmem writing to the wrong address Reply with quote

I have the following two injection scripts for a Unity/Mono game:

God Mode - self explanatory
Code:

[ENABLE]
alloc(origOpcode, 8)
registersymbol(origOpcode)

origOpcode:
  readmem(PlayerHealth:TakeDamage+7, 8)

PlayerHealth:TakeDamage+7:          // Right after the prologue
  jmp "PlayerHealth:TakeDamage"+1AE // Jump straight to the epilogue
  nop
  nop
  nop

[DISABLE]
PlayerHealth:TakeDamage+7:
  readmem(origOpcode, 8)

dealloc(origOpcode)
unregistersymbol(origOpcode)


-------------------------------

No Slow Movement - disables the decreased player movement speed when hit by a specific type of monster
Code:

[ENABLE]
alloc(origOpcode, 6)
registersymbol(origOpcode)

label(fNewSlowVal)
registersymbol(fNewSlowVal)

origOpcode:
  readmem(Player:Slow+6, 6)

fNewSlowVal:
  dd (float)0.0

Player:Slow+6:
  // fldz could be used instead but I don't want to NOP out
  fld dword ptr [fNewSlowVal]

[DISABLE]
Player:Slow+6:
  readmem(origOpcode, 6)

dealloc(origOpcode)
unregistersymbol(origOpcode)
unregistersymbol(fNewSlowVal)



You can see that I'm using readmem in both scripts to restore the original code once the scripts are disabled since the addresses in opcodes I'm targeting change with each restart. However, I discovered that when I do the following:

  1. Enable God Mode
  2. Enable No Slow Movement
  3. Disable God Mode

...readmem will write the original opcode of Player:Slow+6 into PlayerHealth:TakeDamage+7.

What Am I doing wrong here and how do I fix it? Please see the attached screenshots below.



godmode_disabled.PNG
 Description:
The opcode at {PlayerHealth:TakeDamage+7}. This is both the game's original opcode the opcode the 'God Mode' script restores it when it's disabled.
 Filesize:  5.53 KB
 Viewed:  1863 Time(s)

godmode_disabled.PNG



godmode_enabled.PNG
 Description:
The injected opcode at {PlayerHealth:TakeDamage+7} when the 'God Mode' script is enabled.
 Filesize:  6.74 KB
 Viewed:  1863 Time(s)

godmode_enabled.PNG



noslow_disabled.PNG
 Description:
The opcode at {Player:Slow+6}. This is both the game's original opcode the opcode the 'No Slow Movement' script restores it when it's disabled.
 Filesize:  2.1 KB
 Viewed:  1863 Time(s)

noslow_disabled.PNG



noslow_enabled.PNG
 Description:
The injected opcode at {Player:Slow+6} when the 'No Slow Movement' script is enabled.
 Filesize:  2.15 KB
 Viewed:  1863 Time(s)

noslow_enabled.PNG



godmode_disabled_fucked.PNG
 Description:
The restored opcode of {Player:Slow+6} disastrously written at {PlayerHealth:TakeDamage+7}.
 Filesize:  5.33 KB
 Viewed:  1863 Time(s)

godmode_disabled_fucked.PNG


Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25840
Location: The netherlands

PostPosted: Fri May 01, 2020 5:49 pm    Post subject: Reply with quote

use unique names when using registersymbol
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
fluckyourusername
How do I cheat?
Reputation: 0

Joined: 01 May 2020
Posts: 3

PostPosted: Fri May 01, 2020 5:58 pm    Post subject: Reply with quote

Dark Byte wrote:
use unique names when using registersymbol

Well that's embarrassing. Just changed the the symbol names and everything works flawlessly now. Thanks a ton for a quick reply. My stupidity halted my progress for some 20 hours now trying to figure out what went wrong...
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4724

PostPosted: Fri May 01, 2020 6:16 pm    Post subject: Reply with quote

registersymbol registers a symbol globally. If it's already been defined, it's going to redefine it to point to some new address.

Alloc symbols are saved locally to each script, so simply removing (un)registersymbol(origOpcode) in all scripts could fix the problem.
If you really need it registered, then give the symbols unique names.

_________________
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
fluckyourusername
How do I cheat?
Reputation: 0

Joined: 01 May 2020
Posts: 3

PostPosted: Fri May 01, 2020 7:12 pm    Post subject: Reply with quote

ParkourPenguin wrote:
registersymbol registers a symbol globally. If it's already been defined, it's going to redefine it to point to some new address.

Alloc symbols are saved locally to each script, so simply removing (un)registersymbol(origOpcode) in all scripts could fix the problem.
If you really need it registered, then give the symbols unique names.

Will take note of that. Thanks for taking the time to read and reply.
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