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 


Retrieving a 4 Byte Hex value from the cheat table

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 121

PostPosted: Thu Jan 28, 2021 10:52 am    Post subject: Retrieving a 4 Byte Hex value from the cheat table Reply with quote

Hi! im trying to retrieve the 4byte hex value from the cheat table to compare in Lua, the problem is, at least the way im trying to do it, the hash is "mirrored" so instead of getting, for example, the hash
2BEC3CBE i get BE3CEC2B

The code im using is:

Code:
local addrhash = getAddress"[VehTweaksPtr]-4" --Hash
print(string.format('%02X%02X%02X%02X', readBytes(addrhash, 4)))
if readBytes(addrhash, 4) == 'EEF345EC' then


Any solutions you can point me to?
Thanks in advance!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Thu Jan 28, 2021 11:14 am    Post subject: This post has 1 review(s) Reply with quote

That's not a hash; that's just an address.

Multibyte values are stored in little endian: least significant byte first. e.g. the 4-byte value 305420988 (0x12345ABC) is stored as the array of bytes BC 5A 34 12.

If you want to print an integer in base-16 (hexadecimal), use the hexadecimal format specifier:
Code:
print(("%08X"):format(305420988))


To read a 4-byte integer value at an address, use readInteger:
Code:
if readInteger"[VehTweaksPtr]-4" == 0xEEF345EC then
  -- ...
end

Edit: BBCode typo

_________________
I don't know where I'm going, but I'll figure it out when I get there.


Last edited by ParkourPenguin on Thu Jan 28, 2021 4:41 pm; edited 1 time in total
Back to top
View user's profile Send private message
careca777
Expert Cheater
Reputation: 0

Joined: 27 Jul 2013
Posts: 121

PostPosted: Thu Jan 28, 2021 12:19 pm    Post subject: Reply with quote

Many thanks!
I searched wiki for format, could not find it anywhere.
I would never get there by myself.
Thank you.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Thu Jan 28, 2021 4:45 pm    Post subject: Reply with quote

string.format is part of Lua itself. See the official reference manual for more information:
https://www.lua.org/manual/5.3/manual.html#pdf-string.format
It's more or less C printf:
https://en.cppreference.com/w/c/io/fprintf

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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