View previous topic :: View next topic |
Author |
Message |
Jackey23 How do I cheat? Reputation: 0
Joined: 17 Sep 2019 Posts: 5
|
Posted: Sat Oct 05, 2019 11:32 am Post subject: How do floats work? |
|
|
For example, in Hotline Miami 2 WR the float 1.875 is 1 and the number 2 is just 2 and 3 is 2.125. How does that work?
|
|
Back to top |
|
|
Meas Newbie cheater Reputation: 0
Joined: 31 Oct 2015 Posts: 18
|
Posted: Mon Oct 07, 2019 6:43 am Post subject: |
|
|
Can you give me details on which value you mean? Maybe post some screenshots.
Integer 2 is the same as float 2.0. They shouldn't vary unless the game's code is scaling the values.
|
|
Back to top |
|
|
Jackey23 How do I cheat? Reputation: 0
Joined: 17 Sep 2019 Posts: 5
|
Posted: Sat Oct 12, 2019 10:10 am Post subject: |
|
|
Ok, Im just gonna say, in hotline miami 2 wrong nubmer there is a combo system and when I got a combo of 1 the value in cheat engine is 1.875 and combo of 2 is 2 and 3 is 2.125 and 45 is 3.1015625, that makes on sense
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Sat Oct 12, 2019 11:47 am Post subject: |
|
|
This looks like Java type conversions. Seen this before on a few games where values are stored as one thing and converted back to another for use. Java implements their floating point math and types via:
https://en.wikipedia.org/wiki/IEEE_754
In the JDK you can see the source as to how these are converted here:
https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/native/java/lang/Double.c#L52
https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/native/java/lang/Float.c#L35
You can recreate these calls in C++ to perform the same conversion/math and get the results you are seeing like this:
Code: |
#include <Windows.h>
#include <string>
/**
* Java function to convert a double to int64_t. (IEEE 754)
*/
int64_t Java_DoubleToLongBits(double d)
{
union
{
int64_t l;
double d;
} u;
u.d = (double)d;
return u.l;
}
/**
* Java function to convert an int32_t to float. (IEEE 754)
*/
float Java_IntBitsToFloat(int32_t n)
{
union
{
int32_t i;
float f;
} u;
u.i = n;
return (float)u.f;
}
/**
* Application entry point.
*/
int32_t __cdecl main(int32_t argc, char* argv[])
{
for (auto x = 0; x < 50; x++)
{
// Convert the int to Java long bits..
const auto bits = Java_DoubleToLongBits((double)x);
// Convert the long bits to a float.. (Shifting from 64bit to 32bit sized value.)
const auto f = Java_IntBitsToFloat(bits >> 32);
// Print the result..
printf_s("%d - %f\r\n", x, f);
}
return 0;
}
|
Which gives:
Code: |
0 - 0.000000
1 - 1.875000
2 - 2.000000
3 - 2.125000
4 - 2.250000
5 - 2.312500
6 - 2.375000
7 - 2.437500
8 - 2.500000
9 - 2.531250
10 - 2.562500
11 - 2.593750
12 - 2.625000
13 - 2.656250
14 - 2.687500
15 - 2.718750
16 - 2.750000
17 - 2.765625
18 - 2.781250
19 - 2.796875
20 - 2.812500
21 - 2.828125
22 - 2.843750
23 - 2.859375
24 - 2.875000
25 - 2.890625
26 - 2.906250
27 - 2.921875
28 - 2.937500
29 - 2.953125
30 - 2.968750
31 - 2.984375
32 - 3.000000
33 - 3.007813
34 - 3.015625
35 - 3.023438
36 - 3.031250
37 - 3.039063
38 - 3.046875
39 - 3.054688
40 - 3.062500
41 - 3.070313
42 - 3.078125
43 - 3.085938
44 - 3.093750
45 - 3.101563
46 - 3.109375
47 - 3.117188
48 - 3.125000
49 - 3.132813
|
_________________
- Retired. |
|
Back to top |
|
|
Jackey23 How do I cheat? Reputation: 0
Joined: 17 Sep 2019 Posts: 5
|
Posted: Sat Oct 19, 2019 12:45 pm Post subject: |
|
|
So what could I change in the code that you wrote to get a float of a number I want, because I don't understand any of the code you wrote
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
Posted: Sat Oct 19, 2019 6:59 pm Post subject: |
|
|
Code: |
// Change x's value for what you want to convert..
const auto x = 1;
// Convert the int to Java long bits..
const auto bits = Java_DoubleToLongBits((double)x);
// Convert the long bits to a float.. (Shifting from 64bit to 32bit sized value.)
const auto f = Java_IntBitsToFloat(bits >> 32);
// Print the result..
printf_s("%d - %f\r\n", x, f);
|
You can take this chunk, change x's value at the top to have it spit out the value you want to convert.
_________________
- Retired. |
|
Back to top |
|
|
Jackey23 How do I cheat? Reputation: 0
Joined: 17 Sep 2019 Posts: 5
|
Posted: Sun Oct 20, 2019 4:01 am Post subject: |
|
|
Thanks a lot
|
|
Back to top |
|
|
|