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 


[.net] Floats?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Polynomial
Grandmaster Cheater
Reputation: 5

Joined: 17 Feb 2008
Posts: 524
Location: Inside the Intel CET shadow stack

PostPosted: Sat Feb 19, 2011 4:32 am    Post subject: Reply with quote

Just as a note here:

IEEE floats do not have any defined endianness when abstracted, so they may be stored in either (i.e. 0x01234567 or 0x67452301) in memory depending on how the compiler works. In .NET the endianness may be totally different to the implementation of Java, or the endianness of C. Some compilers tie to the standard endianness of the model of processor that is being targeted (e.g. little-endian on Intel CPUs) whereas some stick to one endian type regardless of target architecture. Some may actually switch endianness depending on the OS you target (e.g. cross-platform framework). When you use Array.Reverse() on a byte array being passed to a BitConverter function, you are flipping the endianness. It may actually turn out that in certain strange circumstances you are in fact required not to reverse it. The way to check is with the BitConverter.IsLittleEndian value. I would imagine in this case the answer is false, but if not then it means you're attaching to a process that handles its own internal float memory operations. Be careful, it's a jungle out there.

_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
Back to top
View user's profile Send private message
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Sun Feb 20, 2011 8:30 am    Post subject: Reply with quote

Burningmace wrote:
Just as a note here:

IEEE floats do not have any defined endianness when abstracted, so they may be stored in either (i.e. 0x01234567 or 0x67452301) in memory depending on how the compiler works. In .NET the endianness may be totally different to the implementation of Java, or the endianness of C. Some compilers tie to the standard endianness of the model of processor that is being targeted (e.g. little-endian on Intel CPUs) whereas some stick to one endian type regardless of target architecture. Some may actually switch endianness depending on the OS you target (e.g. cross-platform framework). When you use Array.Reverse() on a byte array being passed to a BitConverter function, you are flipping the endianness. It may actually turn out that in certain strange circumstances you are in fact required not to reverse it. The way to check is with the BitConverter.IsLittleEndian value. I would imagine in this case the answer is false, but if not then it means you're attaching to a process that handles its own internal float memory operations. Be careful, it's a jungle out there.


Thanks for this info Smile
I will try to use the ".IsLittleEndian" to check if I have to reverse it, or not Smile
Thanks :>
Back to top
View user's profile Send private message
SlowPoke69
How do I cheat?
Reputation: 0

Joined: 18 Feb 2011
Posts: 7

PostPosted: Sat Feb 26, 2011 9:27 am    Post subject: Reply with quote

I was having the same issue..
thank you guys so much!
It Works! YaY!
Back to top
View user's profile Send private message
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Mon Mar 07, 2011 8:04 am    Post subject: Reply with quote

#Delete This Please

Last edited by Miaurice on Mon Mar 28, 2011 2:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Mon Mar 28, 2011 2:24 pm    Post subject: Reply with quote

I dont fucking get it.
Is someone able to reverse the routine again?
So if I have the "2500", how to get "451C4000" out of it

I'm sorry I'm too stupid for it..

Thanks for any help ://
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Mar 28, 2011 7:34 pm    Post subject: Reply with quote

what don't you get?

BitConverter.GetBytes()
Back to top
View user's profile Send private message
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Tue Mar 29, 2011 9:06 am    Post subject: Reply with quote

I tried this:
Code:
Dim MyArray() As Byte = BitConverter.GetBytes(2500)
        Array.Reverse(MyArray)
        Return MyArray


Doesn't give me "451C4000"
:/
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Tue Mar 29, 2011 9:41 am    Post subject: Reply with quote

Try using uint instead. In .NET a float does some unwanted math on floats with more than 7 numbers in total.
IE 0x451C4000 is 1159479296.

I ran into this issue a few weeks ago doing SHR conversions on hex numbers. Every 3rd run the number was getting rounded up or down. I changed the type to uint and it cured the issue.

http://www.homeandlearn.co.uk/csharp/csharp_s2p6.html

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Tue Mar 29, 2011 10:02 am    Post subject: Reply with quote

AhMunRa wrote:
Try using uint instead. In .NET a float does some unwanted math on floats with more than 7 numbers in total.
IE 0x451C4000 is 1159479296.

I ran into this issue a few weeks ago doing SHR conversions on hex numbers. Every 3rd run the number was getting rounded up or down. I changed the type to uint and it cured the issue.


Hmmh..
1159479296 is "4 Bytes" in CheatEngine
But I need to deal with the "2500" (which is Float (In vb.net Single))
:/
So I can't switch to UInt.. Sad
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Tue Mar 29, 2011 10:20 am    Post subject: Reply with quote

Use the Converter namespace if you are looking to convert from one type to another.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Tue Mar 29, 2011 10:37 am    Post subject: Reply with quote

Wiccaan wrote:
Use the Converter namespace if you are looking to convert from one type to another.

If I do that I get that "1,159479E+09" again..
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Tue Mar 29, 2011 10:42 am    Post subject: Reply with quote

Miaurice wrote:
Wiccaan wrote:
Use the Converter namespace if you are looking to convert from one type to another.

If I do that I get that "1,159479E+09" again..


Basing on how you are posting:
Code:

float fValue = 2500.0f;
UInt32 uValue = Convert.ToUInt32(fValue);


Doing this I get a perfectly fine result, uValue contains 2500 properly.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Tue Mar 29, 2011 10:50 am    Post subject: Reply with quote

Wiccaan wrote:
Miaurice wrote:
Wiccaan wrote:
Use the Converter namespace if you are looking to convert from one type to another.

If I do that I get that "1,159479E+09" again..


Basing on how you are posting:
Code:

float fValue = 2500.0f;
UInt32 uValue = Convert.ToUInt32(fValue);


Doing this I get a perfectly fine result, uValue contains 2500 properly.


Code:
Dim MyFloat As Single = 2500.0F
Dim MyInt As UInt32 = Convert.ToUInt32(MyFloat)


Gives Me MyInt = 2500
But I need 451C4000..

I already have 2500 from the beginning, I don't have 2500.0F. Its a clean 2500.
But what I now need is to get 451C4000 out of that 2500
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Tue Mar 29, 2011 11:27 am    Post subject: Reply with quote

Code:
float fValue = 2500.0f;
UInt32 uValue = Convert.ToUInt32(fValue);
byte[] btBytes = BitConverter.GetBytes(Convert.ToSingle(uValue));


Should do it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Tue Mar 29, 2011 12:22 pm    Post subject: Reply with quote

Code:
BitConverter.GetBytes(Convert.ToSingle(2500))


In my tries i forgot the "Convert.ToSingle()"

This did it!
Thanks again! I will post it in the Post at the first page (:
I would like to +rep you, but I seem to not be able to do this with my low Post-Count..
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 programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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