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 


redudnant/reduce code?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Diambro
Newbie cheater
Reputation: 0

Joined: 12 Sep 2023
Posts: 23
Location: Austria

PostPosted: Sun Sep 01, 2024 7:59 am    Post subject: redudnant/reduce code? Reply with quote

Hey Community!

Just wanted to ask if this can get reduced somehow or if its ok this way. Its working like intended.

Code:

dmg_code:
  cmp r14,[pPlayer]
  jne dmg_enemy
  cmp [iHP],1
  jne dmg_exit
  cvtsd2ss xmm5,xmm0
  movss xmm5,[r14+00000234]
  jmp dmg_return
dmg_enemy:
  movsd xmm12,[iDMG]          //Main value for OHK,DamageMul
  movsd xmm13,[iCMP]          //iCMP holds (double)1
  ucomisd xmm12,xmm13      //checks if value is 1
  jb dmg_ohk
  je dmg_exit
  mulsd xmm1,xmm12
  xorpd xmm12,xmm12
  xorpd xmm13,xmm13
  jmp dmg_exit
dmg_ohk:
  movsd xmm1,xmm0
dmg_exit:
  subsd xmm0,xmm1
  cvtsd2ss xmm5,xmm0
  jmp dmg_return


specificly the part around the xmm12 and xmm13 compares. I had to make a iCMP value just for the check if the value is 1 or not. Is there an easier way to compare it?

Thanks in advance
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4695

PostPosted: Sun Sep 01, 2024 4:51 pm    Post subject: Reply with quote

The second parameter of `ucomisd` can be a memory location. e.g. `ucomisd xmm12,[iCMP]`

Beyond that, what you're doing is fine. The canonical way to compare a floating point value against a constant is to store the constant in memory and use that memory location in the comparison.

There isn't really a comparison that uses an immediate value. Maybe you could do `mov r64,imm64` then `movd xmm,r/m64` to avoid the memory access, but I don't know enough about compilers or low-level micro-ops to say why that isn't really used in practice or if it's a good thing to do in the first place.

Why the `xorpd`? If the game isn't using xmm12 or xmm13, that does nothing. If it is using xmm12 or xmm13 and you don't want to screw with what the game's doing, you should back them up to the stack (movups / movupd)

_________________
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
Diambro
Newbie cheater
Reputation: 0

Joined: 12 Sep 2023
Posts: 23
Location: Austria

PostPosted: Mon Sep 02, 2024 1:31 pm    Post subject: Reply with quote

Thanks for the reply!

ParkourPenguin wrote:
The second parameter of `ucomisd` can be a memory location. e.g. `ucomisd xmm12,[iCMP]`...


Ah thats good to know, already reduced it with that, thanks!

ParkourPenguin wrote:
...There isn't really a comparison that uses an immediate value. Maybe you could do `mov r64,imm64` then `movd xmm,r/m64` to avoid the memory access, but I don't know enough about compilers or low-level micro-ops to say why that isn't really used in practice or if it's a good thing to do in the first place....


i better leave it as is then. Im not even sure what half those words mean, gotta read into them.

ParkourPenguin wrote:
Why the `xorpd`? If the game isn't using xmm12 or xmm13, that does nothing. If it is using xmm12 or xmm13 and you don't want to screw with what the game's doing, you should back them up to the stack (movups / movupd)


Yeah both registers where zero so i thought better make sure to keep em like that. So you say i probably should do it like that?:

Code:

....
dmg_enemy:
  push rsi
  movupd [rsi],xmm12
  add rsi,16 
  movupd [rsi],xmm13
  movsd xmm12,[iDMG]
  ucomisd xmm12,[iCMP]
  jb dmg_ohk
  je dmg_exit
  mulsd xmm1,xmm12
  jmp dmg_exit
dmg_ohk:
  movsd xmm1,xmm0
dmg_exit:
  movupd xmm13,[rsi]
  sub rsi,16
  movupd xmm12,[rsi]
  pop rsi
  subsd xmm0,xmm1
  cvtsd2ss xmm5,xmm0
  jmp dmg_return


Or am i thinking wrong? Thanks in advance!

PS: How do i rep?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4695

PostPosted: Mon Sep 02, 2024 2:16 pm    Post subject: This post has 1 review(s) Reply with quote

No, like this:
Code:
sub rsp,20  // allocate 32 bytes on the stack
movupd [rsp],xmm12
movupd [rsp+10],xmm13
...
movupd xmm13,[rsp+10]
movupd xmm12,[rsp]
add rsp,20

IDK about rep. Maybe you get that after a certain number of posts. Don't spam the forum to raise post count- it's very obvious.

_________________
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
Diambro
Newbie cheater
Reputation: 0

Joined: 12 Sep 2023
Posts: 23
Location: Austria

PostPosted: Tue Sep 03, 2024 3:53 am    Post subject: Reply with quote

ParkourPenguin wrote:
IDK about rep. Maybe you get that after a certain number of posts. Don't spam the forum to raise post count- it's very obvious.


Normal forum rules, got it.

Im somehow scared of manipulating rsp, but its working like a charm. Imma keep in mind using this. Oh and yeah since you told me i only need one xmm register i got rid of the second. Thank you again for your guidance!
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