summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/cheatfind
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/cheatfind')
-rw-r--r--plugins/cheatfind/init.lua383
1 files changed, 181 insertions, 202 deletions
diff --git a/plugins/cheatfind/init.lua b/plugins/cheatfind/init.lua
index 276193acc13..f36b4f5b2d5 100644
--- a/plugins/cheatfind/init.lua
+++ b/plugins/cheatfind/init.lua
@@ -5,18 +5,20 @@ local exports = {}
exports.name = "cheatfind"
exports.version = "0.0.1"
exports.description = "Cheat finder helper library"
-exports.license = "The BSD 3-Clause License"
+exports.license = "BSD-3-Clause"
exports.author = { name = "Carl" }
local cheatfind = exports
+local reset_subscription
+
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
+ for tag, device in pairs(manager.machine.devices) do
if device.spaces then
spaces[tag] = {}
for name, space in pairs(device.spaces) do
@@ -30,8 +32,8 @@ function cheatfind.startplugin()
-- return table of ram devices
function cheat.getram()
local ram = {}
- for tag, device in pairs(manager:machine().devices) do
- if device:shortname() == "ram" then
+ for tag, device in pairs(manager.machine.devices) do
+ if device.shortname == "ram" then
ram[tag] = {}
ram[tag].dev = device
ram[tag].size = emu.item(device.items["0/m_size"]):read(0)
@@ -43,7 +45,7 @@ function cheatfind.startplugin()
-- return table of share regions
function cheat.getshares()
local shares = {}
- for tag, share in pairs(manager:machine():memory().shares) do
+ for tag, share in pairs(manager.machine.memory.shares) do
shares[tag] = share
end
return shares
@@ -56,7 +58,7 @@ function cheatfind.startplugin()
data.shift = space.shift
end
if getmetatable(space).__name:match("device_t") then
- if space:shortname() == "ram" then
+ if space.shortname == "ram" then
data.block = emu.item(space.items["0/m_pointer"]):read_block(start, size)
if not data.block then
return nil
@@ -144,7 +146,6 @@ function cheatfind.startplugin()
end
end
-
local function check_bcd(val)
local a = val + 0x0666666666666666
a = a ~ val
@@ -240,7 +241,6 @@ function cheatfind.startplugin()
return resort
end
-
-- compare a data block to the current state
function cheat.compcur(olddata, oper, format, val, bcd, step)
local newdata = cheat.save(olddata.space, olddata.start, olddata.size, olddata.space)
@@ -253,23 +253,14 @@ function cheatfind.startplugin()
return cheat.compnext(newdata, olddata, oldmatch, oper, format, val, bcd, step)
end
-
- _G.cf = cheat
-
+ _G.emu.plugin.cheatfind = cheat
local devtable = {}
local devsel = 1
local devcur = 1
-
-
- --local formtable = { " I1", " i1", "<I2", ">I2", "<i2", ">i2", "<I4", ">I4", "<i4", ">i4", "<I8", ">I8", "<i8", ">i8", }-- " <f", " >f", " <d", " >d" }
- --local formname = { "u8", "s8", "little u16", "big u16", "little s16", "big s16",
- -- "little u32", "big u32", "little s32", "big s32", "little u64", "big u64", "little s64", "big s64", }
- -- -- "little float", "big float", "little double", "big double" }
- -- Reordered into likelyhood of use order: unsigned byte by big endian unsigned by little endian unsigned then unsigned in same order
- local formtable = { " I1", ">I2", ">I4", ">I8", "<I2", "<I4", "<I8", " i1", ">i2", ">i4", ">i8", "<i2", "<i4", "<i8", }-- " <f", " >f", " <d", " >d" }
local formname = { "u8", "big u16", "big u32", "big u64", "little u16", "little u32",
- "little u64", "s8", "big s16", "big s32", "big s64", "little s16", "little s32", "little s64", }
-
+ "little u64", "s8", "big s16", "big s32", "big s64", "little s16", "little s32", "little s64", }
+ local formtable = { " I1", ">I2", ">I4", ">I8", "<I2", "<I4", "<I8", " i1", ">i2", ">i4", ">i8", "<i2", "<i4", "<i8", }
+ -- " <f", " >f", " <d", " >d" }
local width = 1
local bcd = 0
local align = 0
@@ -278,27 +269,20 @@ function cheatfind.startplugin()
local value = 0
local leftop = 1
local rightop = 1
- local leftop_text = "Slot 1"
- local rightop_text = "Slot 1"
local value_text = ""
- local expression_text = "Slot 1 < Slot 1"
- local pausetable = { "Automatic", "Manual" }
local pausesel = 1
- local pokevaltable = { "Slot 1 Value", "Last Slot Value", "0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x09", "0x63 (Decimal 99)", "0x99 (BCD 99)",
- "0xFF (Decimal 255)" , "0x3E7 (Decimal 999)", "0x999 (BCD 999)", "0x270F (Decimal 9999)", "0x9999 (BCD 9999)", "0xFFFF (Decimal 65535)" }
local pokevalsel = 1
-
local matches = {}
local matchsel = 0
local matchpg = 0
local menu_blocks = {}
local watches = {}
local menu_func
-
local cheat_save
local name = 1
local name_player = 1
local name_type = 1
+ local name_other = ""
local function start()
devtable = {}
@@ -320,9 +304,11 @@ function cheatfind.startplugin()
for tag, list in pairs(space_table) do
for name, space in pairs(list) do
local ram = {}
- for num, entry in pairs(space.map) do
- if entry.writetype == "ram" then
- ram[#ram + 1] = { offset = entry.offset, size = entry.endoff - entry.offset }
+ for num, entry in pairs(space.map.entries) do
+ if entry.write.handlertype == "ram" then
+ ram[#ram + 1] = {
+ offset = entry.address_start & space.address_mask,
+ size = (entry.address_end & space.address_mask) - (entry.address_start & space.address_mask) }
if space.shift > 0 then
ram[#ram].size = ram[#ram].size >> space.shift
elseif space.shift < 0 then
@@ -349,7 +335,7 @@ function cheatfind.startplugin()
end
end
- emu.register_start(start)
+ reset_subscription = emu.add_machine_reset_notifier(start)
local menu_is_showing = false
local tabbed_out = false
@@ -367,7 +353,7 @@ function cheatfind.startplugin()
for num, func in ipairs(menu) do
local item, f = func()
if item then
- menu_list[#menu_list + 1] = item
+ table.insert(menu_list, item)
menu_func[#menu_list] = f
end
end
@@ -376,7 +362,7 @@ function cheatfind.startplugin()
local function menu_lim(val, min, max, menuitem)
if min == max then
- menuitem[3] = 0
+ menuitem[3] = "on"
elseif val == min then
menuitem[3] = "r"
elseif val == max then
@@ -387,7 +373,7 @@ function cheatfind.startplugin()
end
local function incdec(event, val, min, max)
- local ret
+ local ret = false
if event == "left" and val ~= min then
val = val - 1
ret = true
@@ -400,18 +386,18 @@ function cheatfind.startplugin()
if cheat_save then
local cplayer = { "All", "P1", "P2", "P3", "P4" }
- local ctype = { "Infinite Credits", "Infinite Time", "Infinite Lives", "Infinite Energy", "Infinite Ammo", "Infinite Bombs", "Invincibility" }
+ local ctype = { "Infinite Credits", "Infinite Time", "Infinite Lives", "Infinite Energy", "Infinite Ammo", "Infinite Bombs", "Invincibility", _("Other: ") }
menu[#menu + 1] = function() return { _("Save Cheat"), "", "off" }, nil end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function()
local c = { _("Default"), _("Custom") }
- local m = { _("Cheat Name"), c[name], 0 }
+ local m = { _("Cheat Name"), c[name], "on" }
menu_lim(name, 1, #c, m)
local function f(event)
local r
name, r = incdec(event, name, 1, #c)
if (event == "select" or event == "comment") and name == 1 then
- manager:machine():popmessage(string.format(_("Default name is %s"), cheat_save.name))
+ manager.machine:popmessage(string.format(_("Default name is %s"), cheat_save.name))
end
return r
end
@@ -419,27 +405,49 @@ function cheatfind.startplugin()
end
if name == 2 then
menu[#menu + 1] = function()
- local m = { _("Player"), cplayer[name_player], 0 }
+ local m = { _("Player"), cplayer[name_player], "on" }
menu_lim(name_player, 1, #cplayer, m)
return m, function(event) local r name_player, r = incdec(event, name_player, 1, #cplayer) return r end
end
menu[#menu + 1] = function()
- local m = { _("Type"), ctype[name_type], 0 }
+ local m = { _("Type"), ctype[name_type] .. (name_type == #ctype and (#name_other ~= 0 and name_other or _("(empty)")) or ""), "on" }
menu_lim(name_type, 1, #ctype, m)
- return m, function(event) local r name_type, r = incdec(event, name_type, 1, #ctype) return r end
+ local function f(event)
+ local r
+ name_type, r = incdec(event, name_type, 1, #ctype)
+ if name_type == #ctype then
+ local char = tonumber(event)
+ if char then
+ if #name_other > 0 and (char == 8 or char == 0x7f) then
+ name_other = name_other:sub(1, utf8.offset(name_other, -1) - 1)
+ r = true
+ elseif char > 0x1f and (char & ~0x7f) ~= 0x80 and (char & ~0xf) ~= 0xfdd0 and (char & ~0xfffe) ~= 0xfffe then
+ name_other = name_other .. utf8.char(char)
+ r = true
+ end
+ elseif event == "select" or event == "comment" or event == "right" then
+ manager.machine:popmessage(_("You can enter any type name"))
+ end
+ end
+ return r
+ end
+ return m, f
end
end
menu[#menu + 1] = function()
- local m = { _("Save"), "", 0 }
+ local m = { _("Save"), "", "on" }
local function f(event)
if event == "select" then
local desc
local written = false
if name == 2 then
- if cplayer[name_player] == "All" then
- desc = ctype[name_type]
- else
- desc = cplayer[name_player] .. " " .. ctype[name_type]
+ desc = name_type ~= #ctype and ctype[name_type] or name_other
+ if #desc == 0 then
+ manager.machine:popmessage(_("Type name is empty"))
+ return
+ end
+ if cplayer[name_player] ~= "All" then
+ desc = cplayer[name_player] .. " " .. desc
end
else
desc = cheat_save.name
@@ -459,7 +467,7 @@ function cheatfind.startplugin()
-- old cheat .dat format, write support only (for cheat forum posting of new cheats if posted in simple format)
file:write(string.format(cheat_save.dat, desc))
file:close()
- manager:machine():popmessage(string.format(_("Cheat written to %s and added to cheat.simple"), filename))
+ manager.machine:popmessage(string.format(_("Cheat written to %s and added to cheat.simple"), filename))
end
written = true
elseif not getmetatable(devtable[devcur].space).__name:match("device_t") and devtable[devcur].sname == "program" then
@@ -469,12 +477,12 @@ function cheatfind.startplugin()
-- old cheat .dat format, write support only (for cheat forum posting of new cheats if posted in simple format)
file:write(string.format(cheat_save.dat, desc))
file:close()
- manager:machine():popmessage(_("Cheat added to cheat.simple"))
+ manager.machine:popmessage(_("Cheat added to cheat.simple"))
written = true
end
end
if not written then
- manager:machine():popmessage(_("Unable to write file\nEnsure that cheatpath folder exists"))
+ manager.machine:popmessage(_("Unable to write file\nEnsure that cheatpath folder exists"))
end
cheat_save = nil
return true
@@ -483,45 +491,46 @@ function cheatfind.startplugin()
end
return m, f
end
- menu[#menu + 1] = function() return { _("Cancel"), "", 0 }, function(event) if event == "select" then cheat_save = nil return true end end end
+ menu[#menu + 1] = function() return { _("Cancel"), "", "on" }, function(event) if event == "select" then cheat_save = nil return true end end end
return menu_prepare()
end
menu[#menu + 1] = function()
- local m = { _("CPU or RAM"), devtable[devsel].name, 0 }
+ local m = { _("CPU or RAM"), devtable[devsel].name, "on" }
menu_lim(devsel, 1, #devtable, m)
local function f(event)
if (event == "left" or event == "right") and #menu_blocks ~= 0 then
- manager:machine():popmessage(_("Changes to this only take effect when \"Start new search\" is selected"))
+ manager.machine:popmessage(_("Changes to this only take effect when \"Start new search\" is selected"))
end
- devsel = incdec(event, devsel, 1, #devtable)
- return true
+ local r
+ devsel, r = incdec(event, devsel, 1, #devtable)
+ return r
end
return m, f
end
menu[#menu + 1] = function()
- local m = { _("Pause Mode"), pausetable[pausesel], 0 }
+ local pausetable = { _("Automatic"), _("Manual") }
+ local m = { _("Pause Mode"), pausetable[pausesel], "on" }
menu_lim(pausesel, 1, pausetable, m)
local function f(event)
if (event == "left" or event == "right") then
if pausesel == 1 then
pausesel = 2
menu_is_showing = false
- manager:machine():popmessage(_("Manually pause & unpause the game when needed with the pause hotkey"))
+ manager.machine:popmessage(_("Manually toggle pause when needed"))
else
pausesel = 1
+ manager.machine:popmessage(_("Automatically toggle pause with on-screen menus"))
emu.pause()
end
+ return true
end
-
- return true
+ return false
end
return m, f
end
-
-
menu[#menu + 1] = function()
local function f(event)
local ret = false
@@ -533,26 +542,21 @@ function cheatfind.startplugin()
menu_blocks[num] = {}
menu_blocks[num][1] = cheat.save(devtable[devcur].space, region.offset, region.size)
end
- manager:machine():popmessage(_("All slots cleared and current state saved to Slot 1"))
+ manager.machine:popmessage(_("All slots cleared and current state saved to Slot 1"))
watches = {}
opsel = 1
value = 0
leftop = 1
rightop = 1
- leftop_text = "Slot 1"
- rightop_text = "Slot 1"
value_text = ""
- expression_text = "Slot 1 < Slot 1"
matchsel = 0
return true
end
end
- local opsel = 1
- return { _("Start new search"), "", 0 }, f
+ local opsel = 1
+ return { _("Start new search"), "", "on" }, f
end
-
-
if #menu_blocks ~= 0 then
menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function()
@@ -561,8 +565,7 @@ function cheatfind.startplugin()
for num, region in ipairs(devtable[devcur].ram) do
menu_blocks[num][#menu_blocks[num] + 1] = cheat.save(devtable[devcur].space, region.offset, region.size)
end
- manager:machine():popmessage(string.format(_("Memory State saved to Slot %d"), #menu_blocks[1]))
-
+ manager.machine:popmessage(string.format(_("Memory state saved to Slot %d"), #menu_blocks[1]))
if (leftop == #menu_blocks[1] - 1 and rightop == #menu_blocks[1] - 2 ) then
leftop = #menu_blocks[1]
rightop = #menu_blocks[1]-1
@@ -574,13 +577,12 @@ function cheatfind.startplugin()
elseif (rightop == #menu_blocks[1] - 1) then
rightop = #menu_blocks[1]
end
- leftop_text = string.format("Slot %d", leftop)
- rightop_text = string.format("Slot %d", rightop)
devsel = devcur
return true
end
+ return false
end
- return { _("Save Current Memory State to Slot ") .. #menu_blocks[1] + 1, "", 0 }, f
+ return { string.format(_("Save current memory state to Slot %d"), #menu_blocks[1] + 1), "", "on" }, f
end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function()
@@ -611,83 +613,89 @@ function cheatfind.startplugin()
count = count + #matches[#matches][num]
end
end
- manager:machine():popmessage(string.format(_("%d total matches found"), count))
+ manager.machine:popmessage(string.format(_("%d total matches found"), count))
matches[#matches].count = count
matchpg = 0
devsel = devcur
return true
end
+ return false
end
+ local slot_slot_comp = _("Perform Compare : Slot %d %s Slot %d")
+ local slot_slot_val_comp = _("Perform Compare : Slot %d %s Slot %d %s %d")
+ local slot_slot_bit_comp = _("Perform Compare : Slot %d BITWISE%s Slot %d")
+ local slot_val_comp = _("Perform Compare : Slot %d %s %d")
+ local expression_text
if optable[opsel] == "lt" then
if (value == 0 ) then
- expression_text = string.format("%s < %s", leftop_text, rightop_text)
+ expression_text = string.format(slot_slot_comp, leftop, "<", rightop)
else
- expression_text = string.format("%s == %s - %d", leftop_text, rightop_text, value)
+ expression_text = string.format(slot_slot_val_comp, leftop, "==", rightop, "-", value)
end
elseif optable[opsel] == "gt" then
if (value == 0 ) then
- expression_text = string.format("%s > %s", leftop_text, rightop_text)
+ expression_text = string.format(slot_slot_comp, leftop, ">", rightop)
else
- expression_text = string.format("%s == %s + %d", leftop_text, rightop_text, value)
+ expression_text = string.format(slot_slot_val_comp, leftop, "==", rightop, "+", value)
end
elseif optable[opsel] == "eq" then
- expression_text = string.format("%s == %s", leftop_text, rightop_text)
+ expression_text = string.format(slot_slot_comp, leftop, "==", rightop)
elseif optable[opsel] == "ne" then
if (value == 0 ) then
- expression_text = string.format("%s != %s", leftop_text, rightop_text)
+ expression_text = string.format(slot_slot_comp, leftop, "!=", rightop)
else
- expression_text = string.format("%s == %s +/- %d", leftop_text, rightop_text, value)
+ expression_text = string.format(slot_slot_val_comp, leftop, "==", rightop, "+/-", value)
end
elseif optable[opsel] == "beq" then
- expression_text = string.format("%s BITWISE== %s", leftop_text, rightop_text)
+ expression_text = string.format(slot_slot_bit_comp, leftop, "==", rightop)
elseif optable[opsel] == "bne" then
- expression_text = string.format("%s BITWISE!= %s", leftop_text, rightop_text)
+ expression_text = string.format(slot_slot_bit_comp, leftop, "!=", rightop)
elseif optable[opsel] == "ltv" then
- expression_text = string.format("%s < %d", leftop_text, value)
+ expression_text = string.format(slot_val_comp, leftop, "<", value)
elseif optable[opsel] == "gtv" then
- expression_text = string.format("%s > %d", leftop_text, value)
+ expression_text = string.format(slot_val_comp, leftop, ">", value)
elseif optable[opsel] == "eqv" then
- expression_text = string.format("%s == %d", leftop_text, value)
+ expression_text = string.format(slot_val_comp, leftop, "==", value)
elseif optable[opsel] == "nev" then
- string.format("%s != %d", leftop_text, value)
+ expression_text = string.format(slot_val_comp, leftop, "!=", value)
end
- return { _("Perform Compare : ") .. expression_text, "", 0 }, f
+ return { expression_text, "", "on" }, f
end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function()
- local m = { _(leftop), "", 0 }
+ local m = { string.format("%d", leftop), "", "on" }
menu_lim(leftop, 1, #menu_blocks[1], m)
- m[1] = string.format("Slot %d", leftop)
- return m, function(event) local r leftop, r = incdec(event, leftop, 1, #menu_blocks[1]) leftop_text = "Slot " .. leftop return r end
+ m[1] = string.format(_("Slot %d"), leftop)
+ return m, function(event) local r leftop, r = incdec(event, leftop, 1, #menu_blocks[1]) return r end
end
menu[#menu + 1] = function()
- local m = { _(optable[opsel]), "", 0 }
+ local m = { _(optable[opsel]), "", "on" }
menu_lim(opsel, 1, #optable, m)
local function f(event)
local r
opsel, r = incdec(event, opsel, 1, #optable)
if event == "left" or event == "right" or event == "comment" then
if optable[opsel] == "lt" then
- manager:machine():popmessage(_("Left less than right"))
+ manager.machine:popmessage(_("Left less than right"))
elseif optable[opsel] == "gt" then
- manager:machine():popmessage(_("Left greater than right"))
+ manager.machine:popmessage(_("Left greater than right"))
elseif optable[opsel] == "eq" then
- manager:machine():popmessage(_("Left equal to right"))
+ manager.machine:popmessage(_("Left equal to right"))
elseif optable[opsel] == "ne" then
- manager:machine():popmessage(_("Left not equal to right"))
+ manager.machine:popmessage(_("Left not equal to right"))
elseif optable[opsel] == "beq" then
- manager:machine():popmessage(_("Left equal to right with bitmask"))
+ manager.machine:popmessage(_("Left equal to right with bitmask"))
elseif optable[opsel] == "bne" then
- manager:machine():popmessage(_("Left not equal to right with bitmask"))
+ manager.machine:popmessage(_("Left not equal to right with bitmask"))
elseif optable[opsel] == "ltv" then
- manager:machine():popmessage(_("Left less than value"))
+ manager.machine:popmessage(_("Left less than value"))
elseif optable[opsel] == "gtv" then
- manager:machine():popmessage(_("Left greater than value"))
+ manager.machine:popmessage(_("Left greater than value"))
elseif optable[opsel] == "eqv" then
- manager:machine():popmessage(_("Left equal to value"))
+ manager.machine:popmessage(_("Left equal to value"))
elseif optable[opsel] == "nev" then
- manager:machine():popmessage(_("Left not equal to value"))
+ manager.machine:popmessage(_("Left not equal to value"))
end
end
return r
@@ -698,10 +706,10 @@ function cheatfind.startplugin()
if optable[opsel]:sub(3, 3) == "v" then
return nil
end
- local m = { _(rightop), "", 0 }
+ local m = { string.format("%d", rightop), "", "on" }
menu_lim(rightop, 1, #menu_blocks[1], m)
- m[1] = string.format("Slot %d", rightop)
- return m, function(event) local r rightop, r = incdec(event, rightop, 1, #menu_blocks[1]) rightop_text = "Slot " .. rightop return r end
+ m[1] = string.format(_("Slot %d"), rightop)
+ return m, function(event) local r rightop, r = incdec(event, rightop, 1, #menu_blocks[1]) return r end
end
menu[#menu + 1] = function()
if optable[opsel] == "bne" or optable[opsel] == "beq" or optable[opsel] == "eq" then
@@ -709,9 +717,9 @@ function cheatfind.startplugin()
end
local m
if optable[opsel] == "ltv" or optable[opsel] == "gtv" or optable[opsel] == "eqv" or optable[opsel] == "nev" then
- m = { _("Value"), value, "" }
+ m = { _("Value"), tostring(value), "" }
else
- m = { _("Difference"), value, "" }
+ m = { _("Difference"), tostring(value), "" }
end
local max = 100 -- max value?
menu_lim(value, 0, max, m)
@@ -722,58 +730,27 @@ function cheatfind.startplugin()
end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function()
- local m = { _("Data Format"), formname[width], 0 }
+ local m = { _("Data Format"), formname[width], "on" }
menu_lim(width, 1, #formtable, m)
return m, function(event) local r width, r = incdec(event, width, 1, #formtable) return r end
end
menu[#menu + 1] = function()
- local m = { _("Test/Write Poke Value"), pokevaltable[pokevalsel], 0 }
+ local pokevaltable = { _("Slot 1 Value"), _("Last Slot Value"), "0x00", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06",
+ "0x07", "0x08", "0x09", "0x63 (99)", "0x99", "0xFF (255)" , "0x3E7 (999)", "0x999", "0x270F (9999)",
+ "0x9999", "0xFFFF (65535)" }
+ local m = { _("Test/Write Poke Value"), pokevaltable[pokevalsel], "on" }
menu_lim(pokevalsel, 1, #pokevaltable, m)
local function f(event)
local r
pokevalsel, r = incdec(event, pokevalsel, 1, #pokevaltable)
if event == "left" or event == "right" or event == "comment" then
if pokevalsel == 1 then
- manager:machine():popmessage(_("Use this if you want to poke the Slot 1 value (eg. You started with something but lost it)"))
+ manager.machine:popmessage(_("Use this if you want to poke the Slot 1 value (eg. You started with something but lost it)"))
elseif pokevalsel == 2 then
- manager:machine():popmessage(_("Use this if you want to poke the Last Slot value (eg. You started without an item but finally got it)"))
- elseif pokevalsel == 3 then
- manager:machine():popmessage(_("Use this if you want to poke 0x00"))
- elseif pokevalsel == 4 then
- manager:machine():popmessage(_("Use this if you want to poke 0x01"))
- elseif pokevalsel == 5 then
- manager:machine():popmessage(_("Use this if you want to poke 0x02"))
- elseif pokevalsel == 6 then
- manager:machine():popmessage(_("Use this if you want to poke 0x03"))
- elseif pokevalsel == 7 then
- manager:machine():popmessage(_("Use this if you want to poke 0x04"))
- elseif pokevalsel == 8 then
- manager:machine():popmessage(_("Use this if you want to poke 0x05"))
- elseif pokevalsel == 9 then
- manager:machine():popmessage(_("Use this if you want to poke 0x06"))
- elseif pokevalsel == 10 then
- manager:machine():popmessage(_("Use this if you want to poke 0x07"))
- elseif pokevalsel == 11 then
- manager:machine():popmessage(_("Use this if you want to poke 0x08"))
- elseif pokevalsel == 12 then
- manager:machine():popmessage(_("Use this if you want to poke 0x09"))
- elseif pokevalsel == 13 then
- manager:machine():popmessage(_("Use this if you want to poke 0x63 (Decimal 99)"))
- elseif pokevalsel == 14 then
- manager:machine():popmessage(_("Use this if you want to poke 0x99 (BCD 99)"))
- elseif pokevalsel == 15 then
- manager:machine():popmessage(_("Use this if you want to poke 0xFF (Decimal 255)"))
- elseif pokevalsel == 16 then
- manager:machine():popmessage(_("Use this if you want to poke 0x3E7 (Decimal 999)"))
- elseif pokevalsel == 17 then
- manager:machine():popmessage(_("Use this if you want to poke 0x999 (BCD 999)"))
- elseif pokevalsel == 18 then
- manager:machine():popmessage(_("Use this if you want to poke 0x270F (Decimal 9999)"))
- elseif pokevalsel == 19 then
- manager:machine():popmessage(_("Use this if you want to poke 0x9999 (BCD 9999)"))
- elseif pokevalsel == 20 then
- manager:machine():popmessage(_("Use this if you want to poke 0xFFFF (Decimal 65535)"))
+ manager.machine:popmessage(_("Use this if you want to poke the Last Slot value (eg. You started without an item but finally got it)"))
+ else
+ manager.machine:popmessage(string.format(_("Use this if you want to poke %s"), pokevaltable[pokevalsel]))
end
end
return r
@@ -781,12 +758,11 @@ function cheatfind.startplugin()
return m, f
end
-
menu[#menu + 1] = function()
if optable[opsel] == "bne" or optable[opsel] == "beq" then
return nil
end
- local m = { "BCD", _("Off"), 0 }
+ local m = { "BCD", _("Off"), "on" }
menu_lim(bcd, 0, 1, m)
if bcd == 1 then
m[2] = _("On")
@@ -797,7 +773,7 @@ function cheatfind.startplugin()
if formtable[width]:sub(3, 3) == "1" then
return nil
end
- local m = { "Aligned only", _("Off"), 0 }
+ local m = { _("Aligned only"), _("Off"), "on" }
menu_lim(align, 0, 1, m)
if align == 1 then
m[2] = _("On")
@@ -812,12 +788,13 @@ function cheatfind.startplugin()
matchpg = 0
return true
end
+ return false
end
- return { _("Undo last search -- #") .. #matches, "", 0 }, f
+ return { _("Undo last search -- #") .. #matches, "", "on" }, f
end
menu[#menu + 1] = function() return { "---", "", "off" }, nil end
menu[#menu + 1] = function()
- local m = { _("Match block"), matchsel, "" }
+ local m = { _("Match block"), tostring(matchsel), "" }
menu_lim(matchsel, 0, #matches[#matches], m)
if matchsel == 0 then
m[2] = _("All")
@@ -873,65 +850,63 @@ function cheatfind.startplugin()
local function match_exec(match)
local dev = devtable[devcur]
-
local wid = formtable[width]:sub(3, 3)
local widchar
local pokevalue
local form
-
- if pokevalsel == 1 then
+ if pokevalsel == 1 then
pokevalue = match.oldval
- elseif pokevalsel == 2 then
+ elseif pokevalsel == 2 then
pokevalue = match.newval
- elseif pokevalsel == 3 then
+ elseif pokevalsel == 3 then
pokevalue = 0
- elseif pokevalsel == 4 then
+ elseif pokevalsel == 4 then
pokevalue = 1
- elseif pokevalsel == 5 then
+ elseif pokevalsel == 5 then
pokevalue = 2
- elseif pokevalsel == 6 then
+ elseif pokevalsel == 6 then
pokevalue = 3
- elseif pokevalsel == 7 then
+ elseif pokevalsel == 7 then
pokevalue = 4
- elseif pokevalsel == 8 then
+ elseif pokevalsel == 8 then
pokevalue = 5
- elseif pokevalsel == 9 then
+ elseif pokevalsel == 9 then
pokevalue = 6
- elseif pokevalsel == 10 then
+ elseif pokevalsel == 10 then
pokevalue = 7
- elseif pokevalsel == 11 then
+ elseif pokevalsel == 11 then
pokevalue = 8
- elseif pokevalsel == 12 then
+ elseif pokevalsel == 12 then
pokevalue = 9
- elseif pokevalsel == 13 then
+ elseif pokevalsel == 13 then
pokevalue = 99
- elseif pokevalsel == 14 then
+ elseif pokevalsel == 14 then
pokevalue = 153
- elseif pokevalsel == 15 then
+ elseif pokevalsel == 15 then
pokevalue = 255
- elseif pokevalsel == 16 and wid == "1" then
+ elseif pokevalsel == 16 and wid == "1" then
pokevalue = 99
- elseif pokevalsel == 17 and wid == "1" then
+ elseif pokevalsel == 17 and wid == "1" then
pokevalue = 153
- elseif pokevalsel == 18 and wid == "1" then
+ elseif pokevalsel == 18 and wid == "1" then
pokevalue = 99
- elseif pokevalsel == 19 and wid == "1" then
+ elseif pokevalsel == 19 and wid == "1" then
pokevalue = 153
- elseif pokevalsel == 20 and wid == "1" then
+ elseif pokevalsel == 20 and wid == "1" then
pokevalue = 255
- elseif pokevalsel == 16 then
+ elseif pokevalsel == 16 then
pokevalue = 999
- elseif pokevalsel == 17 then
+ elseif pokevalsel == 17 then
pokevalue = 2457
- elseif pokevalsel == 18 then
+ elseif pokevalsel == 18 then
pokevalue = 9999
- elseif pokevalsel == 19 then
+ elseif pokevalsel == 19 then
pokevalue = 39321
- elseif pokevalsel == 20 then
+ elseif pokevalsel == 20 then
pokevalue = 65535
end
- local cheat = { desc = string.format(_("Test Cheat %08X:%02X"), match.addr, pokevalue), script = {} }
+ local cheat = { desc = string.format(_("Test Cheat %08X_%02X"), match.addr, pokevalue), script = {} }
if wid == "2" then
wid = "u16"
@@ -970,10 +945,10 @@ function cheatfind.startplugin()
cheat.script.run = "cpu:write_" .. wid .. "(" .. match.addr .. "," .. pokevalue .. ")"
end
if match.mode == 1 then
- if not _G.ce then
- manager:machine():popmessage(_("Cheat engine not available"))
+ if not emu.plugin.cheat then
+ manager.machine:popmessage(_("Cheat engine not available"))
else
- _G.ce.inject(cheat)
+ emu.plugin.cheat.inject(cheat)
end
elseif match.mode == 2 then
cheat_save = {}
@@ -983,17 +958,16 @@ function cheatfind.startplugin()
local setname = emu.romname()
if emu.softname() ~= "" then
if emu.softname():find(":") then
- filename = emu.softname():gsub(":", "/")
+ setname = emu.softname():gsub(":", "/")
else
- for name, image in pairs(manager:machine().images) do
- if image:exists() and image:software_list_name() ~= "" then
- setname = image:software_list_name() .. "/" .. emu.softname()
+ for name, image in pairs(manager.machine.images) do
+ if image.exists and image.software_list_name ~= "" then
+ setname = image.software_list_name .. "/" .. emu.softname()
end
end
end
end
- -- lfs.env_replace is defined in boot.lua
- cheat_save.path = lfs.env_replace(manager:machine():options().entries.cheatpath:value()):match("([^;]+)")
+ cheat_save.path = manager.machine.options.entries.cheatpath:value():match("([^;]+)")
cheat_save.filename = string.format("%s/%s", cheat_save.path, setname)
cheat_save.name = cheat.desc
local json = require("json")
@@ -1001,14 +975,17 @@ function cheatfind.startplugin()
cheat_save.json = json.stringify({[1] = cheat}, {indent = true})
cheat_save.xml = string.format("<mamecheat version=\"1\">\n <cheat desc=\"%%s\">\n <script state=\"run\">\n <action>%s.pp%s@%X=%X</action>\n </script>\n </cheat>\n</mamecheat>", dev.tag:sub(2), widchar, match.addr, match.newval)
cheat_save.simple = string.format("%s,%s,%X,%s,%X,%%s\n", setname, dev.tag, match.addr, widchar, pokevalue)
- cheat_save.dat = string.format(":%s:40000000:%X:%08X:FFFFFFFF:%%s\n", setname, match.addr, pokevalue)
- manager:machine():popmessage(string.format(_("Default name is %s"), cheat_save.name))
+ cheat_save.dat = string.format(":%s:40000000:%X:%08X:FFFFFFFF:%%s\n", setname, match.addr, pokevalue)
+ manager.machine:popmessage(string.format(_("Default name is %s"), cheat_save.name))
return true
else
local func = "return space:read"
- local env = { space = devtable[devcur].space }
+ local env = {}
if not getmetatable(dev.space).__name:match("device_t") then
+ env.space = devtable[devcur].space;
func = func .. "_" .. wid
+ else
+ env.space = emu.item(dev.space.items["0/m_pointer"])
end
func = func .. "(" .. match.addr .. ")"
watches[#watches + 1] = { addr = match.addr, func = load(func, func, "t", env), format = form }
@@ -1027,7 +1004,7 @@ function cheatfind.startplugin()
end
local modes = { _("Test"), _("Write"), _("Watch") }
local m = { string.format("%08x" .. bitwidth .. bitwidth, match.addr, match.oldval,
- match.newval), modes[match.mode], 0 }
+ match.newval), modes[match.mode], "on" }
menu_lim(match.mode, 1, #modes, m)
local function f(event)
local r
@@ -1042,7 +1019,7 @@ function cheatfind.startplugin()
end
if matches[#matches].count > 100 then
menu[#menu + 1] = function()
- local m = { _("Page"), matchpg, 0 }
+ local m = { _("Page"), tostring(matchpg), "on" }
local max
if matchsel == 0 then
max = math.ceil(matches[#matches].count / 100) - 1
@@ -1051,6 +1028,7 @@ function cheatfind.startplugin()
end
menu_lim(matchpg, 0, max, m)
local function f(event)
+ local r
matchpg, r = incdec(event, matchpg, 0, max)
return r
end
@@ -1060,7 +1038,7 @@ function cheatfind.startplugin()
end
if #watches ~= 0 then
menu[#menu + 1] = function()
- return { _("Clear Watches"), "", 0 }, function(event) if event == "select" then watches = {} return true end end
+ return { _("Clear Watches"), "", "on" }, function(event) if event == "select" then watches = {} return true end end
end
end
end
@@ -1068,28 +1046,29 @@ function cheatfind.startplugin()
end
local function menu_callback(index, event)
- if event == "cancel" and pausesel == 1 then
+ if event == "back" and pausesel == 1 then
emu.unpause()
menu_is_showing = false
- return {0,0,0}
+ return false -- return false so menu will be popped off the stack
end
+ if index == 0 then return false end
return menu_func[index](event)
end
emu.register_menu(menu_callback, menu_populate, _("Cheat Finder"))
emu.register_frame_done(function ()
- local tag, screen = next(manager:machine().screens)
- local height = mame_manager:ui():get_line_height()
+ local screen = manager.machine.render.ui_container
+ local height = mame_manager.ui.line_height
for num, watch in ipairs(watches) do
screen:draw_text("left", num * height, string.format(watch.format, watch.addr, watch.func()))
end
- if tabbed_out and manager:ui():is_menu_active() then
+ if tabbed_out and manager.ui.menu_active then
emu.pause()
menu_is_showing = true
tabbed_out = false
end
end)
emu.register_periodic(function ()
- if menu_is_showing and not manager:ui():is_menu_active() then
+ if menu_is_showing and not manager.ui.menu_active then
emu.unpause()
menu_is_showing = false
tabbed_out = true