Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LuaOS STARTUP IS _startup
- --[[
- Author of original code: NeverCast
- ]]--
- --[[
- Project info:
- Name: LuaOS
- Creator: Jesusthekiller
- Language: Lua (CC)
- Website: None
- License: GNU GPL
- License file can be fount at www.jesusthekiller.com/license-gpl.html
- Version: 1.0
- ]]--
- --[[
- Changelog:
- 1.0:
- Initial Release
- 1.1:
- Cheaty distro release
- ]]--
- --[[
- LICENSE:
- LuaOS
- Copyright (c) 2013 Jesusthekiller
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- ]]--
- if not fs.exists("uos") then
- shell.run("pastebin", "get", "eFcg8T1E", "uos")
- end
- if os.myEnv then
- return
- end
- local prevState = {}
- table.size = function(tbl)
- local count = 0
- for _,__ in pairs(tbl) do
- count = count + 1
- end
- return count
- end
- local function getParentShell()
- local at=0
- while true do
- at=at+1
- local ok,env = pcall(function() return getfenv(at) end)
- if not ok then break end
- if table.size(env) == 1 then
- local i,v = next(env) -- Grab first
- if i == "shell" then
- return v
- end
- end
- end
- return nil
- end
- local function recover()
- -- Set flag
- os.myEnv = true
- -- Put back the trampled environment
- os.startTimer = prevState.startTimer
- os.shutdown = prevState.shutdown
- os.pullEvent = prevState.pullEvent
- --
- prevState = nil
- -- start rednet
- os.unloadAPI("rednet")
- os.loadAPI("rednet")
- -- start uos shell
- os.run({}, "uos")
- end
- os.stage = {}
- local function setStage(stage)
- os.stage.currentStage = stage
- end
- local function getStage()
- return os.stage.currentStage
- end
- local function _os_pullEvent(_filter)
- _filter = _filter or ""
- if _filter == "key" then
- setStage("bioswait")
- return "key", 0
- elseif _filter == "timer" then
- setStage("shutdown")
- return "timer", 0
- end
- end
- local function _replSleep(dur)
- local timer = prevState.startTimer( dur )
- repeat
- local sEvent, param = prevState.pullEvent( "timer" )
- until param == timer
- end
- local function _os_shutdown()
- if getStage() == "shutdown" then
- setStage("jstincse")
- elseif getStage() == "bioswait" then
- setStage("biosexit")
- end
- if getStage() == "biosexit" then
- recover()
- end
- end
- local function _os_startTimer(seconds)
- return 0
- end
- local function inject()
- prevState.startTimer = os.startTimer
- prevState.shutdown = os.shutdown
- prevState.pullEvent = os.pullEvent
- os.shutdown = _os_shutdown
- os.pullEvent = _os_pullEvent
- os.startTimer = _os_startTimer
- setStage("injected")
- local shellImpl = getParentShell()
- shellImpl.exit()
- end
- inject()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement