Skip to content

Instantly share code, notes, and snippets.

@uyjulian
Last active August 22, 2023 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uyjulian/4f62d799ec0378cc24536e667279c7b2 to your computer and use it in GitHub Desktop.
Save uyjulian/4f62d799ec0378cc24536e667279c7b2 to your computer and use it in GitHub Desktop.
-- Better code have been released since then; see Trails Research Group: https://github.com/Trails-Research-Group
fu = require"file_util"
struct = require"struct"
proc = require"ipc.proc"
up = struct.unpack
rp = struct.pack
exception_filename = {
--for Zero
"bc0510.flg",
"bc0520.flg",
"bc0530.flg",
"bc0540.flg",
"bc0550.flg",
"bc130b.flg",
"bc1400.flg",
"bc140b.flg",
"bc1410.flg",
"bc141b.flg",
"bc1420.flg",
"bc1450.flg",
"bc1460.flg",
"bc1470.flg",
"bm0000.flg",
"bm0001.flg",
"bm0002.flg",
"bm0010.flg",
"bm0011.flg",
"bm0012.flg",
"bm0013.flg",
"bm0100.flg",
"bm0101.flg",
"bm0102.flg",
"bm0110.flg",
"bm0111.flg",
"bm0112.flg",
"bm0113.flg",
"bm0114.flg",
"bm1000.flg",
"bm1010.flg",
"bm1020.flg",
"bm1030.flg",
"bm1040.flg",
"bm1050.flg",
"bm1060.flg",
"bm2000.flg",
"bm2020.flg",
"bm2050.flg",
"bm2099.flg",
"bm3000.flg",
"bm3010.flg",
"bm3020.flg",
"bm3030.flg",
"bm3040.flg",
"bm3050.flg",
"bm3060.flg",
"bm3070.flg",
"bm3080.flg",
"bm3081.flg",
"bm3090.flg",
"br0000.flg",
"br000b.flg",
"br0100.flg",
"br1000.flg",
"br1500.flg",
"br1510.flg",
"br1520.flg",
"br1530.flg",
"br2000.flg",
"br2010.flg",
"br2040.flg",
"br2050.flg",
"br2060.flg",
"br206b.flg",
"br2070.flg",
"br3000.flg",
"br300b.flg",
"br3100.flg",
"bt050b.flg",
"bt0600.flg",
"bt0610.flg",
"bt0620.flg",
"bt0630.flg",
"bt100b.flg",
"bt101b.flg",
"bt102b.flg",
"bt111b.flg",
"bt112b.flg",
"bt113b.flg",
"bt114b.flg",
"bt115b.flg",
"bt150b.flg",
"bt152b.flg",
"bt154b.flg",
"bt155b.flg",
"bt160b.flg",
"bt162b.flg",
"bt163b.flg",
"bt2500.flg",
"bt3000.flg",
"bttest01.flg",
"bttest02.flg",
"bttest03.flg"
-- --for Ao
-- "bc0100.flg",
-- "bc0200.flg",
-- "bc0300.flg",
-- "bc0400.flg",
-- "bc0520.flg",
-- "bc1000.flg",
-- "bc1100.flg",
-- "bc1200.flg",
-- "bc120b.flg",
-- "bc122b.flg",
-- "bc130b.flg",
-- "bc1400.flg",
-- "bc1460.flg",
-- "bc1470.flg",
-- "bc1510.flg",
-- "bc1520.flg",
-- "bc1530.flg",
-- "bc1540.flg",
-- "bc1550.flg",
-- "bc1560.flg",
-- "bc1600.flg",
-- "be4800.flg",
-- "bm0100.flg",
-- "bm0101.flg",
-- "bm0102.flg",
-- "bm0200.flg",
-- "bm0210.flg",
-- "bm0220.flg",
-- "bm0300.flg",
-- "bm0310.flg",
-- "bm0320.flg",
-- "bm1000.flg",
-- "bm1010.flg",
-- "bm1020.flg",
-- "bm1030.flg",
-- "bm1040.flg",
-- "bm1050.flg",
-- "bm1061.flg",
-- "bm1070.flg",
-- "bm1080.flg",
-- "bm2000.flg",
-- "bm2020.flg",
-- "bm2050.flg",
-- "bm2060.flg",
-- "bm2099.flg",
-- "bm4000.flg",
-- "bm4010.flg",
-- "bm4020.flg",
-- "bm4030.flg",
-- "bm4040.flg",
-- "bm4110.flg",
-- "bm4120.flg",
-- "bm4130.flg",
-- "bm4150.flg",
-- "bm4160.flg",
-- "bm4200.flg",
-- "bm4210.flg",
-- "bm4250.flg",
-- "bm9000.flg",
-- "bm9010.flg",
-- "bm9020.flg",
-- "bm9030.flg",
-- "bm9039.flg",
-- "bm9040.flg",
-- "bm9041.flg",
-- "bm9049.flg",
-- "bm9050.flg",
-- "bm9059.flg",
-- "bm9060.flg",
-- "bm9069.flg",
-- "bm9070.flg",
-- "bm9099.flg",
-- "br0000.flg",
-- "br0100.flg",
-- "br0200.flg",
-- "br1000.flg",
-- "br1060.flg",
-- "br1500.flg",
-- "br1510.flg",
-- "br1520.flg",
-- "br1530.flg",
-- "br1600.flg",
-- "br2000.flg",
-- "br2010.flg",
-- "br2040.flg",
-- "br2050.flg",
-- "br2060.flg",
-- "br2061.flg",
-- "br2070.flg",
-- "br2080.flg",
-- "br3000.flg",
-- "br3100.flg",
-- "br4000.flg",
-- "br4010.flg",
-- "br4020.flg",
-- "bt0000.flg",
-- "bt1010.flg",
-- "bt1020.flg",
-- "bt1030.flg",
-- "bt103b.flg",
-- "bt1110.flg",
-- "bt1300.flg",
-- "bt130b.flg",
-- "bt1310.flg",
-- "bt1320.flg",
-- "bt1400.flg",
-- "bt1410.flg",
-- "bt1420.flg",
-- "bt1430.flg",
-- "bt1450.flg",
-- "bt1510.flg",
-- "bt2030.flg",
-- "bt2500.flg",
-- "bt6000.flg",
-- "bt6010.flg",
-- "bt6020.flg",
-- "bt6030.flg",
-- "btest.it3",
-- "btest.flg",
-- "ef_mwing.it3",
}
stdinoutcmd = (s, cmd) ->
ostr = ""
cb = (e, ee) ->
if e == "stdout"
ostr ..= ee
handle = proc.spawn(cmd, {stdin: true, stdout: true, callback:cb})
for a in s\gmatch'.'
handle\write(a)
handle\write(proc.EOF)
handle\wait()
return ostr
find_test = (s) ->
return stdinoutcmd("", "find /Volumes/Untitled/PSP_GAME/USRDIR/data -name " .. s)
d = fu.readfile arg[1]
-- print(arg[1] .. ":")
if #d < 16
os.exit()
i1, i2, i3, i4, b = up("I4I4I4I4", d)
if (i1 ~= i2) or (i1 ~= i3) or (i1 ~= i4)
os.exit()
--error("Not cclm archive")
cnt = i1
in_exception_filename = (s) ->
for i, v in pairs(exception_filename)
if s == v
return true
return false
fs = {}
for i = 1, cnt
if #d - b < 32
os.exit()
name, offset, size, unknown, __unused, b = up("c16I4I4I4I4", d, b)
if in_exception_filename((name\gsub("%z", "")))
table.insert(fs, {name, unknown, d\sub(offset + 1, offset + size)})
tothead = ""
hdroffs = 0
tothead ..= rp("I4I4I4I4", #fs, #fs, #fs, #fs)
hdroffs += 16
hdroffs += 32 * #fs
cont = ""
for i, v in pairs(fs)
tothead ..= rp("c16I4I4I4I4", v[1], hdroffs, #(v[3]), v[2], 0)
hdroffs += #(v[3])
cont ..= v[3]
fu.writefile(arg[1], tothead .. cont)
-- Better code have been released since then; see Trails Research Group: https://github.com/Trails-Research-Group
fu = require"file_util"
struct = require"struct"
proc = require"ipc.proc"
up = struct.unpack
rp = struct.pack
stdinoutcmd = (s, cmd) ->
ostr = ""
cb = (e, ee) ->
if e == "stdout"
ostr ..= ee
handle = proc.spawn(cmd, {stdin: true, stdout: true, callback:cb})
for a in s\gmatch'.'
handle\write(a)
handle\write(proc.EOF)
handle\wait()
return ostr
find_test = (s) ->
return stdinoutcmd("", "find /Volumes/Untitled/PSP_GAME/USRDIR -name " .. s)
d = fu.readfile arg[1]
-- print(arg[1] .. ":")
if #d < 16
os.exit()
i1, i2, i3, i4, b = up("I4I4I4I4", d)
if (i1 ~= i2) or (i1 ~= i3) or (i1 ~= i4)
os.exit()
--error("Not cclm archive")
cnt = i1
for i = 1, cnt
if #d - b < 32
os.exit()
name, offset, size, unknown, __unused, b = up("c16I4I4I4I4", d, b)
if #(find_test((name\gsub("%z", "")))) == 0
print((name\gsub("%z", "")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment