Mariopants does not currently export SRAM format. Mario Paint's SRAM is compressed. HertzDevil discovered that Mario Paint's SRAM is encoded with combined LZ77 and huffman algorithms.
Here is the LUA script for SRAM decompression:
Code:
#!/usr/bin/env lua5.3
if #arg < 2 then
print "Usage: lua5.3 mp_unpack.lua <srm> <output>"
os.exit()
end
local f = io.open(arg[1], "rb")
f:seek("set", 0x7FE)
local datasize = ("<I2"):unpack(f:read(2))
local maptable = {}
for i = 1, 0x400 do
maptable[i] = ("<I2"):unpack(f:read(2))
end
local bin = {}
for i = 1, datasize / 2 - 0x400 do
bin[i] = ("<I2"):unpack(f:read(2))
end
local lz = {}
local huff_ptr = 0
for i, v in ipairs(bin) do
for n = 15, 0, -1 do
huff_ptr = maptable[huff_ptr / 2 + (v & (1 << n) ~= 0 and 2 or 1)]
if maptable[huff_ptr / 2 + 1] == 0 then
table.insert(lz, maptable[huff_ptr / 2 + 2])
huff_ptr = 0
end
end
end
local out = {}
local lz_ptr = 1
local lz_size = #lz
while lz_ptr < lz_size do
local lo, hi = lz[lz_ptr], lz[lz_ptr + 1]
lz_ptr = lz_ptr + 2
if hi >= 0x80 then
for i = 1, hi - 0x80 do
out[#out + 1] = out[#out + 1 - lo]
end
else
for i = 1, hi * 0x100 + lo do
out[#out + 1], lz_ptr = lz[lz_ptr], lz_ptr + 1
end
end
end
local outfile = io.open(arg[2], "wb")
outfile:write(string.char(table.unpack(out)))
outfile:close()
f:close()
There is currently no script for recompression yet.