| View previous topic :: View next topic |
| Author |
Message |
jim2point0 Master Cheater
Reputation: 4
Joined: 05 Oct 2012 Posts: 336
|
Posted: Wed Sep 03, 2014 12:16 pm Post subject: Need a basic math tutorial for Assembly |
|
|
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 |
|
 |
Redouane Master Cheater
Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Wed Sep 03, 2014 12:35 pm Post subject: Re: Need a basic math tutorial for Assembly |
|
|
| 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 |
|
 |
Gi@nnis Cheater
Reputation: 1
Joined: 26 Oct 2013 Posts: 32 Location: Greece
|
Posted: Sat Sep 06, 2014 3:29 am Post subject: |
|
|
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 |
|
 |
jim2point0 Master Cheater
Reputation: 4
Joined: 05 Oct 2012 Posts: 336
|
Posted: Mon Sep 08, 2014 3:43 am Post subject: |
|
|
Thanks guys! This worked
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 |
|
 |
|