diff options
-rw-r--r-- | plugins/cheat/init.lua | 13 | ||||
-rw-r--r-- | plugins/cheatfind/init.lua | 54 |
2 files changed, 39 insertions, 28 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua index dedbea9b2f9..05242e96d0d 100644 --- a/plugins/cheat/init.lua +++ b/plugins/cheat/init.lua @@ -531,19 +531,16 @@ function cheat.startplugin() manager:machine():popmessage(newcheat.desc .. " added") end - function ce.dump(index) - cheat = cheats[index] - if cheat then - for k, v in pairs(cheat.cheat_env) do - emu.print_verbose(k, v) - end - end + function ce.get(index) + return cheats[index] end function ce.list() + local list = {} for num, cheat in pairs(cheats) do - emu.print_verbose(num, cheat.desc) + list[num] = cheat.desc end + return list end _G.ce = ce diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua index dd9e358dbe5..467b0f6f916 100644 --- a/plugins/cheatfind/init.lua +++ b/plugins/cheatfind/init.lua @@ -71,7 +71,7 @@ function cheatfind.startplugin() end -- compare two data blocks, format is as lua string.unpack, bne and beq val is table of masks - function cheat.comp(olddata, newdata, oper, format, val, bcd) + function cheat.comp(newdata, olddata, oper, format, val, bcd) local ret = {} local ref = {} -- this is a helper for comparing two match lists local bitmask = nil @@ -106,6 +106,10 @@ function cheatfind.startplugin() eq = function(a, b, val) return a == b end, ne = function(a, b, val) return (a ~= b and val == 0) or (val > 0 and ((a - val) == b or (a + val) == b)) end, + ltv = function(a, b, val) return a < val end, + gtv = function(a, b, val) return a > val end, + eqv = function(a, b, val) return a == val end, + nev = function(a, b, val) return a ~= val end, bne = bne, beq = beq } local function check_bcd(val) @@ -125,12 +129,16 @@ function cheatfind.startplugin() return result end + if not newdata and oper:sub(3, 3) == "v" then + newdata = olddata + end if olddata.start ~= newdata.start or olddata.size ~= newdata.size or not cfoper[oper] then return {} end if not val then val = 0 end + for i = 1, olddata.size do local old = string.unpack(format, olddata.block, i) local new = string.unpack(format, newdata.block, i) @@ -168,8 +176,8 @@ function cheatfind.startplugin() end -- compare two blocks and filter by table of previous matches - function cheat.compnext(olddata, newdata, oldmatch, oper, format, val, bcd) - local matches, refs = cheat.comp(olddata, newdata, oper, format, check_val(oper, val, oldmatch), bcd) + function cheat.compnext(newdata, olddata, oldmatch, oper, format, val, bcd) + local matches, refs = cheat.comp(newdata, olddata, oper, format, check_val(oper, val, oldmatch), bcd) local nonmatch = {} local oldrefs = {} for num, match in pairs(oldmatch) do @@ -196,13 +204,13 @@ function cheatfind.startplugin() -- compare a data block to the current state function cheat.compcur(olddata, oper, format, val, bcd) local newdata = cheat.save(olddata.space, olddata.start, olddata.size, olddata.space) - return cheat.comp(olddata, newdata, oper, format, val, bcd) + return cheat.comp(newdata, olddata, oper, format, val, bcd) end -- compare a data block to the current state and filter function cheat.compcurnext(olddata, oldmatch, oper, format, val, bcd) local newdata = cheat.save(olddata.space, olddata.start, olddata.size, olddata.space) - return cheat.compnext(olddata, newdata, oldmatch, oper, format, val, bcd) + return cheat.compnext(newdata, olddata, oldmatch, oper, format, val, bcd) end @@ -216,11 +224,11 @@ function cheatfind.startplugin() "little u32", "big u32", "little s32", "big s32", "little u64", "big u64", "little s64", "big s64" } local width = 1 local bcd = 0 - local optable = { "lt", "gt", "eq", "ne", "beq", "bne" } + local optable = { "lt", "gt", "eq", "ne", "beq", "bne", "ltv", "gtv", "eqv", "nev" } local opsel = 1 local value = 0 - local leftop = 1 - local rightop = 0 + local leftop = 2 + local rightop = 1 local matches = {} local matchsel = 1 local menu_blocks = {} @@ -236,7 +244,7 @@ function cheatfind.startplugin() bcd = 0 opsel = 1 value = 0 - leftop = 1 + leftop = 2 rightop = 1 matches = {} matchsel = 1 @@ -294,18 +302,15 @@ function cheatfind.startplugin() menu[midx.lop] = { "Left operand", leftop, "" } menu_lim(leftop, 1, #menu_blocks[1] + 1, menu[midx.lop]) if leftop == #menu_blocks[1] + 1 then - menu[midx.lop][2] = "All" + menu[midx.lop][2] = "Current" end menu[midx.op] = { "Operator", optable[opsel], "" } menu_lim(opsel, 1, #optable, menu[midx.op]) menu[midx.rop] = { "Right operand", rightop, "" } - menu_lim(rightop, 1, #menu_blocks[1] + 1, menu[midx.rop]) - if rightop == #menu_blocks[1] + 1 then - menu[midx.rop][2] = "Current" - end + menu_lim(rightop, 1, #menu_blocks[1], menu[midx.rop]) menu[midx.val] = { "Value", value, "" } menu_lim(value, 0, 100, menu[midx.val]) -- max value? - if value == 0 then + if value == 0 and optable[opsel]:sub(3, 3) ~= "v" then menu[midx.val][2] = "Any" end menu[midx.val + 1] = { "---", "", "off" } @@ -395,8 +400,8 @@ function cheatfind.startplugin() end manager:machine():popmessage("Data cleared and current state saved") watches = {} - leftop = 1 - rightop = 2 + leftop = 2 + rightop = 1 ret = true end devcur = devsel @@ -428,14 +433,23 @@ function cheatfind.startplugin() manager:machine():popmessage("Left equal to right with bitmask, value is ignored") elseif optable[opsel] == "bne" then manager:machine():popmessage("Left not equal to right with bitmask, value is ignored") + elseif optable[opsel] == "ltv" then + manager:machine():popmessage("Left less than value, right is ignored") + elseif optable[opsel] == "gtv" then + manager:machine():popmessage("Left greater than value, right is ignored") + elseif optable[opsel] == "eqv" then + manager:machine():popmessage("Left equal to value, right is ignored") + elseif optable[opsel] == "nev" then + manager:machine():popmessage("Left not equal to value, right is ignored") end end + ret = true elseif index == midx.val then value = incdec(value, 0, 100) elseif index == midx.lop then - leftop = incdec(leftop, 1, #menu_blocks[1]) + leftop = incdec(leftop, 1, #menu_blocks[1] + 1) elseif index == midx.rop then - rightop = incdec(rightop, 1, #menu_blocks[1] + 1) + rightop = incdec(rightop, 1, #menu_blocks[1]) elseif index == midx.width then width = incdec(width, 1, #formtable) elseif index == midx.bcd then @@ -515,7 +529,7 @@ function cheatfind.startplugin() _G.ce.inject(cheat) end elseif match.mode == 2 then - local filename = string.format("%s/%s_%08X_cheat", manager:machine():options().entries.cheatpath:value(), emu.romname(), match.addr) + local filename = string.format("%s/%s_%08X_cheat", manager:machine():options().entries.cheatpath:value():match("([^;]+)"), emu.romname(), match.addr) local json = require("json") local file = io.open(filename .. ".json", "w") file:write(json.stringify({[1] = cheat}, {indent = true})) |