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 


Using fpatan and restoring registers correctly? Cam tracker

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
idk31
Cheater
Reputation: 1

Joined: 11 Jan 2016
Posts: 42

PostPosted: Sat Jul 29, 2017 9:07 pm    Post subject: Using fpatan and restoring registers correctly? Cam tracker Reply with quote

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
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Sun Jul 30, 2017 1:21 am    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25805
Location: The netherlands

PostPosted: Sun Jul 30, 2017 4:11 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
idk31
Cheater
Reputation: 1

Joined: 11 Jan 2016
Posts: 42

PostPosted: Sun Jul 30, 2017 12:04 pm    Post subject: Reply with quote

Panraven, thanks! That's MUCH better than what I was doing Smile 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
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