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 


Need a basic math tutorial for Assembly

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
jim2point0
Master Cheater
Reputation: 4

Joined: 05 Oct 2012
Posts: 336

PostPosted: Wed Sep 03, 2014 12:16 pm    Post subject: Need a basic math tutorial for Assembly Reply with quote

This is probably pretty basic stuff, but for the life of me, I have no idea how to do it.

I have 2 addresses (4 byte) in a game I retrieve via a script. What I want to do is divide 1 number by the other number and store the result in an address I can use in my table. I just don't know the assembly for this. Especially since the numbers are 4 byte, but the result would need to be a float.
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Wed Sep 03, 2014 12:35 pm    Post subject: Re: Need a basic math tutorial for Assembly Reply with quote

jim2point0 wrote:
This is probably pretty basic stuff, but for the life of me, I have no idea how to do it.

I have 2 addresses (4 byte) in a game I retrieve via a script. What I want to do is divide 1 number by the other number and store the result in an address I can use in my table. I just don't know the assembly for this. Especially since the numbers are 4 byte, but the result would need to be a float.


Use fild to load the integer into ST(0),and fidiv to divide it by the other int,it'll save the result in ST(0),then use fstp to pop it out to the destination.
Back to top
View user's profile Send private message
Gi@nnis
Cheater
Reputation: 1

Joined: 26 Oct 2013
Posts: 32
Location: Greece

PostPosted: Sat Sep 06, 2014 3:29 am    Post subject: Reply with quote

Exactly what Redone said.

Assuming that the first address is called AddressA, the second AddressB and the address where you want to store the results is AddressF.
Code:

Fild Dword PTR [AddressA]
Fidiv Dword PTR [AddressB]
Fstp Dword PTR [AddressF]


Waring! Make sure that AddressB hold a none 0 value. You can do something like this:
Code:

Cmp Dwrod PTR [AddressB],0
Jz DIV0
Back to top
View user's profile Send private message
jim2point0
Master Cheater
Reputation: 4

Joined: 05 Oct 2012
Posts: 336

PostPosted: Mon Sep 08, 2014 3:43 am    Post subject: This post has 1 review(s) Reply with quote

Thanks guys! This worked Smile

What I was trying to do was solve an issue in Castlevania: Lords of Shadow 2. The game only renders in 16:9, even if you force a custom windowed resolution (2560x1080) for example.

So I figured out where the game is storing the values for your current resolution (hardcoded...). Using those addresses, I'm figuring out the proper aspect ratio and overriding the location where the game stores the 16:9 aspect ratio.

So now when I enable the script, the game is no longer stretching 16:9 to 2.37:1.

Before fix:


With my script enabled:



Code:
newmem:
cmp [aspectRatio],0
jne useNew
push ebx
push edi
mov ebx,[CLOS2.exe+83A6B8]
mov edi,[CLOS2.exe+83A6Bc]
mov [resWidth],ebx
mov [resHeight],edi
pop edi
pop ebx
Fild Dword PTR [resWidth]
Fidiv Dword PTR [resHeight]
Fstp Dword PTR [aspectRatio]
jmp exit

useNew:
push edi
mov edi,[aspectRatio]
mov [CLOS2.exe+905C24],edi
pop edi
jmp exit
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