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 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Sat Feb 12, 2011 6:43 pm    Post subject: [.net] Floats? Reply with quote

Hey CE.org-Com.
I've got some annoying problems with reading Float-Variables from Memory with vb.net.

Some Information: Cheat Engine shows me 2500 for a Float Value. I want this 2500 in my vb.net Program.

I use some API to get a Value at an Address.
Code:
Public Function ReadFloat(ByVal Address As Long)
        Dim Handle As IntPtr = GetProcessHandleByName(ProzessName)
        Dim Result As Single = 0
        ReadProcessMemory(Handle, Address, Result, 4, 0&)

        CloseHandle(Handle)

        Return Result
End Function


This returns 1,159479E+09
If I
Code:
Return Conversion.Hex(Result)
I get 451C4000

Well.
If I click on my Address in Cheat Engine and click on "Display as Hex" it also says 451C4000.
But if I say "Display as Decimal" it gives me 2500 (The Value I want to display in vb.net..)

How does Cheat Engine convert 451C4000 to 2500?
How do I do that in vb.net / c#

Thanks in advance, sry 4 my bl00dy english..
Miaurice.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Feb 12, 2011 7:52 pm    Post subject: Reply with quote

Try reading as bytes and use the BitConverter class to recast the bytes back to a single / double.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sat Feb 12, 2011 8:00 pm    Post subject: Reply with quote

have you tried "Return Single" and read into the Single variable ? (no idea if it works, I have no experience with VB and I can't see how VB would get the return type of a function since it doesn't seem to be defined, and what is that "Result" variable ? )
_________________
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
Miaurice
Newbie cheater
Reputation: 0

Joined: 03 Jul 2009
Posts: 21
Location: Germany

PostPosted: Sun Feb 13, 2011 7:00 am    Post subject: Reply with quote

Wiccaan wrote:
Try reading as bytes and use the BitConverter class to recast the bytes back to a single / double.


If I read as Bytes I get 451C4000
If I convert this to Single I get 1,159479E+09

Dark Byte wrote:
have you tried "Return Single" and read into the Single variable ? (no idea if it works, I have no experience with VB and I can't see how VB would get the return type of a function since it doesn't seem to be defined, and what is that "Result" variable ? )


I tried to do it like this:
Code:
Public Function ReadFloat(ByVal Address As Long) As Single

Then I get 1,159479E+09

ReadProcessMemory(Handle, Address, Result, 4, 0&)
3rd Parameter is where to write the 4Bytes.
And "Result" is my Variable
Code:
Dim Result As Single

I Return this Variable at the end.


