 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
idk31 Cheater
Reputation: 1
Joined: 11 Jan 2016 Posts: 42
|
Posted: Sat Jul 29, 2017 9:07 pm Post subject: Using fpatan and restoring registers correctly? Cam tracker |
|
|
Goal: Aim camera at player (tracking cam). Up/down, Z not important. 64-bit UE4 game. My code works until crash on level change. Values are "???" briefly. Would like a way to account for that and know if my code makes sense, is efficient, and I'm restoring everything I need to correctly. Borrowed code from Dark Byte here to restore xmm0. Is it even necessary? Am I messing something up when I use fld?
Available to use:
[rbx+120] player X
[rbx+124] player Y
[rax+120] camera X
[rax+124] camera Y
[rax+154] camera yaw (degrees)
I made the following:
Code: |
push ecx
sub esp,#20
movdqu [esp],xmm0 //save xmm0. this necessary?
mov ecx,[rbx+124] //player Y
mov [esp+10],ecx
movss xmm0,[esp+10]
subss xmm0,[rax+124] //subtract camera Y
movss [esp+10],xmm0
fld dword ptr [esp+10] //load
mov ecx,[rbx+120] //player X
mov [esp+10],ecx
movss xmm0,[esp+10]
subss xmm0,[rax+120] //subtract camera X
movss [esp+10],xmm0
fld dword ptr [esp+10] //load
fpatan //inverse tan
mov [esp+10],(float)57.29577951308232
fmul dword ptr [esp+10] //multiply to get degrees
fstp dword ptr [rax+154] //set camera yaw
movss xmm0,[esp] //restore xmm0
add esp,#20
pop ecx
|
_________________
|
|
Back to top |
|
 |
panraven Grandmaster Cheater
Reputation: 62
Joined: 01 Oct 2008 Posts: 958
|
Posted: Sun Jul 30, 2017 1:21 am Post subject: |
|
|
The code run on CE's createThread, and seems give correct answer.
but
Code: |
sub esp,#20 /// it is decimal 20, in hex 0x14, which not stack align
...
add esp,#20
|
It may be ok in CE's createThread enviroment, but may cause problem in actual game? ie. 12 bytes (0x20-0x14 = 0xc) in stack may be overwritten.
Also may change all register in memory [ eax + * ] to r-version rax?
Although ce accept them, it may look less confuse.
It seems ok to use all fpu math, (same result as yours)
Code: |
_:
dd (float)3.14151692,(float)180
...
fld dword ptr[rbx+124]
fsub dword ptr[rax+124]
fld dword ptr[rbx+120]
fsub dword ptr[rax+120]
fpatan
fmul dword ptr[_+4] // 180
fdiv dword ptr[_+0] // pi
fstp dword ptr[rax+154]
|
ADDED:
save a link : https://godbolt.org/g/eusJoj generate assembler from c
_________________
- Retarded.
Last edited by panraven on Sun Jul 30, 2017 7:34 am; edited 1 time in total |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25805 Location: The netherlands
|
Posted: Sun Jul 30, 2017 4:11 am Post subject: |
|
|
you are mixing 32-bit and 64-bit together. My example was for 32-bit code
But i think it may work.
But do add some tests for the validity of RBX and RAX, they could be 0
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
idk31 Cheater
Reputation: 1
Joined: 11 Jan 2016 Posts: 42
|
Posted: Sun Jul 30, 2017 12:04 pm Post subject: |
|
|
Panraven, thanks! That's MUCH better than what I was doing I googled for days "fpatan example" and "assembly subtract/multiply float." Nothing was making sense. Then I just cobbled something together. Was surprised when it worked.
Dark Byte, I'm still crashing when values go to "??" I am not sure what it means or how to handle it. The address appears to always be valid. I'm watching it from pointer [_camera+120] I get from "mov [_camera],rax." Do I need isbadreadptr?
I tried (with no luck)...
Code: | cmp [_player],0 //rbx was never more than symbol "_player"
je return
cmp [rax],0
je return
test rax,rax
je return
push rbx
mov rbx,[_player]
//stuff
pop rbx |
Complete table. Point of interest: script "CAMERA," label "doTracking"
_________________
|
|
Back to top |
|
 |
|
|
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
|
|