mirror of
https://github.com/Adorable-Catgirl/Zorya-NEO.git
synced 2024-11-14 14:38:04 +11:00
42 lines
3.3 KiB
Lua
42 lines
3.3 KiB
Lua
|
||
local s, t = string, table
|
||
local ss = s.sub
|
||
|
||
--------------------------------------------------------------------------------
|
||
local POS_BITS = 12
|
||
local LEN_BITS = 16 - POS_BITS
|
||
local POS_SIZE = 1 << POS_BITS
|
||
local LEN_SIZE = 1 << LEN_BITS
|
||
local LEN_MIN = 3
|
||
|
||
local function lzss_decompress(input)
|
||
local offset, output = 1, {}
|
||
local window = ''
|
||
|
||
while offset <= #input do
|
||
local flags = s.byte(input, offset)
|
||
offset = offset + 1
|
||
|
||
for i = 1, 8 do
|
||
local str = nil
|
||
if (flags & 1) ~= 0 and offset <= #input then
|
||
str = ss(input, offset, offset)
|
||
offset = offset + 1
|
||
elseif offset + 1 <= #input then
|
||
local tmp = s.unpack('>I2', input, offset)
|
||
offset = offset + 2
|
||
local pos = (tmp >> LEN_BITS) + 1
|
||
local len = (tmp & (LEN_SIZE - 1)) + LEN_MIN
|
||
str = ss(window, pos, pos + len - 1)
|
||
end
|
||
flags = flags >> 1
|
||
if str then
|
||
output[#output + 1] = str
|
||
window = ss(window .. str, -POS_SIZE)
|
||
end
|
||
end
|
||
end
|
||
|
||
return t.concat(output)
|
||
end
|
||
return print(lzss_decompress("ÿlocal a=ÿ..._BIOSÿ=\"Zorya ÿNEO\"_ZVSTR=\"2.0±÷ER=@;_ZPwAT=GIT a9eec0\" |