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 


[delphi] 4-byte floats

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
seesix
How do I cheat?
Reputation: 0

Joined: 20 Aug 2009
Posts: 2

PostPosted: Thu Aug 20, 2009 11:42 am    Post subject: [delphi] 4-byte floats Reply with quote

with c++, a float is 4 bytes.
as a dword, the float value of 383.2284 would look like 0x43bf9d3b.

i'm using the 'single' type in delphi to store a 4-byte float value from a file structure - however, the value isn't calculated correctly:

Code:
var x : single;
begin
x := $43bf9d3b;
ShowMessage(Format('%f', [x]));
end;


the message shows "1136631040.00" - which looks similar to a lousy int conversion...


help!
Back to top
View user's profile Send private message
DanielG
Expert Cheater
Reputation: 1

Joined: 13 May 2009
Posts: 130
Location: The Netherlands

PostPosted: Thu Aug 20, 2009 1:10 pm    Post subject: Reply with quote

I've never used delphi, but could you try this?

Code:
var x : single;
var y : single;
begin
x := $43bf9d3b;
y := 383.2284;

ShowMessage(Format('x fixed: %f', [x]));
ShowMessage(Format('x hex: %x', [x]));
ShowMessage(Format('y fixed: %f', [y]));
ShowMessage(Format('y hex: %x', [y]));

end;


I'm interested if the 'x hex' and 'y hex' are the same, the problem could be there.
Back to top
View user's profile Send private message
seesix
How do I cheat?
Reputation: 0

Joined: 20 Aug 2009
Posts: 2

PostPosted: Thu Aug 20, 2009 1:41 pm    Post subject: Reply with quote

thank you for replying.

unfortunately, you can't format as another type / on-the-fly like that

edit

(with a clearer head:)

it seemed i was just casting x as a large number (only in hex).
i ended up hacking together the following function:

Code:

procedure SingleAsDWORD(var outSingle : Single; inDWORD : DWORD);
begin
  CopyMemory(@outSingle, @inDWORD, 4);
end;


instead of just setting the single type's value _equal_ to the dword, it copies it to where it would be accessed - which returns the correct float value!

Arrow solved
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Sat Aug 22, 2009 9:23 am    Post subject: Reply with quote

0x43BF9D3B = 1136631099.
It converted int to float automatically, why didn't you simply do:
x := 383.2284?

Or, you could also use pointers. cast 0x43BF9D3B to a pointer to float and then dereference it.
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
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