 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Y.A.K.E Advanced Cheater
Reputation: 0
Joined: 15 Jul 2019 Posts: 56
|
Posted: Sat Aug 20, 2022 8:43 am Post subject: Unsigned to signed |
|
|
| Code: |
local val = readInteger(addr)
print(val) --4294967295
local var_str = string.format("%d",val)
print(var_str) --4294967295 (why not -1)
CETrainer.edit1.Txet = var_str --4294967295
|
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4722
|
Posted: Sat Aug 20, 2022 10:43 am Post subject: |
|
|
I might be wrong on this, someone correct me if so. Some of this might be CE modifications to Lua.
There's only one number type in Lua: "number". Internally, this can have two different representations: 64-bit signed integers or doubles. Functions like readInteger return the 64-bit signed integer representation- key point being it's 64 bits regardless of what you read. Smaller integer types, such as the 32-bit integers read by readInteger, have a unique representation regardless of whether it's signed or not. e.g. the 32-bit signed value -1 (encoded as "FF FF FF FF") encoded as a 64-bit signed value would be "FF FF FF FF FF FF FF FF", while the 32-bit unsigned value 4294967295 (also encoded as "FF FF FF FF") encoded as a 64-bit signed value would be "00 00 00 00 FF FF FF FF".
When converting smaller integer types into Lua's 64-bit signed integer type, it's important to clarify whether the smaller integer type is signed or not. By default, the smaller integer types are unsigned, but signed integer types are also supported. In celua.txt:
| Quote: | readSmallInteger, readInteger, readSmallIntegerLocal, readIntegerLocal
can also have second boolean parameter. If true, value will be signed. | readQword (read 64-bit integer) is always going to be signed since there is no unsigned representation Lua can provide.
| Code: | writeBytes('foo', { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF })
print(readQword'foo') -- prints -1
print(readInteger'foo') -- prints 4294967295
print(readInteger('foo', true)) -- prints -1 |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Y.A.K.E Advanced Cheater
Reputation: 0
Joined: 15 Jul 2019 Posts: 56
|
Posted: Tue Aug 23, 2022 6:57 am Post subject: |
|
|
thanks,
readInteger(addr, true) is working
|
|
| Back to top |
|
 |
|
|
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
|
|