View previous topic :: View next topic |
Author |
Message |
Miaurice Newbie cheater
Reputation: 0
Joined: 03 Jul 2009 Posts: 21 Location: Germany
|
Posted: Sat Feb 12, 2011 6:43 pm Post subject: [.net] Floats? |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Feb 12, 2011 7:52 pm Post subject: |
|
|
Try reading as bytes and use the BitConverter class to recast the bytes back to a single / double. _________________
- Retired. |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Sat Feb 12, 2011 8:00 pm Post subject: |
|
|
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 |
|
 |
Miaurice Newbie cheater
Reputation: 0
Joined: 03 Jul 2009 Posts: 21 Location: Germany
|
Posted: Sun Feb 13, 2011 7:00 am Post subject: |
|
|
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 |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
|
Back to top |
|
 |
Miaurice Newbie cheater
Reputation: 0
Joined: 03 Jul 2009 Posts: 21 Location: Germany
|
Posted: Sun Feb 13, 2011 8:49 am Post subject: |
|
|
Jorg hi wrote: | Do you have the right... address?
stackoverflow . com / questions / 272013 / c-float-vs-vb-net-single-namin-complainin |
Of course
The same Address in vb.net as in Cheat Engine
Well this link doesn't help me in any way.. but thanks  |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Sun Feb 13, 2011 1:23 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
Back to top |
|
 |
Miaurice Newbie cheater
Reputation: 0
Joined: 03 Jul 2009 Posts: 21 Location: Germany
|
Posted: Mon Feb 14, 2011 3:41 pm Post subject: |
|
|
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
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
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...
Last edited by Miaurice on Mon Feb 14, 2011 4:49 pm; edited 2 times in total |
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Mon Feb 14, 2011 4:22 pm Post subject: |
|
|
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 |
|
 |
Miaurice Newbie cheater
Reputation: 0
Joined: 03 Jul 2009 Posts: 21 Location: Germany
|
Posted: Mon Feb 14, 2011 4:47 pm Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Mon Feb 14, 2011 7:25 pm Post subject: |
|
|
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 |
|
 |
Miaurice Newbie cheater
Reputation: 0
Joined: 03 Jul 2009 Posts: 21 Location: Germany
|
Posted: Tue Feb 15, 2011 7:40 am Post subject: |
|
|
Wiccan's Method works
Thanks at all!
Thank you all very very much
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
To reverse it again:
Code: | Dim MyArray() As Byte = BitConverter.GetBytes(Convert.ToSingle(2500)) |
Result: An Array containing: {&H45, &H1C, &H40, &H0}
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 |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Tue Feb 15, 2011 2:58 pm Post subject: |
|
|
Lol obviously his solution was right, I already + repped him a long time ago. |
|
Back to top |
|
 |
Miaurice Newbie cheater
Reputation: 0
Joined: 03 Jul 2009 Posts: 21 Location: Germany
|
Posted: Tue Feb 15, 2011 5:48 pm Post subject: |
|
|
Jorg hi wrote: | Lol obviously his solution was right, I already + repped him a long time ago. |
Glückwunsch |
|
Back to top |
|
 |
|