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 


Can't get CMP / compare to work. help pls?
Goto page 1, 2  Next
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

PostPosted: Fri May 01, 2020 12:17 pm    Post subject: Can't get CMP / compare to work. help pls? Reply with quote

Hi. I have looked through some compare topics, but i still can't get it to work.

instruction i'm using accesses like 100+ addresses. so i right click on the one i need and "show register states"

then in that registers window I find a register value that is unique to that address.
in my case it's R10=0000000000000014

so in my script i do this

Code:

cmp R10,14

// code to get address of health
push rbx
mov rbx,_health
mov [rbx],rdx
pop rbx

// original code
  mov eax,[rdx+08]
  mov [rcx],00000001
  jmp return


but it simply ignores the cmp all together. what am I doing wrong?
I also tried replacing 14 with 20 (HEX TO DEC), but still it gets ignored. i'm quite sure i'm using cmp wrong, but i dont know how to add it properly.

i have used rest of the code many times in many games, so everything else is 100% working.

what i need this code to do, is to only get the value if R10 register of the address is equal to 14 and ignore all other addresses that it accesses.
i hope someone can fix this for me. thanks in advance.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Fri May 01, 2020 1:42 pm    Post subject: Reply with quote

cmp just sets rflags. You need something that reads rflags and acts on the result of the cmp - i.e. a jcc instruction:
Code:
cmp r10,14
jne originalcode    // if r10 != 14 then skip this
  mov eax,_health
  mov [eax],rdx
originalcode:
mov eax,[rdx+08]
mov [rcx],00000001
jmp return
p.s.: eax is overwritten later, so it's safe to clobber without backing it up.
_________________
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
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

PostPosted: Fri May 01, 2020 2:10 pm    Post subject: Reply with quote

thanks for quick reply, i tried, but it crashes the game with this one:

Code:
cmp r10,14
jne originalcode    // if r10 != 14 then skip this
  mov eax,_health
  mov [eax],rdx
originalcode:
mov eax,[rdx+08]
mov [rcx],00000001
jmp return


