|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
TheKrzysiek How do I cheat? Reputation: 0
Joined: 29 Oct 2024 Posts: 2
|
Posted: Tue Oct 29, 2024 5:23 am Post subject: Converting a float script to work with big endian |
|
|
I've been making simple scripts that change the FOV in racing games based on the speed.
Recently I've been trying to do it on Xenia and RPCS3 but I've had issues with the script actually working properly, and after eliminating all other possible issues, I assumed that it's due to the Float Big Endian that those emulators use.
I've tried some fixes and ChatGPT, but it didn't do anything good and my own knowledge of this is pretty limited.
Here's the script:
Code: | local MINSPEED_value = 50
local SPEED_CAP_Value = 250
local DEFAULTFOV_value = 333
local SPEEDMULTIPLIER_value = 1.0
local FOV_address = 0x201A10044
local SPEED_address = 0x205371378
function updateValues()
local SPEED_value = readFloat(SPEED_address)
if SPEED_value > MINSPEED_value and SPEED_value < SPEED_CAP_Value then
local FOV_value = (DEFAULTFOV_value + (MINSPEED_value * SPEEDMULTIPLIER_value) - SPEED_value * SPEEDMULTIPLIER_value)
writeFloat(FOV_address, FOV_value)
end
end |
Any help is much appreciated.
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 59
Joined: 01 Oct 2008 Posts: 957
|
Posted: Tue Oct 29, 2024 9:17 am Post subject: |
|
|
IIRC, CE use Lua 5.3 since ver 6.5 and Lua 5.3 has string.pack string.unpack functions to convert different value type to and from a string, including big-endian numeric type.
We can apply the conversion on values we read from or write to memory.
Here an example :
Code: |
function mem_struct(fms)
local ok, sz, read, write = pcall(string.packsize,fms)
if ok then
function read(addr)
local bs = readBytes(addr, sz, true)
if bs then
return string.unpack(fms, byteTableToString(bs))
end
end
function write(addr, ...)
local ok, bs = pcall(string.pack, fms, ...)
if ok then
local write_ok = writeBytes(addr, stringToByteTable(bs))
return write_ok
end
end
return { read = read, write = write }
end
end
|
Now we can replace readFloat/writeFloat with this function, yours as example (not tested),
Code: |
function updateValues(isBig) -- add a flag if use big-endian
local mx, readFloat, writeFloat = mem_struct(isBig and '>f' or 'f')
if not mx then return else readFloat, writeFloat = mx.read, mx.write end -- use the functions
-- your original code below
local SPEED_value = readFloat(SPEED_address)
if SPEED_value > MINSPEED_value and SPEED_value < SPEED_CAP_Value then
local FOV_value = (DEFAULTFOV_value + (MINSPEED_value * SPEEDMULTIPLIER_value) - SPEED_value * SPEEDMULTIPLIER_value)
writeFloat(FOV_address, FOV_value)
end
end
|
Check the string.pack/unpack format from Lua 5.3 Manual
https://www.lua.org/manual/5.3/manual.html#6.4.2
_________________
- Retarded. |
|
Back to top |
|
|
TheKrzysiek How do I cheat? Reputation: 0
Joined: 29 Oct 2024 Posts: 2
|
Posted: Tue Oct 29, 2024 1:02 pm Post subject: |
|
|
It works now, thanks a lot!
|
|
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
|
|