Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function component.isAvailable(target)
- return component.list(target)() ~= nil
- end
- function computer.getBootAddress()
- return __BIOS_DATA:sub(1, 36)
- end
- setmetatable(component, {
- ["__index"] = function(_, key)
- if component.isAvailable(key) then
- return component.proxy(component.list(key)())
- end
- end
- })
- local eeprom = component.eeprom
- __BIOS_PXE = component.modem ~= nil
- __BIOS_TARGET = ""
- __BIOS_SERVER = ""
- __BIOS_DATA = eeprom.getData()
- __BIOS_LEGACY = (__BIOS_DATA ~= "" and type(__BIOS_DATA == "string")) and #__BIOS_DATA == 36
- event = {}
- local stack = {}
- local listeners = {}
- function event.pull(filter)
- if not filter then return table.remove(stack,1)
- else
- for _,v in pairs(stack) do
- if v == filter then
- return v
- end
- end
- repeat
- t=table.pack(computer.pullSignal())
- evtype = table.remove(t,1)
- if listeners[evtype] ~= nil then
- for k,v in pairs(listeners[evtype]) do
- local evt = pcall(v,evtype,table.unpack(t))
- end
- end
- until evtype == filter
- return evtype, table.unpack(t)
- end
- end
- if __BIOS_DATA:sub(37, 41) == ":http" then
- if component.isAvailable("internet") then
- local url = __BIOS_DATA:sub(38, #__BIOS_DATA)
- local internet = component.internet
- local req = internet.request(url)
- repeat
- local success, connected = pcall(req.finishConnect)
- until success and connected
- __BIOS_TARGET = req.read()
- __BIOS_PXE = false
- end
- if __BIOS_DATA:sub(37, 38) == ":/" or (__BIOS_LEGACY and __BIOS_PXE) then
- local targetAddr = __BIOS_DATA:sub(1, 36)
- local targetFile = __BIOS_DATA:sub(38, #__BIOS_DATA)
- __BIOS_ROOT = component.proxy(targetAddr)
- local handle = __BIOS_ROOT.open(targetFile or __BIOS_LEGACY and "/init.lua")
- __BIOS_TARGET = __BIOS_ROOT.read(handle, math.huge)
- __BIOS_PXE = false
- end
- end
- if __BIOS_PXE then
- local modem = component.modem
- local function status(msg, ...)
- modem.broadcast(2412, msg, ...)
- end
- modem.open(2412)
- status("PXE_READY")
- repeat
- local _, _, addr, _, _, status = event.pull("modem_message")
- __PXE_SERVER = addr
- until status == "PXE_CONNECT"
- status = nil
- repeat
- local _, _, from, _, _, partial = event.pull("modem_message")
- if (from ~= __PXE_SERVER) then
- do break end
- end
- __BIOS_TARGET = __BIOS_TARGET .. partial
- until partial == ""
- end
- return load(__BIOS_TARGET)()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement