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 


call and ret = return a value to the same spot :D

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

Joined: 13 Sep 2013
Posts: 222

PostPosted: Sat May 31, 2014 5:28 pm    Post subject: call and ret = return a value to the same spot :D Reply with quote

This will make alot of people alot happy Very Happy

i got alot of offsets that i have to edit

but don't what to push and pop and etc to get the maximum amount so i can set it

so i was think something like this

Code:
newmem:
push rdx
mov rdx,[rdi+123]
call maxxi //dont know how this works just guessing from my c# background
//now i want to send rdx to maxxi to add +4
//now i got the value back with +4
mov [rdi+123],rdx

i got more then 20 offsets that i have to edit
would be alot easier if i could say mov [rdi+123],[rdi+123+4] but i know i cant :(

maxxi: //
push eax
Mov eax,[rdx+4] //add 4 to the rdx to get the maxximum nr
mov rdx,[eax]
pop eax
ret // dont know how this works!! -- return this value to where it was called

originalcode:
Back to top
View user's profile Send private message
Daijobu
Master Cheater
Reputation: 13

Joined: 05 Feb 2013
Posts: 301
Location: the Netherlands

PostPosted: Sat May 31, 2014 5:54 pm    Post subject: Reply with quote

Should work. As far as I'm aware you can call a label and use ret.
_________________
Scripts/tables from scratch. Relation to other scripts is coincidental. Use of posted code is credited properly.
Euro Truck Simulator 2 Backwards Compatible Cheat
American Truck Simulator Backwards Compatible Cheat
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 892

PostPosted: Sat May 31, 2014 7:11 pm    Post subject: Re: call and ret = return a value to the same spot :D Reply with quote

NanoByte wrote:
// dont know how this works!! -- return this value to where it was called


call is basically shorthand for "push instruction pointer (eip/rip), jump target"
ret is basically shorthand for "add esp/rsp address, jump [esp-4/rsp-8]'

This might be good to know if your function is working on data in the stack, since you'll need to use a different offset inside the function.

_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on...
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Sat May 31, 2014 8:19 pm    Post subject: Reply with quote

@NanoByte: If I understand correctly what you want to do, line 3 needs to be "lea rdx,[rdi+123]" instead of a mov (you want rdx=rdi+123, not rdx=the data at rdi+123, right?).

There is also a problem in maxxi:
Code:
Mov eax,[rdx+4] //puts the 4 bytes at rdx+4 into eax, so for example now eax=100 hitpoints
mov rdx,[eax] //puts the 4 bytes at ADDRESS 100 hitpoints into rdx->crash
What you want to do is probably:
Code:
Mov eax,[rdx+4]
mov edx,eax //copies eax into rdx, so now edx=100 hitpoints
Which you could write in one line:
Code:
Mov edx,[rdx+4] //now edx=100 hitpoints and you don't need the push/pop eax anymore
...This or what you want to do is more complex than "mov [rdi+123],[rdi+123+4]"


Seeing that you code is going to look like:
Code:
newmem:
  push rdx

  //repeat and adjust this block 20 times
  lea rdx, [rdi+123]
  call maxxi
  //mov [rdi+123],rdx
  mov [rdi+123],edx //edx if your variable is a "4 bytes" in cheat engine, rdx is it is a "8 bytes"

 //...
  pop rdx
  originalcode:
  //...
jmp returnhere

maxxi:
  Mov edx,[rdx+4]
ret
You might want to write it that way:
Code:
newmem:
  //repeat and adjust this block 20 times
  push dword [rdi+123+4]  //saves the 4 bytes (=a dword) at rdi+???+4 into a new temporary variable
  //btw I think that cheat engine understands that 123+4=127
  pop dword [rdi+123]  //copies the dword from the temporary variable into rdi+??? and frees the temp variable

  //...
  originalcode:
  //...
jmp returnhere
Unless this is exactly what you wanted to avoid when you said "but don't what to push and pop and etc to get the maximum amount so i can set it", I'm not sure I understand very well what you meant there.

--------------------- EDIT ---------------------
Thinking again about it, this one would be even better (don't know why I didn't think about it the first time):
Code:
newmem:
  push eax 
  //repeat and adjust those 2 lines 20 times
  mov eax, dword [rdi+123+4]
  mov dword [rdi+123], eax

  //...
  pop eax
  originalcode:
  //...
jmp returnhere

Making functions for something you repeat over and over may seem a good idea, but I think the operation is so small this time that one more function does not improve readability (and definitely lowers performance, even if you don't notice the difference).

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
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