 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
deama1234 Master Cheater
Reputation: 3
Joined: 20 Dec 2014 Posts: 328
|
Posted: Thu May 21, 2015 10:47 am Post subject: ASM convert unsigned to signed int? |
|
|
I'm doing some calculations in the FPU, and I need the result to be an int, so I use "fistp [hp]". Problem is, if the calculations result in a float of "-50" and it converts it via "fistp [hp]" then it comes out as 4294967296 (or something like that) and then that screws up the rest of the calculations.
How would I convert 4294967296 to a 32int signed? |
|
Back to top |
|
 |
Gniarf Grandmaster Cheater Supreme
Reputation: 43
Joined: 12 Mar 2012 Posts: 1285
|
Posted: Thu May 21, 2015 12:17 pm Post subject: |
|
|
0xFFFFFFCE = 4294967246 (read as an unsigned integer) = -50 (read as a signed integer). You don't have to convert them, just look at them differently. If you're checking the result of your calculation in CE and it shows you a 4294967246 in your cheat table, right click on it->show as signed.
As for your calculations, you have to tell the next instruction to read your number as signed integer. If the next thing you do is a cmp, know that cmp+ja/jb does unsigned comparison and cmp+jg/jl does signed comparison. _________________
DO NOT PM me if you want help on making/fixing/using a hack. |
|
Back to top |
|
 |
deama1234 Master Cheater
Reputation: 3
Joined: 20 Dec 2014 Posts: 328
|
Posted: Thu May 21, 2015 12:33 pm Post subject: |
|
|
What if I have something like:
mov ebx,[hp]
add [eax+4],ebx
how would I tell it to read it as a signed? |
|
Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
|
Back to top |
|
 |
deama1234 Master Cheater
Reputation: 3
Joined: 20 Dec 2014 Posts: 328
|
Posted: Thu May 21, 2015 1:06 pm Post subject: |
|
|
I'm not too good with that technical talk. So, if I had an unsigned value adding to some other value, the CPU would process the calculation beforehand, converting unsigned to signed and then performing the calculation? Then the result would be a signed value right?
EDIT: Well, I got this
Code: | movss [newHP],xmm6
fld [newHP] //new hp
fsub [rax+rcx*4+04] //new - old
fistp [hp]
cmp [hp],0
je exit
cmp [hp],0
jg check2
cmp [hp],0
jl check3
jmp exit |
and the jump ones don't work right. What happens is it always goes to check3, even if the result is higher than 0.
However, if I do:
Code: | movss [newHP],xmm6
fld [newHP] //new hp
fsub [rax+rcx*4+04] //new - old
mov [newHP],(float)1000
fadd [newHP]
fistp [hp]
cmp [hp],0
je exit
cmp [hp],0
jg check2
cmp [hp],0
jl check3
jmp exit |
then it works! But this screws up my calculations at check2/3.
EDIT2: Nvm, nothing works, my brain hurts, help?
EDIT3: Uhh, nvm. |
|
Back to top |
|
 |
Gniarf Grandmaster Cheater Supreme
Reputation: 43
Joined: 12 Mar 2012 Posts: 1285
|
Posted: Thu May 21, 2015 5:12 pm Post subject: |
|
|
deama1234 wrote: |
I'm not too good with that technical talk. So, if I had an unsigned value adding to some other value, the CPU would process the calculation beforehand, converting unsigned to signed and then performing the calculation? Then the result would be a signed value right? | Well the fun thing is that adding to a signed or unsigned integer gives the same result. ie:
if 0xFFFFFFCE = 4294967246 (unsigned integer) = -50 (signed) and 50=0x32.
0xFFFFFFCE+0x32=0
4294967246+50=0 (on 32bit integers)
-50+50=0
and with 49=0x31
0xFFFFFFCE+0x31=0xFFFFFFFF=-1=4294967295
deama1234 wrote: | EDIT: Well, I got this
Code: | movss [newHP],xmm6
fld [newHP] //new hp
fsub [rax+rcx*4+04] //new - old
fistp [hp]
cmp [hp],0
je exit
cmp [hp],0
jg check2
cmp [hp],0
jl check3
jmp exit |
and the jump ones don't work right. What happens is it always goes to check3, even if the result is higher than 0. | I ran this piece of code Code: | cmp [hp],0
je exit
cmp [hp],0
jg check2
cmp [hp],0
jl check3
jmp exit
check2:
mov eax,1
retn
check3:
mov eax,2
retn
exit:
retn
| And if I manually set hp to 0 in CE the execution goes to exit.
hp to -50 -> check3 (also tried with -999999999)
hp to +50 -> check2 (also tried with +999999999)
So the comparison seems ok, are you absolutely sure that hp is what you think when it enters the cmp's? Can you put a breakpoint on the first cmp and look at hp at that time?
Literally, Post scriptum: deama1234 wrote: | EDIT3: Uhh, nvm. | Ah, err, so it works in the end? _________________
DO NOT PM me if you want help on making/fixing/using a hack. |
|
Back to top |
|
 |
deama1234 Master Cheater
Reputation: 3
Joined: 20 Dec 2014 Posts: 328
|
Posted: Thu May 21, 2015 8:05 pm Post subject: |
|
|
Mmm, yeah. Should of made it clear, sorry; brain was still melted. |
|
Back to top |
|
 |
|
|
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
|
|