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 


Subtracting Floats

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

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Fri May 28, 2021 5:09 am    Post subject: Subtracting Floats Reply with quote

I'm completely lost, but this is a bit more complicated than I thought it would need to be.. unless I'm just being an idiot but I've been trying to do this for hours and I'm at my limit.

Just trying to store the difference in hits between the previous and current HP bars of a boss shield, as "shield_hit"

There's plenty of comments in the attached image so it should be explanatory enough, but "shield_hit" always contains 0? The actual shield value decreases so I'm not sure what the issue is.. I've tried so many different approaches to this and I just can't get it. My best guess is Line 86's pop EDX interrupting the cmp? Not too familiar with the conditions but I think I recall seeing it was okay to do this way.. otherwise EDX would need to be popped under code2 which won't always have it pushed to the stack.. maybe a better way I can do that section.
Help super appreciated.



subtraction sucks.png
 Description:
 Filesize:  123.94 KB
 Viewed:  1940 Time(s)

subtraction sucks.png


Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Fri May 28, 2021 1:55 pm    Post subject: This post has 1 review(s) Reply with quote

You don't reset the stats if the enemy changes.

You should be pushing and popping the entire register- not just the lower 32 bits. Most modifications to 32-bit registers zero extend to the upper 32 bits. If the game is using the upper 32 bits for something, e.g. a pointer, then the game would crash since you didn't restore it properly.

You seem to have no idea what's a pointer and what's a value. "boss_shield" is a symbol that I presume represents an address in memory allocated by CE (either by an alloc or by a label defined under an alloc). "[boss_shield]" is a pointer you store with "mov [boss_shield],rdi" - it is not a float value as you seem to think it is with the instructions "mov eax,[boss_shield]" and "cmp [boss_shield],edx".

You shouldn't be trying to compare floating point values with integer cmp instructions. Coincidentally, it usually works out anyway.

I can't think of any reason anyone should ever push the stack pointer (rsp) onto the stack.

Code:
mov ebx,[last_shield]
mov ecx,[boss_shield]
movdqu [esp],xmm1
movss xmm1,[ebx]
subss xmm1,[ecx]
pop ecx
movss [ebx],xmm1
movss xmm1,[esp]
  • Addressing modes in 64-bit processes use 64-bit registers (i.e. use rsp instead of esp).
  • You didn't allocate space on the stack for the double stored by movdqu.
  • I think you mean for ebx and ecx to be float values, not pointers. The fact that they're pointers means this code might not crash the game; however, the difference will always be 0 since they point to the same address.
  • You're trying to read a single (float) from the stack when you stored a double. SSE can't magically convert between types the same way x87 can. (you also aren't backing up the rest of xmm1, but the game probably isn't using it anyway)

I'm genuinely surprised at the amount of luck required for that code to not crash the game.

You're making this more complicated than it needs to be. I'm not sure you need to do anything special: why not use the value at rsp+50? It looks like the last damage to the shield. No need to do anything with SSE instructions - just copy that value.

_________________
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
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Fri May 28, 2021 2:13 pm    Post subject: Reply with quote

Thanks for the feedback.. just trying to work with what I know and clearly not well enough, haha.

I originally attempted to just take rsp+50's value as the damage, but for whatever reason in doing so it's the previous shield hp, before damage (I should just check what's in xmm0 I guess).. so I tried this stupid workaround to just math it out.

Unfortunately a lot of my learning has been through secondhand examples, brief documentation and a lot of trial and error, so I appreciate you telling me what's wrong with all this. I'll have another proper go at this later on, thanks again.
Back to top
View user's profile Send private message Visit poster's website
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Fri May 28, 2021 2:43 pm    Post subject: Reply with quote

I'd put a breakpoint at the instruction "subss xmm0,[rsp+50]", look at what xmm0 is, step over the instruction, then look at how it changed.

Breakpoints are really nice for learning what code does. Learning how to use them should be one of the first things you do. (unlike assembly, basic operations with breakpoints can be learned through trial and error easily)

_________________
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
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