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 


Simple Division Question?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Humam2104
How do I cheat?
Reputation: 0

Joined: 27 May 2022
Posts: 2

PostPosted: Fri May 27, 2022 11:14 pm    Post subject: Simple Division Question? Reply with quote

I'm creating a simple function that divides damage

The original line of code is:
Code:
  mov [rbx+000003E8],eax

Replacing this line of code in the memory viewer removes all damage.
My idea is divide the damage by 2 for example (damage and health are integers)

But the game crashes whenever I try this simple division

Code:

DamageAI:

  mov ax, [eax]
  mov bx, 2
  div bx //causes crash, skipping this line wouldn't cause a crash
  mov [rbx+000003E8],eax
  jmp return


Thank you. I hope someone helps me with this because most guides I've seen deal with xmm values and I already used divss before once. But I'm having difficulty dealing with integer divisions.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4297

PostPosted: Sat May 28, 2022 12:21 am    Post subject: Reply with quote

Why are you using 16-bit registers? The original code makes it look like a 32-bit value.

You're modifying rbx without backing it up. (bx is the lower 16 bits of rbx)
You need to back up rdx too. It needs to be set to 0 prior to the div, and the remainder of the div gets written to dx.

Anyway, if you're dividing by a power of 2, shift right:
Code:
newmem:
  shr eax,1
  mov [rbx+3E8],eax
  jmp return

General integer division:
Code:
label(divisor)

newmem:
  push rcx
  push rdx
  mov ecx,[divisor]
  xor edx,edx
  div ecx
  pop rdx
  pop rcx
  mov [rbx+3E8],eax
  jmp return

align 4 CC
divisor:
  dd 2

Integer division using floating point arithmetic:
Code:
label(divisor)

newmem:
  pxor xmm0,xmm0
  cvtsi2ss xmm0,eax
  divss xmm0,[divisor]
  cvttss2si eax,xmm0
  mov [rbx+3E8],eax
  jmp return

align 4 CC
divisor:
  dd (float)2.0

All this is assuming eax is the damage being done and not your actual health.

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