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 


How to compare the first digit after decimal point in float?

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

Joined: 30 Jan 2023
Posts: 118

PostPosted: Mon May 15, 2023 7:08 pm    Post subject: How to compare the first digit after decimal point in float? Reply with quote

Is there a way to compare to the first digit after a decimal point in a float?

For example if * were a wildcard...
//theory of what a code might look like to check if the first digit after the decimal point is a 0
comiss [rbx+34],(float)*.0
jne game.exe+C94230


In this example a 23.0 float would be a match but 23.7 would not.
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon May 15, 2023 7:12 pm    Post subject: Reply with quote

The first thing that comes to mind is to use hex, but I'm not quite sure that I am fully understanding your question. You can also filter out everything that is above or below a particular value.
Back to top
View user's profile Send private message
Autem
Expert Cheater
Reputation: 1

Joined: 30 Jan 2023
Posts: 118

PostPosted: Mon May 15, 2023 7:16 pm    Post subject: Reply with quote

I'm trying to compare the first digit after the decimal point in a float and find out if it's a 0. I will never know the number before the decimal point, so that part can be a wildcard.

Floats like these would match...
45.0
339.0
1246.0
1.0

Floats like these would not...
45.1
339.803382
1246.483384
1.9999321

So something like a wildcard comes to mind in float form of: *.0
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon May 15, 2023 7:40 pm    Post subject: Reply with quote

Autem wrote:
I'm trying to compare the first digit after the decimal point in a float and find out if it's a 0. I will never know the number before the decimal point, so that part can be a wildcard.
-I see. Probably, you can do this easily with lua. Curious what you are doing and why, though. Like, why can you never know the value before the decimal point, and why are you only interested in comparing the value after the decimal point?

I see you doing many different things lately, and I often wonder if you are going about things in the best way. In this case, maybe you are, but I cannot think of any reason why you would need to do this, so I am really curious about it.
Back to top
View user's profile Send private message
Autem
Expert Cheater
Reputation: 1

Joined: 30 Jan 2023
Posts: 118

PostPosted: Mon May 15, 2023 7:50 pm    Post subject: Reply with quote

++METHOS wrote:
Curious what you are doing and why, though. Like, why can you never know the value before the decimal point, and why are you only interested in comparing the value after the decimal point?


The float value being checked will be counting down from a random number to 0, at which point it triggers an action in the game.

Sometimes this value has just been set, and is not yet counting down. Other times, it's already counting down.

I am trying to differentiate between a value that already has begun counting down, and one that has not.

If the value has not started counting down yet, it'll still be more like a whole number in float form, such as 48.0 or 22.0 and so on...

Since I never know what the starting random number will be, I only know that the starting number will have a 0 after the decimal point.

My earlier example was this, to give some idea of what I mean in code form even tho I know this is incorrect:
Code:
//theory of what a code might look like to check if the first digit after the decimal point is a 0
comiss [rbx+34],(float)*.0
jne game.exe+C94230
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 941

PostPosted: Mon May 15, 2023 8:52 pm    Post subject: Reply with quote

Not sure it make sense or correct ...

If we can take the fractional part we can compare it to see how close the original float
to a integer boundary, it seems no such instruction but there instruction to the integral
part, which let us compute the fractional. Assume the original float is non-negative finite
(not NaN or +/-inf), then we can do
Code:

  round down case: fractional= orig - int<orig>
    if fractional <0.0001 then integral_float;
  round up case:   fractional= int<orig> - orig
    if fractional >0.9999 then integral_float;

We can test round up or down with the sign of orig - int<orig>.

There are instructions
CVTTSD2SI https://www.felixcloutier.com/x86/cvttps2pi
and
FISTTP https://www.felixcloutier.com/x86/fisttp
that say 'chop'(round down?), so the test with above assumption <ie.non-negative finite>
should come down to only one comparison.

Without testing, the code might be
Code:

sub      rsp,10                          - st: - ; rsp: [?]
fld      dword ptr[original_float]       - st: [original] ; rsp: [?]
fld      dword ptr[original_float]       - st: [original] [original] ; rsp: [?]
FISTTP   dword ptr[rsp]                  - st: [original] ; rsp: [int<original>]
fsub     dword ptr[rsp]                  - st: [original - int<original> = fractional] ; rsp: [int<original>]
fstp     dword ptr[rsp]                  - st: - ; rsp: [fractional]
cmp      dword ptr[rsp],(float)0.0001 - compare the magnitude of fractional
add      rsp,10
jl       to_do_integral
...      to_do_fractional


upd: typo, express the idea with a bit more detail.

_________________
- Retarded.


Last edited by panraven on Tue May 16, 2023 2:18 am; edited 1 time in total
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon May 15, 2023 9:53 pm    Post subject: Reply with quote

Autem wrote:
The float value being checked will be counting down from a random number to 0, at which point it triggers an action in the game.

Sometimes this value has just been set, and is not yet counting down. Other times, it's already counting down.

I am trying to differentiate between a value that already has begun counting down, and one that has not.
-Thanks for explaining. I suspect that there may be a better way to go about this, but you would need to examine the assembly code before this code gets executed, to see how the values are generated, for example. You could probably even find a call or jump that only gets executed before or after the timer starts, which might be easier. There is likely a trigger/flag that gets set, that initializes the timer.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Mon May 15, 2023 10:28 pm    Post subject: Reply with quote

Autem wrote:
If the value has not started counting down yet, it'll still be more like a whole number in float form, such as 48.0 or 22.0 and so on...

Check the "Lua formula" checkbox to the right and use this as the search value:
Code:
value//1==value and value>0 and value<100
`//` is the integer division operator (basically Math.floor but can be used in an empty Lua state). The rest should be self explanatory; if not, look up a Lua tutorial for beginners
_________________
I don't know where I'm going, but I'll figure it out when I get there.
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