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 


Assembly Double comparison (Negate if negative)

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

Joined: 07 Apr 2009
Posts: 95

PostPosted: Fri Aug 11, 2017 8:10 pm    Post subject: Assembly Double comparison (Negate if negative) Reply with quote

Been working on this for hours on end, learned a ridiculous amount, but still not enough to get this working.

I've been trying to simply check if a double amount is negative or positive, and then either add or subtract it from another double.
A ridiculously easy function that I'd easily get working with integers, but with these doubles I'm at a loss.


What I had so far looked like this:
Code:
newmem:
  fld qword ptr [ebp-08] //Code that has the addition/subtraction that needs to be checked.
  fldz
  fcompp
  jb goldRem

  fld qword ptr [ebp-08]
  fld qword ptr [eax+90] //Code that contains the value that gets changed
  faddp
  jmp code

goldRem:
  fld qword ptr [ebp-08]
  fld qword ptr [eax+90]
  fsubp

code:
  fstp qword ptr [eax+90]
  jmp return

GameGold:
  jmp newmem
  nop
return:
registersymbol(GameGold)

This doesn't remotely work, and I found some things like:
fnstsw ax
test ah,41

But putting it after fcompp crashed things, and I don't even know why there's 41 right there.

Any help would be much appreciated.



Additionally, I know I could use fcomp, but I don't know if I'd have to use a value on the same line, or if it'll compare it by 0 if left blank, or if it does the last 2 floats in the register by default.
I'm frustrated how little you can figure out by simply watching code and the values they change.
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 20

Joined: 01 Feb 2016
Posts: 1586

PostPosted: Fri Aug 11, 2017 8:37 pm    Post subject: Reply with quote

you can use:
Code:
JS // jump if sign

Code:
JNS // jump if not sign

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote:
i am a sweetheart.
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 137

Joined: 06 Jul 2014
Posts: 4250

PostPosted: Fri Aug 11, 2017 9:03 pm    Post subject: This post has 1 review(s) Reply with quote

fcom / fcomp / fcompp modifies the FPU status word register, not eflags. You use fnstsw to store the FPU status word register and use that to set eflags as desired. You might as well use ftst if you want to do this.
Code:
push eax
fld qword ptr [ebp-08]
ftst
fstsw ax
test ax,100
pop eax
jcc wherever  // use jz / jnz


It might be more desirable to use fucomi / fucomip to set eflags directly.
Code:
fld qword ptr[ebp-08]
fldz
fucomip
jcc wherever  // use above/below and not greater/less


With the way doubles are encoded (see IEEE 754), you can avoid floating point numbers completely.
Code:
push eax
mov eax,[ebp-04]
test eax,eax
pop eax
jcc wherever  // use js / jns


Alphasoldier wrote:
I'm frustrated how little you can figure out by simply watching code and the values they change.

That's what documentation is for. See Intel's software developer manuals for more information. Volume 2 has information about instructions themselves, and volume 1 has information about the fpu in general.

_________________
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
Alphasoldier
Advanced Cheater
Reputation: 1

Joined: 07 Apr 2009
Posts: 95

PostPosted: Sat Aug 12, 2017 6:01 am    Post subject: Reply with quote

Ah, thank you so much. If I had known there was an instrution that set the eflags, I would've tried that immediately.
I'm still at a loss as to how to use the FPU status word register, but I suppose I'll figure it out in time.

The snippet that it became:
Code:
fld qword ptr [ebp-08]
fldz
fucomip st(0),st(1)
jna goldAdd
Ridiculously simple, and probably not even optimal, but it works.

Quote:
That's what documentation is for. See Intel's software developer manuals for more information. Volume 2 has information about instructions themselves, and volume 1 has information about the fpu in general.

I'm a really poor learner when it comes to simply reading how things work. I'm a much more visceral learner than that. I need examples and direct documentation on what parameters go with which functions.
Yours were perfect, thank you again.


EDIT:

Now that this is working, I'd like to be able to add a permanent symbol to the address that contains the value I'm altering.
Is there any way to do this through auto assembly?
My google-fu is letting me down.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 137

Joined: 06 Jul 2014
Posts: 4250

PostPosted: Sat Aug 12, 2017 8:35 am    Post subject: Reply with quote

Alphasoldier wrote:
I'm still at a loss as to how to use the FPU status word register, but I suppose I'll figure it out in time.

See the section titled "x87 FPU Status Register" in volume 1 of Intel's software developer manuals. There is a chart in that section which shows the condition codes are located at bits 8, 9, 10, and 14 (C0, C1, C2, and C3 respectively).

In volume 2, look at the ftst instruction. It has a very nice chart that shows what the condition code flags are set to based on the input. In this scenario, it looked like C0 would be enough to test for, so I tested the status word register in ax against a word with only bit 8 set (i.e. 0x0100). If the result is 0, then C0 wasn't set, and if it is a non-zero value, then C0 was set.

Alphasoldier wrote:
I'd like to be able to add a permanent symbol to the address that contains the value I'm altering.

You could do it indirectly. Assuming the instruction addresses the memory location via eax+90:
Code:
[ENABLE]
...
alloc(myAddress,4)
registersymbol(myAddress)

code:
  mov [myAddress],eax
  ...

[DISABLE]
dealloc(myAddress)
unregistersymbol(myAddress)
...

Add the address "myAddress" to the address list as a L1 pointer whose first offset is 90.

_________________
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
Alphasoldier
Advanced Cheater
Reputation: 1

Joined: 07 Apr 2009
Posts: 95

PostPosted: Sat Aug 12, 2017 9:11 am    Post subject: Reply with quote

ParkourPenguin wrote:
You could do it indirectly. Assuming the instruction addresses the memory location via eax+90:
Code:
[ENABLE]
...
alloc(myAddress,4)
registersymbol(myAddress)

code:
  mov [myAddress],eax
  ...

[DISABLE]
dealloc(myAddress)
unregistersymbol(myAddress)
...

Add the address "myAddress" to the address list as a L1 pointer whose first offset is 90.

This is more or less what I already have. Thing is, I want to keep the symbol even when the script is deactivated. Which means I can't deallocate or unregister the symbol.
Is there another way around this? Or am I stuck to the script? I don't particularly mind, but I'd like to know if it's possible.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 137

Joined: 06 Jul 2014
Posts: 4250

PostPosted: Sat Aug 12, 2017 9:16 am    Post subject: Reply with quote

Use globalalloc.
Code:
[ENABLE]
...
globalalloc(myAddress,4)

code:
  mov [myAddress],eax
  ...

[DISABLE]
...

It registers the symbol automatically and will only allocate the memory for a particular symbol once.

_________________
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
Alphasoldier
Advanced Cheater
Reputation: 1

Joined: 07 Apr 2009
Posts: 95

PostPosted: Sat Aug 12, 2017 12:12 pm    Post subject: Reply with quote

Absolutely perfect, all questions answered. This'll definitely help me in future endeavors.
Thanks again!
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