But if you type 2500 in Calc.EXE (in decimal) and then click on "Hex" it says 9C4.
If you type 451C4000 (Cheat Engine's HEX to 2500 in Decimal) it says 1159479296.
So why is it 1159479296 in Calc.exe and 2500 in CE ?
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sun Feb 13, 2011 8:43 am    Post subject: Reply with quote

Do you have the right... address?

http://stackoverflow.com/questions/272013/c-float-vs-vb-net-single-namin-complainin
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 13, 2011 8:49 am    Post subject: Reply with quote

Jorg hi wrote:
Do you have the right... address?

stackoverflow . com / questions / 272013 / c-float-vs-vb-net-single-namin-complainin


Of course Very Happy
The same Address in vb.net as in Cheat Engine Wink

Well this link doesn't help me in any way.. but thanks Smile
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Sun Feb 13, 2011 1:23 pm    Post subject: Reply with quote

If you set the result manually to 2500.0 and then do Return Conversion.Hex(Result)

what is the outcome of that ? (make sure the .0 is part of value)

_________________
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
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Feb 13, 2011 2:07 pm    Post subject: This post has 1 review(s) Reply with quote

Other then having the wrong address, are you sure its a single and not a double? If you are continuing to get the wrong number, it sounds more like it could be due to the wrong type being used.

If you go to the address in memory with CE do the bytes match what you are reading from the memory?

Also it could be due to notation. 2500.0f is 00401C45, so you may need to reverse the bytes before you convert them to a number. For example in C#:

Code:

            byte[] btNumber = new byte[] { 0x45, 0x1C, 0x40, 0x00 };
            Array.Reverse(btNumber);
            Single sngNumber = BitConverter.ToSingle(btNumber, 0);

_________________
- 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: Mon Feb 14, 2011 3:41 pm    Post subject: Reply with quote

Quote:
If you set the result manually to 2500.0 and then do Return Conversion.Hex(Result)

what is the outcome of that ? (make sure the .0 is part of value)


You mean I should try to set the Value to 2500.0 from my vb.net App (not Cheat Engine)?
I'll try that Smile

Quote:
Other then having the wrong address, are you sure its a single and not a double? If you are continuing to get the wrong number, it sounds more like it could be due to the wrong type being used.


Well the HEX-Value is correct..

Quote:
If you go to the address in memory with CE do the bytes match what you are reading from the memory?

Yes.

Quote:
Also it could be due to notation. 2500.0f is 00401C45, so you may need to reverse the bytes before you convert them to a number. For example in C#:

Code:

byte[] btNumber = new byte[] { 0x45, 0x1C, 0x40, 0x00 };
Array.Reverse(btNumber);
Single sngNumber = BitConverter.ToSingle(btNumber, 0);


Okay I'll try Smile
But if you put in 54C104000 in Microsofts Calc.exe and then press on Dec it says 1159479296
401C45 is 4201541
9C4 is 2500...

So why does Cheat Engine convert 2500 to 54C104000 instead of 9C4 ?
This is weird...



FloatVB.jpg
 Description:
 Filesize:  59.82 KB
 Viewed:  18781 Time(s)

FloatVB.jpg




Last edited by Miaurice on Mon Feb 14, 2011 4:49 pm; edited 2 times in total
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Mon Feb 14, 2011 4:22 pm    Post subject: Reply with quote

Hammered this out in C# should work for you as well.

Code:

string val = "451C4000";
Int32 iVal = Convert.ToInt32(val, 16);  / Converts hex number to dec equiv

_________________
<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: Mon Feb 14, 2011 4:47 pm    Post subject: Reply with quote

AhMunRa wrote:
Hammered this out in C# should work for you as well.

Code:

string val = "451C4000";
Int32 iVal = Convert.ToInt32(val, 16);  / Converts hex number to dec equiv


In VB.NET:
Code:
Dim val As String = "451C4000"
Dim iVal As Int32 = Convert.ToInt32(val, 16)


Result: 1159479296

... :<<<<<<<<<<<<<<<<<<<<<<<

DAMN IT!
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Mon Feb 14, 2011 7:25 pm    Post subject: Reply with quote

I think Wiccan is right, read in the bytes then redo the conversion. There is something wonky going on in the code. Anyway you slice it you can not get 9C4 == 2500 from 451C4000. Not without doing Math-FU to it.
_________________
<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 Feb 15, 2011 7:40 am    Post subject: Reply with quote

Wiccan's Method works Smile

Thanks at all!
Thank you all very very much Smile

For all who have the same Problem and find this Thread:

VB.NET Source-Code:
Code:
Dim MyArray() As Byte = New Byte() {&H45, &H1C, &H40, &H0}
Array.Reverse(MyArray)
Dim MyNumber As Single = BitConverter.ToSingle(MyArray, 0)
MsgBox(MyNumber)

Result: 2500 Smile

To reverse it again:
Code:
Dim MyArray() As Byte = BitConverter.GetBytes(Convert.ToSingle(2500))

Result: An Array containing: {&H45, &H1C, &H40, &H0}
Smile

To fill the Array with the String:
VB.NET Source-Code:
Code:
Dim MyFloatHex As String = "451C4000"
Dim n As Integer = MyFloatHex.Length \ 2
Dim buffer(n - 1) As Byte
For i As Integer = 0 To MyFloatHex.Length - 1 Step 2
    buffer(i \ 2) = Convert.ToByte(MyFloatHex.Substring(i, 2), 16)
Next

This Source-Code was coded by ~blaze~
Threadlink: www . vb-paradise . de / programmieren / hauptforum / p410380-string-verarbeitung-zu-byte / #post410380


Last edited by Miaurice on Tue Mar 29, 2011 12:24 pm; edited 1 time in total
Back to top
View user's profile Send private message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Tue Feb 15, 2011 2:58 pm    Post subject: Reply with quote

Lol obviously his solution was right, I already + repped him a long time ago.
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 Feb 15, 2011 5:48 pm    Post subject: Reply with quote

Jorg hi wrote:
Lol obviously his solution was right, I already + repped him a long time ago.

Glückwunsch
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 1, 2  Next
Page 1 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