so i tried using my old code (that i've used in many games) + your code

Code:
cmp r10,14
jne originalcode    // if r10 != 14 then skip this

push rbx
mov rbx,_health
mov [rbx],rdx
pop rbx

originalcode:
mov eax,[rdx+08]
mov [rcx],00000001
jmp return


and in this case game won't crash, but again it seems like compare is being ignored completely. it gives me totally wrong address like before.

any ideas why? thanks.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Fri May 01, 2020 2:53 pm    Post subject: This post has 1 review(s) Reply with quote

My bad - instead of eax, use rax:
Code:
cmp r10,14
jne originalcode    // if r10 != 14 then skip this
  mov rax,_health
  mov [rax],rdx
originalcode:
mov eax,[rdx+08]
mov [rcx],00000001
jmp return

If it still doesn't work, then r10 isn't equal to 0x14 and/or rdx isn't what you think it is when r10 is 0x14.

_________________
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
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

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

yeah this one works, thanks. i thoguht it was rax instead of eax, but wasn't sure.
but problem is still not fully solved, some other addresses seem to have same values, there's just so many and i didn't check all of them. I just took like 10-20 of them at random and checked, but is there any easy way to compare all addresses at once and find a unique value?

also if it's not too much trouble for you to explain, can you explain the following things:

Why did you remove these two:
push rbx
pop rbx

and what's the difference between eax and rax?
and also what's the difference between rax, rbx, rcx, rdx ..etc? I've always thought that they're the same, just like numbers 1 2 3 4 ..etc that are used to hold different values, but now i'm not so sure.
and why there's no rex and rfx?

edit:
sry also forgot to ask, why can't i use RIP in compare?
register shows RIP and it seems unique value too, but when i replace
cmp R10,14 with cmp RIP,14 then it says it cannot be compiled. hmm?
and finally, how would I go about comparing 2 registers?
for example if I want to do R10 and R11.

edit2:
sry again lol
one more thing i dont get. I see that R9 is also unchanged and unique, so i did this
Code:
cmp R9,6FF61EF61000

but it doesn't work at all. when i use that and activate the script, it simply gives ???? as address (meaning it just finds nothing).
any ideas on this one?


sry i'm not that good in coding and thanks again for the info.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

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

mordax wrote:
is there any easy way to compare all addresses at once and find a unique value?
Easy is relative, but I'd try to automate it with Lua: set a breakpoint, record a context to whatever degree of thoroughness you want (registers, stack, pointers...), let it run for a while, and do basic data analysis to find something the marked ones have in common that all of the others don't.
mordax wrote:
Why did you remove these two:
push rbx
pop rbx
The rax register is overwritten later via "mov eax,[rdx+08]", meaning the game isn't using it now and you can do whatever you want with it. You only need to push / pop registers to back them up.
mordax wrote:
and what's the difference between eax and rax?
Both names eax and rax refer to the same area of memory in the processor, but rax refers to the full 64 bits while eax only refers to the first 32 bits. Addresses are 8 bytes (64 bits) in size, so rax is needed in this case. Using eax is likely to cause problems.
mordax wrote:
and also what's the difference between rax, rbx, rcx, rdx ..etc? I've always thought that they're the same, just like numbers 1 2 3 4 ..etc that are used to hold different values, but now i'm not so sure.
rax, rbx, rcx... are all names that refer to their own area of storage in the processor. Try searching for "x64 cpu register" for more information.
mordax wrote:
and why there's no rex and rfx?
Because cpu manufacturers didn't feel like putting more registers in the cpu.
If you're referring to the newer r8...r15 registers, they're used slightly differently from rax, rbx, rcx... and therefore should have different names. (this difference is inconsequential to most users)
mordax wrote:
sry also forgot to ask, why can't i use RIP in compare?
rip is special in that it points to the instruction to execute. You can only access it using special instructions like call and jmp. It's not a general purpose register like rax, rbx, rcx... are.
mordax wrote:
register shows RIP and it seems unique value too, but when i replace
cmp R10,14 with cmp RIP,14 then it says it cannot be compiled. hmm?
If rip is unique, you aren't looking at the same instruction.
mordax wrote:
and finally, how would I go about comparing 2 registers?
for example if I want to do R10 and R11.
Code:
cmp r10,r11

mordax wrote:
one more thing i dont get. I see that R9 is also unchanged and unique, so i did this...
That looks like a pointer; it's probably going to change when you restart the game. Or it's going to change later on at some point as I believe you're experiencing.

Don't say something is consistent and/or unique if you've only done a few tests. Ideally you'd do hundreds of tests for every possible value it could access across several instances of the game- hence why I'd recommend scripting to automate that process.

_________________
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
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

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

thank you so much for the detailed info. it has helped a lot.
I did think that eax is 32 and rax is 64, but didn't want to say anything stupid.

Think I got it working with single compare, but I will try with 2 compares if needed, however where exactly do I insert the values?
for example if i have R10 = 14 and R11 = 15
Doesn't
Code:
cmp R10,R11
just compare R10 to R11?


as about the R9 that looks like a pointer, i'm quite sure it's static address / value. I have restarted the game several times and even installed update in meanwhile and it hasn't changed, so i'm quite sure that pointer / address is static enough to be used. i rarely make many tests, i usually make trainers for my personal use first (or share with friends), i play the game with the trainer and when i'm bored of the game, i sometimes publish them. so during that play-time, i will figure out if the methods i've used are static enough to be put into public trainer or not.

But still the question i have, why doesn't it work in compare? Is there some special syntax or way of adding such values / addresses into compare?
Back to top
View user's profile Send private message
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

PostPosted: Thu Sep 08, 2022 2:13 pm    Post subject: Reply with quote

bump .. anyone? how do I use 2 compares?
I need to compare R9 and check if value is 5
AND
compare R10 and check if values is 10

IF R9 = 5 AND R10 = 10 THEN use custom code.
someone here said use

cmp R9,R10, but what use is that? I don't need to compare R9 to R10
I need to check both register values and only jump to custom code if both match my values I check them against.
I tried:
Code:

cmp [R9,5],[R10,10]
cmp [R9,5]+[R10,10]
cmp [R9,5+R10,10]
cmp [R9,R10],15
cmp [R9+R10],15
cmp R9,5 and R10,10
cmp R9,5 and cmp R10,10

none of them worked.

would be great if someone can point out what i'm doing wrong and how to fix this.
Thanks.
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Thu Sep 08, 2022 2:47 pm    Post subject: Reply with quote

Think sequentially:

CMP R9, 5
JNE Failure/Return
CMP R10, 10
JNE Failure/Return

...Your code should go here.

Failure/Return:
Back to top
View user's profile Send private message
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

PostPosted: Thu Sep 08, 2022 4:27 pm    Post subject: Reply with quote

cooleko wrote:
Think sequentially:

CMP R9, 5
JNE Failure/Return
CMP R10, 10
JNE Failure/Return

...Your code should go here.

Failure/Return:


thanks, but definitly NOT because


this is my current code (which doesnt work as intended


i have done this in other games and also in this game (before the update) and with single compare it worked fine. but as i said, now the game has updated and there are other addresses with same register entires, but i think none have R9=5 AND R14=10
this is why i need a way to compare both register values and check if they are same.



currentre.JPG
 Description:
 Filesize:  28.22 KB
 Viewed:  2865 Time(s)

currentre.JPG



faile.JPG
 Description:
 Filesize:  29.27 KB
 Viewed:  2865 Time(s)

faile.JPG


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

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Sep 08, 2022 5:49 pm    Post subject: Reply with quote

You're expected to replace "Failure/Return" with the actual destination you want to jump to.
If you want to copy/paste code, don't ask for help: ask someone else to write it for you.

Also:
cooleko wrote:
Code:
cmp ...
jne ...
cmp ...
jne ...
mordax wrote:
Code:
cmp ...
cmp ...
jne ...

_________________
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
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Thu Sep 08, 2022 6:27 pm    Post subject: Reply with quote

Sorry about that mordax. Sometimes when we see something super trivial, we don't think about explaining everything and just push the person in the correct direction. Since I didn't know what you were planning on doing, I suggested that you have either a Failure jump or simply skip straight to the return without explaining it thinking that you would pick up on it since you appear to have coding experience but not assembly experience. CE isn't going to like it if you copy the exact label as provided!

If you have two sequential compares as noted by Parkour, the first one does not have effect since the second one overwrites the results of the first so the jump only responds to the second one. You need to have a jump after each compare to make it useful.
Back to top
View user's profile Send private message
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

PostPosted: Fri Sep 09, 2022 5:56 am    Post subject: Reply with quote

cooleko wrote:
Sorry about that mordax. Sometimes when we see something super trivial, we don't think about explaining everything and just push the person in the correct direction. Since I didn't know what you were planning on doing, I suggested that you have either a Failure jump or simply skip straight to the return without explaining it thinking that you would pick up on it since you appear to have coding experience but not assembly experience. CE isn't going to like it if you copy the exact label as provided!

If you have two sequential compares as noted by Parkour, the first one does not have effect since the second one overwrites the results of the first so the jump only responds to the second one. You need to have a jump after each compare to make it useful.


i don't understand the jump part. i always use automatic AOB template that makes the jump for me. how do i know where to make it jump?
jump over the first compare or what?

can you please give me example of working code. thanks.
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Fri Sep 09, 2022 10:06 am    Post subject: Reply with quote

Fix your code as instructed and fix your edits to it and it will work as written.

You changed the original code weirdly, you want to write rax into [rbx].

Fix your compare, fix your write, enjoy success (if the conditions truly appear as expected).

A jump needs a destination, the destination is a label. You only go to the destination if the jump conditions are met. You need to design your logic so you execute when expected, otherwise jump away to execute the original code.
Back to top
View user's profile Send private message
mordax
Expert Cheater
Reputation: 1

Joined: 16 Apr 2010
Posts: 120

PostPosted: Fri Sep 09, 2022 11:38 am    Post subject: Reply with quote

cooleko wrote:
Fix your code as instructed and fix your edits to it and it will work as written.

You changed the original code weirdly, you want to write rax into [rbx].

Fix your compare, fix your write, enjoy success (if the conditions truly appear as expected).

A jump needs a destination, the destination is a label. You only go to the destination if the jump conditions are met. You need to design your logic so you execute when expected, otherwise jump away to execute the original code.


if i would know how to fix, i wouldn't be here asking for help now, would I??
you trying to say that just because you say "fix your code" means that i magically will understand everything? thanks for being a-hole!

also that originalcode is ORIGINAL code that game uses, there's nothing to fix you insult bag. go tell game developers to fix game code, because i didn't write it.

i only came here to ask help with compare. I DONT KNOW HOW TO FIX IT!
i don't know where the jump destination has to be!

I'm asking HOW DO I COMPARE 2 REGISTER VALUES and youre reply is "fix your code" WOW so useful, why didn't I think of that?
Obviously you are just trolling and you don't know yourself how to fix it. so please stop adding more insults if you don't know or are unwilling to help! your insults are not helping!


Last edited by mordax on Sat Sep 10, 2022 5:49 am; edited 1 time in total
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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