Advertisement
TYKUHN2

New EEPROM

Jun 9th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. mainGPU = component.proxy(component.list("gpu")())
  2. mainGPU.bind(component.list("screen")(), true)
  3. eepData = component.invoke(component.list("eeprom")(), "getData") or ""
  4. prefLoad = string.sub(eepData, 1, 36)
  5. prefType = string.sub(eepData, 37, 37)
  6. eepData = nil
  7. readOnly = false
  8. function readManaged(drive)
  9.     mainDrive = drive
  10.     drive = nil
  11.     if mainDrive.isReadOnly() then
  12.         readOnly = true
  13.         return
  14.     end
  15.     local success, file = pcall(mainDrive.open, ".boot", "r")
  16.     if not success then
  17.         return
  18.     end
  19.     success = nil
  20.     readOnly = nil
  21.     local path = mainDrive.read(file, 2048)
  22.     mainDrive.close(file)
  23.     if not path then
  24.         return
  25.     end
  26.     local success, file = pcall(mainDrive.open, path, "r")
  27.     local exec = load(function() return mainDrive.read(file, 2048) end, "=managedBoot@/".. path)
  28.     mainDrive.close(file)
  29.     file, path = nil, nil
  30.     if not exec then
  31.         return
  32.     end
  33.     exec()
  34.     computer.shutdown()
  35. end
  36. function readUnmanaged(drive)
  37.     mainDrive = drive
  38.     drive = nil
  39.     if string.sub(mainDrive.readSector(1), 1, 7) ~= "TYKBOOT" then return end
  40.     readOnly = nil
  41.     local start = 1
  42.     local atByte = 8
  43.     while true do
  44.         local temp = mainDrive.readByte(atByte)
  45.         if temp == -128 then
  46.             start = start / mainDrive.readByte(atByte-1)
  47.             if start == 1 then
  48.                 start = 0
  49.             end
  50.             start = start + mainDrive.readByte(atByte-1)
  51.             break
  52.         end
  53.         start = start * temp
  54.         atByte = atByte + 1
  55.     end
  56.     atByte = 0
  57.     local code = ""
  58.     while true do
  59.         local temp = mainDrive.readByte(start + atByte)
  60.         if temp == 28 then
  61.             break
  62.         end
  63.         atByte = atByte + 1
  64.         code = code .. string.char(temp)
  65.     end
  66.     load(code, "=unmanagedBoot@"..start.."-"..(start+atByte))()
  67.     computer.shutdown()
  68. end
  69. if prefType == "m" then
  70.     local success, drive = pcall(component.proxy, prefLoad)
  71.     prefLoad, prefType = nil, nil
  72.     if success then
  73.         readManaged(drive)
  74.     end
  75. elseif prefType == "u" then
  76.     local success, drive = pcall(component.proxy, prefLoad)
  77.     prefLoad, prefType = nil, nil
  78.     if success then
  79.         readUnmanaged(drive)
  80.     end
  81. end
  82. prefLoad, prefType = nil, nil
  83. list = component.list("filesystem")
  84. while true do
  85.     local success, drive = pcall(component.proxy, list())
  86.     if not success then
  87.         break
  88.     end
  89.     readManaged(drive)
  90. end
  91. list = component.list("drive")
  92. while true do
  93.     local success, drive = pcall(component.proxy, list())
  94.     if not success then
  95.         break
  96.     end
  97.     readUnmanaged(drive)
  98. end
  99. if readOnly then
  100.     error("All mediums are readonly!", 0)
  101. end
  102. error("No Bootable Medium Found!", 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement