function process_arcgfx(fname, h, size, ext) log("Processing " .. fname .. "." .. ext) if dump_mode then o = Output(fname .. "." .. ext) o:copyfrom(h, size) o:destroy() h:seek(-size, SEEK_CUR) end log("Extracting " .. fname .. " - format 'arcgfx'") dump_mkdir(fname) local nfiles = h:readU32() local extra = h:readU32() local ret if dump_mode then o = Output(fname .. "/--extra.bin") o:writeU32(extra) o:destroy() o = Output(fname .. string.format("/0000-%08X", extra)) o:writeU32(extra) o:destroy() else ret = Buffer(true) ret:writeU32(nfiles) ret:writeU32(extra) end index = {} for i = 1, nfiles do index[i] = {} index[i].extra = h:readU32() index[i].size = h:readU32() end local outfile = {} local script = nil local font = nil for i = 1, nfiles do local tell = h:tell() local handler = nil local counter = 1 local f1 = andB(index[i].extra, 0xffffff00) if dump_mode and f1 == 0x00300900 then if script then error "Can't have two scripts" end handler = function(fname, h, size, ext) if counter == 1 then log "taking script" script = Buffer(true) script:copyfrom(h) else error "Too many files" end counter = counter + 1 end elseif dump_mode and f1 == 0x00300800 then if font then error "Can't have two fonts" end handler = function(fname, h, size, ext) if counter == 1 then log "taking font" font = Buffer(true) font:copyfrom(h) else error "Too many files" end counter = counter + 1 end elseif not dump_mode and f1 == 0x00300900 then error "Not written yet" elseif not dump_mode and f1 == 0x00300800 then error "Not written yet" end outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].extra), h, index[i].size, ext, handler) if handler and script and font then if dump_mode then extract_simple_script(fname .. string.format("/%04i", i), script, font) end script:destroy() font:destroy() script = nil font = nil end h:seek(tell + index[i].size) end if not dump_mode then for i = 1, nfiles do local alignment_bytes = alignment(outfile[i]:getsize(), 4) for j = 1, alignment_bytes do outfile[i]:writeU8(0) end ret:writeU32(index[i].extra) ret:writeU32(outfile[i]:getsize()) end for i = 1, nfiles do ret:copyfrom(outfile[i]) outfile[i]:destroy() end end -- return ret end