plugins/cheat: add safe table functions to sandbox (nw)

This commit is contained in:
cracyc 2016-04-11 17:39:35 -05:00
parent b548623691
commit b09ae03b65

View File

@ -22,9 +22,9 @@
-- ...
-- },
-- "screen": {
-- "varname": "tag"
-- },
-- "varname": "tag",
-- ...
-- },
-- "region": {
-- "varname": "tag",
-- ...
@ -153,16 +153,18 @@ function cheat.startplugin()
tobcd = tobcd,
frombcd = frombcd,
pairs = pairs,
ipairs = ipairs }
ipairs = ipairs,
table_insert = table.insert,
table_remove = table.remove }
cheat.enabled = false
-- verify scripts are valid first
if not cheat.script then
return
end
for name, script in pairs(cheat.script) do
script = load(script, cheat.desc .. name, "t", cheat.cheat_env)
script, err = load(script, cheat.desc .. name, "t", cheat.cheat_env)
if not script then
print("error loading cheat script: " .. cheat.desc)
print("error loading cheat script: " .. cheat.desc .. " " .. err)
cheat = { desc = cheat.desc .. " error" }
return
end
@ -233,21 +235,9 @@ function cheat.startplugin()
if not param then
return
end
if not param.min then
param.min = 0
else
param.min = tonumber(param.min)
end
if not param.max then
param.max = #param.item
else
param.max = tonumber(param.max)
end
if not param.step then
param.step = 1
else
param.step = tonumber(param.step)
end
param.min = tonumber(param.min) or 0
param.min = tonumber(param.min) or #param.item
param.step = tonumber(param.step) or 1
if param.item then
for count, item in pairs(param.item) do
if not item.value then
@ -432,13 +422,13 @@ function cheat.startplugin()
emu.register_start(function()
cheats = load_cheats()
for num, cheat in ipairs(cheats) do
for num, cheat in pairs(cheats) do
parse_cheat(cheat)
end
end)
emu.register_frame(function()
for num, cheat in ipairs(cheats) do
for num, cheat in pairs(cheats) do
if cheat.enabled and cheat.script.run then
cheat.script.run()
end
@ -447,7 +437,7 @@ function cheat.startplugin()
emu.register_frame_done(function()
line = 0
for num, draw in ipairs(output) do
for num, draw in pairs(output) do
if draw.type == "text" then
if not draw.color then
draw.scr:draw_text(draw.x, draw.y, draw.str)
@ -455,9 +445,9 @@ function cheat.startplugin()
draw.scr:draw_text(draw.x, draw.y, draw.str, draw.color)
end
elseif draw.type == "line" then
draw.scr:draw_line(draw.x1, draw.x2, draw.y1, draw.y2, draw.color)
draw.scr:draw_line(draw.x1, draw.y1, draw.x2, draw.y2, draw.color)
elseif draw.type == "box" then
draw.scr:draw_box(draw.x1, draw.x2, draw.y1, draw.y2, draw.bgcolor, draw.linecolor)
draw.scr:draw_box(draw.x1, draw.y1, draw.x2, draw.y2, draw.bgcolor, draw.linecolor)
end
end
output = {}