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 


Add Fixed Number to Float Value?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Feb 07, 2022 7:12 pm    Post subject: Add Fixed Number to Float Value? Reply with quote

I am trying to add (float)3 on top of the elevation value, but I am not sure how to do it.

For example, this will not work:


Code:
mov rdx,[elevation_value]
add rdx,(float)3               // I want to take the elevation_value and add float 3 to it
mov [rdi+78],rdx               // [rdi+78] contains vertical coordinate


This code appears to overwrite rdx with (float) 3 instead of adding it on top of elevation_value for some reason.

To clarify, if elevation_value is (float)100, then I want to be able to add 3 on top of it, so that it becomes (float)103 before it gets loaded into the vertical coordinate value.

How to do this properly?

Thanks.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Mon Feb 07, 2022 7:26 pm    Post subject: This post has 1 review(s) Reply with quote

probably something like:

Code:

alloc(value3,4)
...
value3:
dd (float)3
...
movss xmm1,[elevation_value]
addss xmm1,[value3]
movss [rdi+78],xmm1


or
Code:

mov rdx,[elevation_value]
{$ccode ev=rdxf}
ev=ev+3.0f
{$asm}
mov [rdi+78],rdx

_________________
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
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Tue Feb 08, 2022 5:00 am    Post subject: Reply with quote

You are awesome, DB. Thank you very much.

By the way, the first solution worked, but the second one did not work for some reason.

Thanks so much.
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3337

PostPosted: Tue Feb 08, 2022 7:33 am    Post subject: This post has 1 review(s) Reply with quote

Code:
push (float)3.0
addss xmm1,[rsp]
add rsp,8

?
If the value is always the same, allocating that and using that address directly like DB suggested is faster.
I.e.
Code:

addss xmm1,[myvalue]
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Tue Feb 08, 2022 4:21 pm    Post subject: Reply with quote

Quote:

By the way, the first solution worked, but the second one did not work for some reason.

Right, there is an issue with the XXXf reg notation in ccode (picks the wrong reg)

for now should be able to do:
Code:

{$ccode ev=rdx}
float *evfix=(float*)&ev;
*ev=*ev+3.0f
{$asm}

_________________
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
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Tue Feb 08, 2022 4:29 pm    Post subject: Reply with quote

Thank you, Csimbi and Dark Byte. I really appreciate everyone's help.
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