summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/cheat/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/cheat/init.lua')
-rw-r--r--plugins/cheat/init.lua49
1 files changed, 33 insertions, 16 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index a096869ce20..0bd9427f8c0 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -23,12 +23,16 @@
-- },
-- "screen": {
-- "varname": "tag"
--- },
+-- },
-- ...
-- "region": {
-- "varname": "tag",
-- ...
-- },
+-- "ram": {
+-- "varname": "tag",
+-- ...
+-- },
-- "script": {
-- "on|off|run|change": "script",
-- ...
@@ -148,7 +152,8 @@ function cheat.startplugin()
draw_box = draw_box,
tobcd = tobcd,
frombcd = frombcd,
- pairs = pairs }
+ pairs = pairs,
+ ipairs = ipairs }
cheat.enabled = false
-- verify scripts are valid first
if not cheat.script then
@@ -158,7 +163,7 @@ function cheat.startplugin()
script = load(script, cheat.desc .. name, "t", cheat.cheat_env)
if not script then
print("error loading cheat script: " .. cheat.desc)
- cheat = { desc = cheat.desc .. "error" }
+ cheat = { desc = cheat.desc .. " error" }
return
end
cheat.script[name] = script
@@ -173,7 +178,7 @@ function cheat.startplugin()
cpu = manager:machine().devices[space.tag]
if not cpu then
print("error loading cheat script: " .. cheat.desc)
- cheat = { desc = cheat.desc .. "error" }
+ cheat = { desc = cheat.desc .. " error" }
return
end
if space.type then
@@ -183,7 +188,7 @@ function cheat.startplugin()
end
if not mem then
print("error loading cheat script: " .. cheat.desc)
- cheat = { desc = cheat.desc .. "error" }
+ cheat = { desc = cheat.desc .. " error" }
return
end
cheat.cheat_env[name] = mem
@@ -206,12 +211,24 @@ function cheat.startplugin()
mem = manager:machine():memory().regions[region]
if not mem then
print("error loading cheat script: " .. cheat.desc)
- cheat = nil
+ cheat = { desc = cheat.desc .. " error" }
return
end
cheat.cheat_env[name] = mem
end
end
+ if cheat.ram then
+ for name, ram in pairs(cheat.ram) do
+ local ram
+ ram = manager:machine().devices[ram]
+ if not ram then
+ print("error loading cheat script: " .. cheat.desc)
+ cheat = { desc = cheat.desc .. " error" }
+ return
+ end
+ cheat.cheat_env[name] = emu.item(ram.items["0/pointer"])
+ end
+ end
local param = cheat.parameter
if not param then
return
@@ -250,7 +267,7 @@ function cheat.startplugin()
local function menu_populate()
local menu = {}
- for num, cheat in pairs(cheats) do
+ for num, cheat in ipairs(cheats) do
menu[num] = {}
menu[num][1] = cheat.desc
if not cheat.parameter then
@@ -259,17 +276,17 @@ function cheat.startplugin()
menu[num][1] = "---"
end
menu[num][2] = ""
- menu[num][3] = 32 -- MENU_FLAG_DISABLE
+ menu[num][3] = "off"
elseif not cheat.script.run and not cheat.script.off then
menu[num][2] = "Set"
menu[num][3] = 0
else
if cheat.enabled then
menu[num][2] = "On"
- menu[num][3] = 1 -- MENU_FLAG_LEFT_ARROW
+ menu[num][3] = "l"
else
menu[num][2] = "Off"
- menu[num][3] = 2 -- MENU_FLAG_RIGHT_ARROW
+ menu[num][3] = "r"
end
end
else
@@ -279,16 +296,16 @@ function cheat.startplugin()
else
menu[num][2] = "Off"
end
- menu[num][3] = 2
+ menu[num][3] = "r"
else
if cheat.parameter.item then
menu[num][2] = cheat.parameter.item[cheat.parameter.index].text
else
menu[num][2] = cheat.parameter.value
end
- menu[num][3] = 1
+ menu[num][3] = "l"
if cheat.parameter.index < cheat.parameter.last then
- menu[num][3] = 3
+ menu[num][3] = "lr"
end
end
end
@@ -415,13 +432,13 @@ function cheat.startplugin()
emu.register_start(function()
cheats = load_cheats()
- for num, cheat in pairs(cheats) do
+ for num, cheat in ipairs(cheats) do
parse_cheat(cheat)
end
end)
emu.register_frame(function()
- for num, cheat in pairs(cheats) do
+ for num, cheat in ipairs(cheats) do
if cheat.enabled and cheat.script.run then
cheat.script.run()
end
@@ -430,7 +447,7 @@ function cheat.startplugin()
emu.register_frame_done(function()
line = 0
- for num, draw in pairs(output) do
+ for num, draw in ipairs(output) do
if draw.type == "text" then
if not draw.color then
draw.scr:draw_text(draw.x, draw.y, draw.str)