OC-Tsuki/extras/crescent/velx.lua

42 lines
1.0 KiB
Lua

local function lzss_decompress(a)local b,c,d,e,j,i,h,g=1,'',''while b<=#a do
e=c.byte(a,b)b=b+1
for k=0,7 do h=c.sub
g=h(a,b,b)if e>>k&1<1 and b<#a then
i=c.unpack('>I2',a,b)j=1+(i>>4)g=h(d,j,j+(i&15)+2)b=b+1
end
b=b+1
c=c..g
d=h(d..g,-4^6)end
end
return c end
local function load_velx(addr, path)
status("loading kernel... "..lsc())
local fs = component.proxy(addr)
local h = fs.open(path)
local magic, fver, comp, lver, osid, psize = string.unpack("<c5BBBBxxxxI3xxxxxxxxxx", fs.read(h, 13))
if (magic ~= "\27VelX" or fver ~= 1 or osid ~= 127) then
return
end
local rdat = psize
local dat = ""
local buf = ""
repeat
buf = fs.read(h, rdat)
if (buf) then
dat = dat .. buf
end
rdat = psize - #dat
y = y - 1
status("loading kernel... "..lsc())
until rdat == 0 or not buf or buf == ""
y = y - 1
status("loading kernel... ")
if (comp == 1) then
status("decompressing kernel...")
dat = lzss_decompress(dat)
end
local env = {}
env._G = env
return load(dat, "="..path, "t", setmetatable(env, {__index=_G})), env
end