diff options
| author | 2016-04-08 11:59:32 -0500 | |
|---|---|---|
| committer | 2016-04-08 11:59:50 -0500 | |
| commit | 978ab32a11e663b2571c9f72ec43114e2eabf2c5 (patch) | |
| tree | 136963e604a5a280afea640ab92e3a1c701fffc3 /plugins/cheatfind/init.lua | |
| parent | 28d364bc8fe6cd616128b29fa5f80170bee79a80 (diff) | |
plugins/cheatfind: start lua cheat finder library [Carl]
Diffstat (limited to 'plugins/cheatfind/init.lua')
| -rw-r--r-- | plugins/cheatfind/init.lua | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua new file mode 100644 index 00000000000..a4334b67aba --- /dev/null +++ b/plugins/cheatfind/init.lua @@ -0,0 +1,98 @@ +-- license:BSD-3-Clause +-- copyright-holders:Carl +-- This is a library of functions to be used at the Lua console as cf.getspaces() etc... +local exports = {} +exports.name = "cheatfind" +exports.version = "0.0.1" +exports.description = "Cheat finder helper library" +exports.license = "The BSD 3-Clause License" +exports.author = { name = "Carl" } + +local cheatfind = exports + +function cheatfind.startplugin() + local cheat = {} + + -- return table of devices and spaces + function cheat.getspaces() + local spaces = {} + for tag, device in pairs(manager:machine().devices) do + if device.spaces then + spaces[tag] = {} + for name, space in pairs(device.spaces) do + spaces[tag][name] = space + end + end + end + return spaces + end + + -- return table of ram devices + function cheat.getram() + local ram = {} + for tag, device in pairs(manager:machine().devices) do + if device:shortname() == "ram" then + ram[tag] = device + end + end + end + + -- save data block + function cheat.save(space, start, size) + local data = { block = "", dev = space, start = start, size = size, space = space } + if space.shortname then + if space:shortname() == "ram" then + data.block = emu.item(device.items["0/m_pointer"]):read_block(start, size) + if not data.block then + return nil + end + end + else + local block = "" + for i = start, start + size do + block = block .. string.pack("B", space:read_u8(i)) + end + data.block = block + end + return data + end + + -- compare a data block to the current state + function cheat.comp(olddata, oper, val) + local newdata = cheat.save(olddata.dev, olddata.start, olddata.size, olddata.space) + local ret = {} + if not val then + val = 0 + end + if oper == "+" or oper == "inc" then + for i = 1, olddata.size do + local old = string.unpack("B", olddata.block, i) + local new = string.unpack("B", newdata.block, i) + if old < new then + if (val > 0 and (old + val) == new) or val == 0 then + ret[#ret + 1] = { addr = olddata.start + i, + oldval = old, + newval = new} + end + end + end + elseif oper == "-" or oper == "dec" then + for i = 1, olddata.size do + local old = string.unpack("B", olddata.block, i) + local new = string.unpack("B", newdata.block, i) + if old > new then + if (val > 0 and (old - val) == new) or val == 0 then + ret[#ret + 1] = { addr = olddata.start + i, + oldval = old, + newval = new} + end + end + end + end + return ret + end + + _G.cf = cheat +end + +return exports |
