summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2020-09-15 09:37:47 -0500
committer GitHub <noreply@github.com>2020-09-15 09:37:47 -0500
commit90fd79601bed949b48fa2780e88a63bd19d2a459 (patch)
tree3c8d6023570019d4d9fd52c39822a19836c61710 /plugins
parent8e517cc746cefb238ed8baeed0b7531ae794dfbf (diff)
plugins/cheat: copy the cheat table to not expose internal state (#7238)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/cheat/init.lua46
1 files changed, 42 insertions, 4 deletions
diff --git a/plugins/cheat/init.lua b/plugins/cheat/init.lua
index 2293e3c0605..81b7a66ce7e 100644
--- a/plugins/cheat/init.lua
+++ b/plugins/cheat/init.lua
@@ -580,7 +580,7 @@ function cheat.startplugin()
cheat.get_value = function(cheat) return cheat.parameter.value end
cheat.get_text = function(cheat)
if cheat.parameter.item then
- return cheat.parameter.item[cheat.parameter.index]
+ return cheat.parameter.item[cheat.parameter.index].text
else
return cheat.parameter.value
end
@@ -761,8 +761,8 @@ function cheat.startplugin()
end
elseif event == "right" then
if cheat.parameter then
- local idx, chd = cheat:set_index(cheat:get_index() + 1)
- return chd
+ local idx, chg = cheat:set_index(cheat:get_index() + 1)
+ return chg
else
if not cheat:is_oneshot() then
local state, chg = cheat:set_enabled(true)
@@ -906,7 +906,45 @@ function cheat.startplugin()
end
function ce.get(index)
- return cheats[index]
+ local cheat = cheats[index]
+ if not cheat then
+ return nil
+ end
+ local intf = {
+ get_enabled = function() return cheat:get_enabled() end,
+ set_enabled = function(status) return cheat:set_enabled(status) end,
+ desc = cheat.desc,
+ is_oneshot = cheat:is_oneshot(),
+ comment = cheat.comment,
+ get_hotkeys = function() if cheat.hotkeys then return cheat.hotkeys.keys end return nil end,
+ set_hotkeys = function(seq) cheat.hotkeys = { pressed = false, keys = manager:machine():input():seq_clean(seq) } end
+ }
+ if cheat.script then
+ intf.script = {}
+ if cheat.script.on then intf.script.on = true end
+ if cheat.script.off then intf.script.off = true end
+ if cheat.script.run then intf.script.run = true end
+ if cheat.script.change then intf.script.change = true end
+ end
+
+ if cheat.parameter then
+ intf.parameter = {}
+ intf.get_value = function() return cheat:get_value() end
+ intf.set_value = function(value) return cheat:set_value(value) end
+ intf.get_index = function() return cheat:get_index() end
+ intf.set_index = function(index) return cheat:set_index(index) end
+ intf.parameter.min = cheat.parameter.min
+ intf.parameter.max = cheat.parameter.max
+ intf.parameter.step = cheat.parameter.step
+ if cheat.parameter.item then
+ intf.parameter.item = {}
+ for idx, item in pairs(cheat.parameter.item) do
+ intf.parameter.item[idx].text = cheat.parameter.item[idx].text
+ intf.parameter.item[idx].value = cheat.parameter.item[idx].value
+ end
+ end
+ end
+ return intf
end
function ce.list()