Posted: Mon Oct 22, 2018 3:27 am Post subject: Writing Bytes from string
If anyone has any suggestions for improving this snippet then feel free to suggest them, planning to take a look at some old patch codes for FF12 (PAL) that I found a thread reporting problems (while I was looking for something else) and I don't fancy the effort involved in transforming my list codes into
cheat table format, didn't find a more useful variant in cheat engine so made my own:
Code:
--[[ For modern pcsx2 editions that fix
the base address at compile time,
change to function call that hooks
and loads the base address if not using
the above emulator (will provide template
at a later date)
]]--
BaseAddress = tonumber('2000000',16)
function Reverse(array,from,to)
local i = 1, c = #array, j = c
if type(from) == 'number' and
from < c then
i = from
end
if type(to) == 'number' and
to < c then
j = to
end
local tmp
while i < j do
tmp = array[j]
array[j] = array[i]
array[i] = tmp
j = j - 1
i = i + 1
end
return array
end
function WrBytes(addr,bytes,value)
-- Provides fallback scenario
if BaseAddress == 0xDEADC0DE or
addr == 0xDEADC0DE then
return nil
end
addr = addr + BaseAddress
if type(bytes) == 'number' then
if not value then
if bytes > 0xFFFF then
value = ('%08X'):format(bytes)
elseif bytes > 0xFF then
value = ('%04X'):format(bytes)
else
value = ('%02X'):format(bytes)
end
else
value = ('%0' ..
(('%dX'):format(bytes))):format(value)
end
bytes = value:gmatch("%S{2}")
bytes = Reverse(bytes)
bytes = table.join(bytes," ")
end
local asm = ([[
registersymbol(WrBytesTmp,%x)
WrBytesTmp:
db %s
unregistersymbol(WrBytesTmp)
]]):format(addr,bytes)
local success = autoAssemble(asm)
if not success then
return nil
end
return addr
end
Btw feel free to use it yourselves (but at least give credit if you're adding to a cheat table you're gonna distribute)
Edit: Thought of something myself, changed to reflect
Edit 2: Decided to extend it to support numbers, new function added on top
Edit 3: Noticed an issue and fixed it
Edit 4: Oversight with overwriting bytes parameter _________________
Those who do not trust in christ to save them from their sins will only experience hell when their soul is released from it's earthly vessel.
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