整理cmd代码,用户代码能访问更多东西并且使用保护模式执行可以返回错误,增加一个解谜要素
This commit is contained in:
@@ -6,27 +6,71 @@ local inputBox=WIDGET.newInputBox{name="input",x=40,y=650,w=1200,h=50}
|
|||||||
local outputBox=WIDGET.newTextBox{name="output",x=40,y=30,w=1200,h=600,font=25,lineH=25,fix=true}
|
local outputBox=WIDGET.newTextBox{name="output",x=40,y=30,w=1200,h=600,font=25,lineH=25,fix=true}
|
||||||
outputBox:push("Techmino Shell")
|
outputBox:push("Techmino Shell")
|
||||||
outputBox:push("©2020 26F Studio some rights reserved")
|
outputBox:push("©2020 26F Studio some rights reserved")
|
||||||
local history,hisPtr={"help"}
|
local history,hisPtr={"?"}
|
||||||
|
|
||||||
local scene={}
|
|
||||||
|
|
||||||
|
local noLog=false
|
||||||
local function log(str)
|
local function log(str)
|
||||||
outputBox:push(str)
|
if noLog then return end
|
||||||
|
outputBox:push(tostring(str))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Environment for user's function
|
||||||
local userEnv={
|
local userEnv={
|
||||||
print=log,
|
assert=assert,error=error,
|
||||||
math=math,
|
tonumber=tonumber,tostring=tostring,
|
||||||
table=table,
|
select=select,next=next,
|
||||||
string=string,
|
ipairs=ipairs,pairs=pairs,
|
||||||
}
|
print=log,type=type,
|
||||||
|
pcall=pcall,xpcall=xpcall,
|
||||||
|
rawget=rawget,rawset=rawset,rawlen=rawlen,rawequal=rawequal,
|
||||||
|
setfenv=setfenv,setmetatable=setmetatable,
|
||||||
|
-- load=load,loadfile=loadfile,dofile=dofile,
|
||||||
|
-- getfenv=getfenv,getmetatable=getmetatable,
|
||||||
|
-- collectgarbage=collectgarbage,
|
||||||
|
|
||||||
function scene.sceneInit()
|
math={},
|
||||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
table={},
|
||||||
BG.set("none")
|
string={},
|
||||||
|
coroutine={},
|
||||||
|
bit32={},
|
||||||
|
debug={"No way."},
|
||||||
|
package={"No way."},
|
||||||
|
io={"No way."},
|
||||||
|
os={"No way."},
|
||||||
|
_VERSION=VERSION_CODE,
|
||||||
|
}userEnv._G=userEnv
|
||||||
|
TABLE.complete(math, userEnv.math)
|
||||||
|
TABLE.complete(table, userEnv.table)
|
||||||
|
TABLE.complete(string, userEnv.string)
|
||||||
|
TABLE.complete(coroutine, userEnv.coroutine)
|
||||||
|
TABLE.complete(bit, userEnv.bit)
|
||||||
|
|
||||||
|
--Puzzle box
|
||||||
|
local first_key={}
|
||||||
|
local fleg={
|
||||||
|
pw=(14^2*10)..(2*11),
|
||||||
|
second_box="Coming soon",
|
||||||
|
}setmetatable(fleg,{__tostring=function()return"The fl\97g."end})
|
||||||
|
local function first_box(k,f)
|
||||||
|
if k~=first_key then log"Usage:"log"?"return end
|
||||||
|
if not f then log"Two keys needed"return end
|
||||||
|
if type(f):byte()~=102 then log"Function need"return end
|
||||||
|
noLog=true
|
||||||
|
if not f()then noLog=false log"There are something in the void."return end
|
||||||
|
if f()~=f then noLog=false log"It is itself."return end
|
||||||
|
if f(26)~=math.huge then noLog=false log"26 can create the huge"return end
|
||||||
|
noLog=false
|
||||||
|
log"You lose."
|
||||||
|
return fleg
|
||||||
end
|
end
|
||||||
|
userEnv.the_key=first_key
|
||||||
|
userEnv.the_box=first_box
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local commands={}
|
||||||
|
--Basic commands
|
||||||
|
do--commands.help(arg)
|
||||||
-- command_help_messages format:
|
-- command_help_messages format:
|
||||||
-- command_help_messages is a table
|
-- command_help_messages is a table
|
||||||
-- key: the command
|
-- key: the command
|
||||||
@@ -41,11 +85,26 @@ local command_help_messages={
|
|||||||
details={
|
details={
|
||||||
"Display help messages.",
|
"Display help messages.",
|
||||||
"",
|
"",
|
||||||
|
"Aliases: help ?",
|
||||||
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"help",
|
"help",
|
||||||
"help [page]",
|
"help [page]",
|
||||||
"help [command_name]"
|
"help [command_name]",
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
["?"]={
|
||||||
|
description="Display help messages.",
|
||||||
|
details={
|
||||||
|
"Display help messages.",
|
||||||
|
"",
|
||||||
|
"Aliases: help ?",
|
||||||
|
"",
|
||||||
|
"Usage:",
|
||||||
|
"help",
|
||||||
|
"help [page]",
|
||||||
|
"help [command_name]",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
["#"]={
|
["#"]={
|
||||||
description="Run arbitrary Lua code.",
|
description="Run arbitrary Lua code.",
|
||||||
@@ -53,10 +112,11 @@ local command_help_messages={
|
|||||||
"Run arbitrary Lua code.",
|
"Run arbitrary Lua code.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"#<lua_source_code>",
|
"#[lua_source_code]",
|
||||||
"",
|
"",
|
||||||
"print() can be used to print text into this window."
|
"print() can be used to print text into this window.",
|
||||||
}
|
"There is a strange box.",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
exit={
|
exit={
|
||||||
description="Return to the previous menu.",
|
description="Return to the previous menu.",
|
||||||
@@ -66,8 +126,8 @@ local command_help_messages={
|
|||||||
"Aliases: exit quit bye",
|
"Aliases: exit quit bye",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"exit"
|
"exit",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
quit={
|
quit={
|
||||||
description="Return to the previous menu.",
|
description="Return to the previous menu.",
|
||||||
@@ -77,8 +137,8 @@ local command_help_messages={
|
|||||||
"Aliases: exit quit bye",
|
"Aliases: exit quit bye",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"exit"
|
"exit",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
bye={
|
bye={
|
||||||
description="Return to the previous menu.",
|
description="Return to the previous menu.",
|
||||||
@@ -88,8 +148,8 @@ local command_help_messages={
|
|||||||
"Aliases: exit quit bye",
|
"Aliases: exit quit bye",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"exit"
|
"exit",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
echo={
|
echo={
|
||||||
description="Print a message to this window.",
|
description="Print a message to this window.",
|
||||||
@@ -97,8 +157,8 @@ local command_help_messages={
|
|||||||
"Print a message to this window.",
|
"Print a message to this window.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"echo <message>"
|
"echo [message]",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
cls={
|
cls={
|
||||||
description="Clear the log output.",
|
description="Clear the log output.",
|
||||||
@@ -106,8 +166,8 @@ local command_help_messages={
|
|||||||
"Clear the log output.",
|
"Clear the log output.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"cls"
|
"cls",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
shutdown={
|
shutdown={
|
||||||
description="(Attempt to) shutdown your machine.",
|
description="(Attempt to) shutdown your machine.",
|
||||||
@@ -117,8 +177,8 @@ local command_help_messages={
|
|||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"shutdown",
|
"shutdown",
|
||||||
"shutdown [args]"
|
"shutdown [args]",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
fn={
|
fn={
|
||||||
description="Simulates a Function key press.",
|
description="Simulates a Function key press.",
|
||||||
@@ -127,8 +187,8 @@ local command_help_messages={
|
|||||||
"Useful if you are on a mobile device without access to these keys.",
|
"Useful if you are on a mobile device without access to these keys.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"fn <1-12>"
|
"fn <1-12>",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
scrinfo={
|
scrinfo={
|
||||||
description="Display information about your screen.",
|
description="Display information about your screen.",
|
||||||
@@ -136,8 +196,8 @@ local command_help_messages={
|
|||||||
"Display information about your screen.",
|
"Display information about your screen.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"scrinfo"
|
"scrinfo",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
wireframe={
|
wireframe={
|
||||||
description="Enable or disable wireframe.",
|
description="Enable or disable wireframe.",
|
||||||
@@ -145,8 +205,8 @@ local command_help_messages={
|
|||||||
"Enable or disable wireframe.",
|
"Enable or disable wireframe.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"wireframe <true|false>"
|
"wireframe <true|false>",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
gammacorrect={
|
gammacorrect={
|
||||||
description="Enable or disable gamma correction.",
|
description="Enable or disable gamma correction.",
|
||||||
@@ -154,8 +214,8 @@ local command_help_messages={
|
|||||||
"Enable or disable gamma correction.",
|
"Enable or disable gamma correction.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"gammacorrect <true|false>"
|
"gammacorrect <true|false>",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
rmwtm={
|
rmwtm={
|
||||||
description="Remove the \"no recording\" watermark.",
|
description="Remove the \"no recording\" watermark.",
|
||||||
@@ -164,8 +224,8 @@ local command_help_messages={
|
|||||||
"You will need a password to do that.",
|
"You will need a password to do that.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"rmwtm <password>"
|
"rmwtm [password]",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
unlockall={
|
unlockall={
|
||||||
description="Unlock all modes on the map.",
|
description="Unlock all modes on the map.",
|
||||||
@@ -173,8 +233,8 @@ local command_help_messages={
|
|||||||
"Unlock all modes on the map.",
|
"Unlock all modes on the map.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"unlockall"
|
"unlockall",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
play={
|
play={
|
||||||
description="Load a game mode, including those that are not on the map.",
|
description="Load a game mode, including those that are not on the map.",
|
||||||
@@ -182,8 +242,8 @@ local command_help_messages={
|
|||||||
"Load a game mode, including those that are not on the map.",
|
"Load a game mode, including those that are not on the map.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"play <mode_name>"
|
"play [mode_name]",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
festival={
|
festival={
|
||||||
description="Load a festival theme.",
|
description="Load a festival theme.",
|
||||||
@@ -191,9 +251,11 @@ local command_help_messages={
|
|||||||
"Load a festival theme.",
|
"Load a festival theme.",
|
||||||
"",
|
"",
|
||||||
"Usage:",
|
"Usage:",
|
||||||
"festival list",
|
"festival [festival_name]",
|
||||||
"festival <festival_name>"
|
"",
|
||||||
}
|
"Available festivals:",
|
||||||
|
"classic|xmas|sprfes|zday",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,12 +280,9 @@ local command_help_list={
|
|||||||
}
|
}
|
||||||
|
|
||||||
local command_help_page_size=10
|
local command_help_page_size=10
|
||||||
|
|
||||||
local commands={}
|
|
||||||
--Basic commands
|
|
||||||
function commands.help(arg)
|
function commands.help(arg)
|
||||||
if command_help_messages[arg]then -- help [command]
|
if command_help_messages[arg]then -- help [command]
|
||||||
for _,v in pairs(command_help_messages[arg].details)do
|
for _,v in ipairs(command_help_messages[arg].details)do
|
||||||
log(v)
|
log(v)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
@@ -247,6 +306,7 @@ function commands.help(arg)
|
|||||||
log("".._c.." - "..command_help_messages[_c].description)
|
log("".._c.." - "..command_help_messages[_c].description)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
function commands.shutdown(arg)os.execute("shutdown "..arg)end
|
function commands.shutdown(arg)os.execute("shutdown "..arg)end
|
||||||
function commands.cls()outputBox:clear()end
|
function commands.cls()outputBox:clear()end
|
||||||
commands.echo=log
|
commands.echo=log
|
||||||
@@ -282,8 +342,8 @@ function commands.gammacorrect(bool)
|
|||||||
log"Usage: gammacorrect [true|false]"
|
log"Usage: gammacorrect [true|false]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function commands.rmwtm(password)
|
function commands.rmwtm(pw)
|
||||||
if password==(14^2*10)..(2*11)then
|
if pw==fleg.pw then
|
||||||
_G["\100\114\97\119\70\87\77"]=NULL
|
_G["\100\114\97\119\70\87\77"]=NULL
|
||||||
log("\68\69\86\58\87\97\116\101\114\109\97\114\107\32\82\101\109\111\118\101\100")
|
log("\68\69\86\58\87\97\116\101\114\109\97\114\107\32\82\101\109\111\118\101\100")
|
||||||
SFX.play("clear")
|
SFX.play("clear")
|
||||||
@@ -316,10 +376,7 @@ function commands.play(m)--marathon_bfmax can only entered through here
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function commands.festival(name)
|
function commands.festival(name)
|
||||||
if name=="list" then
|
if name=="classic"then
|
||||||
log("Available festivals:")
|
|
||||||
log("classic xmas sprfes zday")
|
|
||||||
elseif name=="classic"then
|
|
||||||
FESTIVAL=false
|
FESTIVAL=false
|
||||||
BG.setDefault("space")
|
BG.setDefault("space")
|
||||||
BGM.setDefault("blank")
|
BGM.setDefault("blank")
|
||||||
@@ -339,29 +396,42 @@ function commands.festival(name)
|
|||||||
BG.setDefault("lanterns")
|
BG.setDefault("lanterns")
|
||||||
BGM.setDefault("overzero")
|
BGM.setDefault("overzero")
|
||||||
BGM.play()
|
BGM.play()
|
||||||
elseif name~="" then
|
|
||||||
log("No festival called "..name)
|
|
||||||
else
|
else
|
||||||
log"Usage: festival [festivalName]"
|
if name~=""then
|
||||||
|
log("No festival called "..name)
|
||||||
|
end
|
||||||
|
log"Usage: festival [fesitivalName]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local scene={}
|
||||||
|
|
||||||
|
function scene.sceneInit()
|
||||||
|
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
||||||
|
BG.set("none")
|
||||||
|
end
|
||||||
|
|
||||||
function scene.keyDown(k)
|
function scene.keyDown(k)
|
||||||
if k=="return"then
|
if k=="return"then
|
||||||
local input=inputBox.value
|
local input=inputBox.value
|
||||||
|
log""
|
||||||
log("> "..input)
|
log("> "..input)
|
||||||
if input:byte()==35 then
|
if input:byte()==35 then
|
||||||
--Execute code
|
--Execute code
|
||||||
local code=loadstring(input:sub(2))
|
local code,err=loadstring(input:sub(2))
|
||||||
if code then
|
if code then
|
||||||
setfenv(code,userEnv)
|
setfenv(code,userEnv)
|
||||||
ins(history,input)
|
code,err=pcall(code)
|
||||||
code()
|
if not code then
|
||||||
else
|
log("[ERR] "..err)
|
||||||
log"Syntax error"
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log("[SYNTAX ERR] "..err)
|
||||||
|
end
|
||||||
|
ins(history,input)
|
||||||
|
hisPtr=nil
|
||||||
elseif input~=""then
|
elseif input~=""then
|
||||||
--Load command
|
--Load command
|
||||||
local p=input:find(" ")
|
local p=input:find(" ")
|
||||||
|
|||||||
Reference in New Issue
Block a user