diff options
author | Pixel <pixel@nobis-crew.org> | 2013-06-22 19:16:59 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2013-06-22 19:16:59 -0700 |
commit | 476cf29aca86d8dbace2c4cab7db6a036404b679 (patch) | |
tree | 51f36596218206fc7d4e80120b439366935d730a /VP-miscwork.lua | |
parent | b8a9b4f9fa8a75c79ea7d9096e8f5d03514612e1 (diff) | |
parent | ad728683a0f8896508bcf24dadf9161b158573af (diff) |
Merge branch 'master' of ssh+git://git.grumpycoder.net/pub/repo.git/VP-hack
Diffstat (limited to 'VP-miscwork.lua')
-rw-r--r-- | VP-miscwork.lua | 185 |
1 files changed, 182 insertions, 3 deletions
diff --git a/VP-miscwork.lua b/VP-miscwork.lua index 31f7e92..1a5bc14 100644 --- a/VP-miscwork.lua +++ b/VP-miscwork.lua @@ -31,11 +31,54 @@ function process_arcgfx(fname, h, size, ext) index[i].size = h:readU32() end - local tell local outfile = {} + local script = nil + local font = nil for i = 1, nfiles do - tell = h:tell() - outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].extra), h, index[i].size, ext) + 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 @@ -57,3 +100,139 @@ function process_arcgfx(fname, h, size, ext) -- return ret end +function process_cscript(fname, h, size, ext) + log("Processing " .. fname .. ".slz") + log("Extracting " .. fname .. " - format 'cscript'") + local counter = 1 + local script + local font + local handler = function(fname, h, size, ext) + if counter == 1 then + log "taking script" + script = Buffer(true) + script:copyfrom(h) + elseif counter == 2 then + log "taking font" + font = Buffer(true) + font:copyfrom(h) + else + error "Too many files" + end + counter = counter + 1 + end + + process_single_file(fname, h, h:getsize(), ext, handler) + + if not script or not font then error "Not enough files" end + if dump_mode then + extract_simple_script(fname, script, font) + end + script:destroy() + font:destroy() +end + +function process_carc(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 'carc'") + dump_mkdir(fname) + local nfiles = h:readU32() + local ret + if not dump_mode then + ret = Buffer(true) + ret:writeU32(nfiles) + end + + local index = {} + for i = 1, nfiles do + index[i] = {} + local offset = h:readU32() + index[i].extra = shr(offset, 24) + index[i].offset = andB(offset, 0xffffff) + end + + index[nfiles + 1] = {} + index[nfiles + 1].extra = 0 + index[nfiles + 1].offset = size + + local outfile = {} + local script = nil + local font = nil + for i = 1, nfiles do + local tell = h:tell() + local handler = nil + local counter = 1 + if index[i].extra == 3 then + handler = function(fname, h, size, ext) + if counter ~= 1 then error "Too many files" end + counter = counter + 1 + return process_carc(fname, h, size, ext) + end + elseif dump_mode and index[i].extra == 2 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 index[i].extra == 1 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 index[i].extra == 2 then + error "Not written yet" + elseif not dump_mode and index[i].extra == 1 then + error "Not written yet" + end + local fsize = index[i + 1].offset - index[i].offset + outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].extra), h, fsize, ext, handler) + + if handler and script and font then + if dump_mode then + second_style_script = true + extract_simple_script(fname .. string.format("/%04i", i), script, font) + second_style_script = false + end + script:destroy() + font:destroy() + script = nil + font = nil + end + h:seek(tell + fsize) + 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 |