整理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}
|
||||
outputBox:push("Techmino Shell")
|
||||
outputBox:push("©2020 26F Studio some rights reserved")
|
||||
local history,hisPtr={"help"}
|
||||
|
||||
local scene={}
|
||||
local history,hisPtr={"?"}
|
||||
|
||||
local noLog=false
|
||||
local function log(str)
|
||||
outputBox:push(str)
|
||||
if noLog then return end
|
||||
outputBox:push(tostring(str))
|
||||
end
|
||||
|
||||
--Environment for user's function
|
||||
local userEnv={
|
||||
print=log,
|
||||
math=math,
|
||||
table=table,
|
||||
string=string,
|
||||
}
|
||||
assert=assert,error=error,
|
||||
tonumber=tonumber,tostring=tostring,
|
||||
select=select,next=next,
|
||||
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()
|
||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
||||
BG.set("none")
|
||||
math={},
|
||||
table={},
|
||||
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
|
||||
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 is a table
|
||||
-- key: the command
|
||||
@@ -41,11 +85,26 @@ local command_help_messages={
|
||||
details={
|
||||
"Display help messages.",
|
||||
"",
|
||||
"Aliases: help ?",
|
||||
"",
|
||||
"Usage:",
|
||||
"help",
|
||||
"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.",
|
||||
@@ -53,10 +112,11 @@ local command_help_messages={
|
||||
"Run arbitrary Lua code.",
|
||||
"",
|
||||
"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={
|
||||
description="Return to the previous menu.",
|
||||
@@ -66,8 +126,8 @@ local command_help_messages={
|
||||
"Aliases: exit quit bye",
|
||||
"",
|
||||
"Usage:",
|
||||
"exit"
|
||||
}
|
||||
"exit",
|
||||
},
|
||||
},
|
||||
quit={
|
||||
description="Return to the previous menu.",
|
||||
@@ -77,8 +137,8 @@ local command_help_messages={
|
||||
"Aliases: exit quit bye",
|
||||
"",
|
||||
"Usage:",
|
||||
"exit"
|
||||
}
|
||||
"exit",
|
||||
},
|
||||
},
|
||||
bye={
|
||||
description="Return to the previous menu.",
|
||||
@@ -88,8 +148,8 @@ local command_help_messages={
|
||||
"Aliases: exit quit bye",
|
||||
"",
|
||||
"Usage:",
|
||||
"exit"
|
||||
}
|
||||
"exit",
|
||||
},
|
||||
},
|
||||
echo={
|
||||
description="Print a message to this window.",
|
||||
@@ -97,8 +157,8 @@ local command_help_messages={
|
||||
"Print a message to this window.",
|
||||
"",
|
||||
"Usage:",
|
||||
"echo <message>"
|
||||
}
|
||||
"echo [message]",
|
||||
},
|
||||
},
|
||||
cls={
|
||||
description="Clear the log output.",
|
||||
@@ -106,8 +166,8 @@ local command_help_messages={
|
||||
"Clear the log output.",
|
||||
"",
|
||||
"Usage:",
|
||||
"cls"
|
||||
}
|
||||
"cls",
|
||||
},
|
||||
},
|
||||
shutdown={
|
||||
description="(Attempt to) shutdown your machine.",
|
||||
@@ -117,8 +177,8 @@ local command_help_messages={
|
||||
"",
|
||||
"Usage:",
|
||||
"shutdown",
|
||||
"shutdown [args]"
|
||||
}
|
||||
"shutdown [args]",
|
||||
},
|
||||
},
|
||||
fn={
|
||||
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.",
|
||||
"",
|
||||
"Usage:",
|
||||
"fn <1-12>"
|
||||
}
|
||||
"fn <1-12>",
|
||||
},
|
||||
},
|
||||
scrinfo={
|
||||
description="Display information about your screen.",
|
||||
@@ -136,8 +196,8 @@ local command_help_messages={
|
||||
"Display information about your screen.",
|
||||
"",
|
||||
"Usage:",
|
||||
"scrinfo"
|
||||
}
|
||||
"scrinfo",
|
||||
},
|
||||
},
|
||||
wireframe={
|
||||
description="Enable or disable wireframe.",
|
||||
@@ -145,8 +205,8 @@ local command_help_messages={
|
||||
"Enable or disable wireframe.",
|
||||
"",
|
||||
"Usage:",
|
||||
"wireframe <true|false>"
|
||||
}
|
||||
"wireframe <true|false>",
|
||||
},
|
||||
},
|
||||
gammacorrect={
|
||||
description="Enable or disable gamma correction.",
|
||||
@@ -154,8 +214,8 @@ local command_help_messages={
|
||||
"Enable or disable gamma correction.",
|
||||
"",
|
||||
"Usage:",
|
||||
"gammacorrect <true|false>"
|
||||
}
|
||||
"gammacorrect <true|false>",
|
||||
},
|
||||
},
|
||||
rmwtm={
|
||||
description="Remove the \"no recording\" watermark.",
|
||||
@@ -164,8 +224,8 @@ local command_help_messages={
|
||||
"You will need a password to do that.",
|
||||
"",
|
||||
"Usage:",
|
||||
"rmwtm <password>"
|
||||
}
|
||||
"rmwtm [password]",
|
||||
},
|
||||
},
|
||||
unlockall={
|
||||
description="Unlock all modes on the map.",
|
||||
@@ -173,8 +233,8 @@ local command_help_messages={
|
||||
"Unlock all modes on the map.",
|
||||
"",
|
||||
"Usage:",
|
||||
"unlockall"
|
||||
}
|
||||
"unlockall",
|
||||
},
|
||||
},
|
||||
play={
|
||||
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.",
|
||||
"",
|
||||
"Usage:",
|
||||
"play <mode_name>"
|
||||
}
|
||||
"play [mode_name]",
|
||||
},
|
||||
},
|
||||
festival={
|
||||
description="Load a festival theme.",
|
||||
@@ -191,9 +251,11 @@ local command_help_messages={
|
||||
"Load a festival theme.",
|
||||
"",
|
||||
"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 commands={}
|
||||
--Basic commands
|
||||
function commands.help(arg)
|
||||
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)
|
||||
end
|
||||
return
|
||||
@@ -247,6 +306,7 @@ function commands.help(arg)
|
||||
log("".._c.." - "..command_help_messages[_c].description)
|
||||
end
|
||||
end
|
||||
end
|
||||
function commands.shutdown(arg)os.execute("shutdown "..arg)end
|
||||
function commands.cls()outputBox:clear()end
|
||||
commands.echo=log
|
||||
@@ -282,8 +342,8 @@ function commands.gammacorrect(bool)
|
||||
log"Usage: gammacorrect [true|false]"
|
||||
end
|
||||
end
|
||||
function commands.rmwtm(password)
|
||||
if password==(14^2*10)..(2*11)then
|
||||
function commands.rmwtm(pw)
|
||||
if pw==fleg.pw then
|
||||
_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")
|
||||
SFX.play("clear")
|
||||
@@ -316,10 +376,7 @@ function commands.play(m)--marathon_bfmax can only entered through here
|
||||
end
|
||||
end
|
||||
function commands.festival(name)
|
||||
if name=="list" then
|
||||
log("Available festivals:")
|
||||
log("classic xmas sprfes zday")
|
||||
elseif name=="classic"then
|
||||
if name=="classic"then
|
||||
FESTIVAL=false
|
||||
BG.setDefault("space")
|
||||
BGM.setDefault("blank")
|
||||
@@ -339,29 +396,42 @@ function commands.festival(name)
|
||||
BG.setDefault("lanterns")
|
||||
BGM.setDefault("overzero")
|
||||
BGM.play()
|
||||
elseif name~="" then
|
||||
log("No festival called "..name)
|
||||
else
|
||||
log"Usage: festival [festivalName]"
|
||||
if name~=""then
|
||||
log("No festival called "..name)
|
||||
end
|
||||
log"Usage: festival [fesitivalName]"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
local scene={}
|
||||
|
||||
function scene.sceneInit()
|
||||
TASK.new(function()YIELD()WIDGET.sel=inputBox end)
|
||||
BG.set("none")
|
||||
end
|
||||
|
||||
function scene.keyDown(k)
|
||||
if k=="return"then
|
||||
local input=inputBox.value
|
||||
log""
|
||||
log("> "..input)
|
||||
if input:byte()==35 then
|
||||
--Execute code
|
||||
local code=loadstring(input:sub(2))
|
||||
local code,err=loadstring(input:sub(2))
|
||||
if code then
|
||||
setfenv(code,userEnv)
|
||||
ins(history,input)
|
||||
code()
|
||||
else
|
||||
log"Syntax error"
|
||||
code,err=pcall(code)
|
||||
if not code then
|
||||
log("[ERR] "..err)
|
||||
end
|
||||
else
|
||||
log("[SYNTAX ERR] "..err)
|
||||
end
|
||||
ins(history,input)
|
||||
hisPtr=nil
|
||||
elseif input~=""then
|
||||
--Load command
|
||||
local p=input:find(" ")
|
||||
|
||||
Reference in New Issue
Block a user