From e9f6873c0ebaa4ecfd368a4b3a932f3a63ba374a Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 25 Oct 2012 01:45:53 -0700 Subject: Adding preliminary work on non-room scripts (menus ?) --- VP-map.lua | 1 + VP-roomwork.lua | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/VP-map.lua b/VP-map.lua index df096b9..e3fa3c2 100644 --- a/VP-map.lua +++ b/VP-map.lua @@ -66,6 +66,7 @@ VP_map = { [ 3] = { dir = "MISC", ext = "txt" }, [ 4] = { dir = "MAIN/SOUNDS", ext = "wag" }, [ 5] = { dir = "MAIN/GFX" }, + [ 6] = { dir = "MAIN/MISC", ext = "main", ftype = "arcroom" }, [ 618] = { dir = "SOUNDS/MISC", ext = "wag" }, [1021] = { dir = "SOUNDS/MISC", ext = "wag" }, diff --git a/VP-roomwork.lua b/VP-roomwork.lua index d1eabfe..ac0a958 100644 --- a/VP-roomwork.lua +++ b/VP-roomwork.lua @@ -120,7 +120,7 @@ function process_arcroom(fname, h, size, ext) o:destroy() h:seek(-size, SEEK_CUR) end - log("Processing " .. fname .. " - format 'arcroom'") + log("Processing " .. fname .. " - format 'arcroom' - " .. ext) dump_mkdir(fname) local nfiles = h:readU32() @@ -157,23 +157,23 @@ function process_arcroom(fname, h, size, ext) tell = h:tell() local handler = nil local counter = 1 - if dump_mode and index[i].ftype == 4 then + if dump_mode and ext == "room" and index[i].ftype == 4 then log("Preparing to dump script...") - script = Buffer(true) - font = Buffer(true) 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 - elseif index[i].ftype == 4 and script and font then + elseif not dump_mode and ext == "room" and index[i].ftype == 4 and script and font then old_script = Buffer(true) handler = function(fname, h, size, ext) local ret @@ -190,15 +190,46 @@ function process_arcroom(fname, h, size, ext) counter = counter + 1 return ret end + elseif dump_mode and ext == "main" and index[i].ftype == 4 then + if script then error "Can't have two scripts in these..." end + handler = function(fname, h, size, ext) + if counter == 1 then + log("Taking text...") + script = Buffer(true) + script:copyfrom(h) + else + error("Too many files") + end + counter = counter + 1 + end + elseif dump_mode and ext == "main" and index[i].ftype == 7 then + if font then error "Can't have two fonts in these..." 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 ext == "main" and index[i].ftype == 4 then + error "Not written yet" + elseif not dump_mode and ext == "main" and index[i].ftype == 7 then + error "Not written yet" end outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].ftype), h, index[i].size, "room", handler) - if handler then - if counter ~= 3 then error("Didn't get enough files; got " .. (counter - 1) .. " instead of 2.") end - if dump_mode then + if handler and script and font then + if dump_mode and counter == 3 then extract_room_script(fname .. string.format("/%04i", i), script, font) + else + 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 @@ -497,3 +528,55 @@ function extract_room_script(fname, script, font) o:destroy() end + +function extract_simple_script(fname, script, font) + log("Processing script " .. fname) + dump_mkdir(fname) + local font = extract_font(fname .. "/FONT", font) + local lookup = resolve_font(font) + local n_ptrs = 1 + local script_begin = script:readU32() + + local ptrs = {} + local unks = {} + local ptr_start = 1 + local tell = script:tell() + + while tell < script_begin do + unks[n_ptrs] = script:readU32() + ptrs[n_ptrs] = script:readU32() + tell = script:tell() + n_ptrs = n_ptrs + 1 + end + ptrs[n_ptrs] = script:getsize() - script_begin + n_ptrs = n_ptrs - 1 + + local ptrs_contents, ptrs_raws = {}, {} + ptr_start = 1 + for i = ptr_start, n_ptrs do + ptrs_contents[i] = "" + ptrs_raws[i] = "" + +-- if tell + ptrs[i] ~= script:tell() then print("Script consistancy failure for pointer " .. i .. " - we're at " .. script:tell() .. " and " .. (tell + ptrs[i]) .. " was expected.") end + + script:seek(script_begin + ptrs[i]) + while script:tell() ~= (script_begin + ptrs[i + 1]) do + local r, rr = extract_char(script, lookup) + if r then + ptrs_contents[i] = ptrs_contents[i] .. r + ptrs_raws[i] = ptrs_raws[i] .. rr + elseif script:tell() ~= (script_begin + ptrs[i + 1]) then + ptrs_contents[i] = ptrs_contents[i] .. "" + end + end + end + + local o = Output(fname .. "-script.txt") + for i = ptr_start, n_ptrs do + o:write("\n") + o:write(ptrs_contents[i]) + o:write("\n") + end + + o:destroy() +end -- cgit v1.2.3 From 911936a303001d2fb2f2e94c7228374656d1b88b Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 25 Oct 2012 09:32:15 -0700 Subject: A bit more on the menus. --- VP-map.lua | 7 ++++++- VP-roomwork.lua | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/VP-map.lua b/VP-map.lua index e3fa3c2..f18249a 100644 --- a/VP-map.lua +++ b/VP-map.lua @@ -49,6 +49,9 @@ VP_map_spans = { { idx_s = 2096, idx_e = 2097, data = { dir = "SOUNDS/UNKNOWN03", ext = "wag", }, }, { idx_s = 2098, idx_e = 2172, data = { dir = "SOUNDS/VICTORY", ext = "wag", }, }, + + { idx_s = 2175, idx_e = 2186, data = { dir = "MISC/MENUS", ext = "sarc", ftype = "arcroom", }, }, + { idx_s = 2187, idx_e = 2211, data = { dir = "GFX/STATUSPIC" }, }, { idx_s = 2296, idx_e = 2319, data = { dir = "GFX/UNKNOWN06" }, }, { idx_s = 3299, idx_e = 3505, data = { dir = "GFX/FACE" }, }, @@ -66,7 +69,7 @@ VP_map = { [ 3] = { dir = "MISC", ext = "txt" }, [ 4] = { dir = "MAIN/SOUNDS", ext = "wag" }, [ 5] = { dir = "MAIN/GFX" }, - [ 6] = { dir = "MAIN/MISC", ext = "main", ftype = "arcroom" }, + [ 6] = { dir = "MAIN/MISC", ext = "sarc", ftype = "arcroom" }, [ 618] = { dir = "SOUNDS/MISC", ext = "wag" }, [1021] = { dir = "SOUNDS/MISC", ext = "wag" }, @@ -88,6 +91,8 @@ VP_map = { [1983] = { dir = "GFX/MAGIC12", ext = "agx", ftype = "arcgfx", }, [1986] = { dir = "GFX/MAGIC13", ext = "agx", ftype = "arcgfx", }, + [2173] = { dir = "MISC/GFX", ext = "agx", ftype = "arcgfx", }, + -- -- Videos -- diff --git a/VP-roomwork.lua b/VP-roomwork.lua index ac0a958..4349ca4 100644 --- a/VP-roomwork.lua +++ b/VP-roomwork.lua @@ -190,7 +190,7 @@ function process_arcroom(fname, h, size, ext) counter = counter + 1 return ret end - elseif dump_mode and ext == "main" and index[i].ftype == 4 then + elseif dump_mode and ext == "sarc" and index[i].ftype == 4 then if script then error "Can't have two scripts in these..." end handler = function(fname, h, size, ext) if counter == 1 then @@ -202,7 +202,7 @@ function process_arcroom(fname, h, size, ext) end counter = counter + 1 end - elseif dump_mode and ext == "main" and index[i].ftype == 7 then + elseif dump_mode and ext == "sarc" and index[i].ftype == 7 then if font then error "Can't have two fonts in these..." end handler = function(fname, h, size, ext) if counter == 1 then @@ -214,9 +214,9 @@ function process_arcroom(fname, h, size, ext) end counter = counter + 1 end - elseif not dump_mode and ext == "main" and index[i].ftype == 4 then + elseif not dump_mode and ext == "sarc" and index[i].ftype == 4 then error "Not written yet" - elseif not dump_mode and ext == "main" and index[i].ftype == 7 then + elseif not dump_mode and ext == "sarc" and index[i].ftype == 7 then error "Not written yet" end outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].ftype), h, index[i].size, "room", handler) -- cgit v1.2.3 From d17ccb1258c40fbd6767c4e2c98b6e2462cb8987 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 25 Oct 2012 21:15:03 -0700 Subject: More scripts types. --- VP-miscwork.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- VP-roomwork.lua | 2 +- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/VP-miscwork.lua b/VP-miscwork.lua index 31f7e92..cb111f3 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 diff --git a/VP-roomwork.lua b/VP-roomwork.lua index 4349ca4..b4724f4 100644 --- a/VP-roomwork.lua +++ b/VP-roomwork.lua @@ -223,7 +223,7 @@ function process_arcroom(fname, h, size, ext) if handler and script and font then if dump_mode and counter == 3 then extract_room_script(fname .. string.format("/%04i", i), script, font) - else + elseif dump_mode then extract_simple_script(fname .. string.format("/%04i", i), script, font) end script:destroy() -- cgit v1.2.3 From 6f37a8a7c34fbbfa62df139bfc904288e319d140 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 26 Oct 2012 09:06:13 -0700 Subject: And still more script types. --- VP-map.lua | 3 +++ VP-miscwork.lua | 30 ++++++++++++++++++++++++++++++ VP-process.lua | 12 +++++------- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/VP-map.lua b/VP-map.lua index f18249a..795e2e7 100644 --- a/VP-map.lua +++ b/VP-map.lua @@ -4,6 +4,7 @@ VP_maintypes = { "GFX", "MAIN", "GAME", + "MISC", } VP_map = { } @@ -93,6 +94,8 @@ VP_map = { [2173] = { dir = "MISC/GFX", ext = "agx", ftype = "arcgfx", }, + [2294] = { dir = "MISC/SCRIPT", ext = "script", ftype = "cscript", }, + -- -- Videos -- diff --git a/VP-miscwork.lua b/VP-miscwork.lua index cb111f3..1818b30 100644 --- a/VP-miscwork.lua +++ b/VP-miscwork.lua @@ -100,3 +100,33 @@ 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 diff --git a/VP-process.lua b/VP-process.lua index c85cfc5..2861d4e 100644 --- a/VP-process.lua +++ b/VP-process.lua @@ -239,14 +239,12 @@ function process_files(index, map, iso, iso_full, cindex, index_add, jp_in_us) log("JP-in-US: replacing file " .. i .. " by file " .. lookup) file_out = index_add[lookup].cd:cdfile(index_add[lookup].sector, index_add[lookup].size * sec_sizes[mode]) end - elseif not ftype then - file_out = process_single_file("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext) - elseif ftype == "arcgfx" then - file_out = process_arcgfx("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext) - elseif ftype == "arcroom" then - file_out = process_arcroom("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext) + elseif ftype then + local handler = _G["process_" .. ftype] + if not handler then error("Unknown ftype: " .. ftype) end + file_out = handler("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext) else - error("Unknow ftype: " .. ftype) + file_out = process_single_file("DUMP/" .. dir .. string.format("/%04i", i), file_in, file_in:getsize(), ext) end if not file_out then file_out = file_in end file_in:seek(0) -- cgit v1.2.3 From d8321af9f135590e303ea6d5f08253f432eaa726 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 26 Oct 2012 09:33:27 -0700 Subject: Small tweaks for yet another kind of script. --- VP-map.lua | 2 ++ VP-roomwork.lua | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/VP-map.lua b/VP-map.lua index 795e2e7..334f7c7 100644 --- a/VP-map.lua +++ b/VP-map.lua @@ -96,6 +96,8 @@ VP_map = { [2294] = { dir = "MISC/SCRIPT", ext = "script", ftype = "cscript", }, + [4734] = { dir = "MISC/SCRIPT", ext = "sarc", ftype = "arcroom", }, + -- -- Videos -- diff --git a/VP-roomwork.lua b/VP-roomwork.lua index b4724f4..6aacfcf 100644 --- a/VP-roomwork.lua +++ b/VP-roomwork.lua @@ -191,12 +191,17 @@ function process_arcroom(fname, h, size, ext) return ret end elseif dump_mode and ext == "sarc" and index[i].ftype == 4 then - if script then error "Can't have two scripts in these..." end handler = function(fname, h, size, ext) if counter == 1 then + if script then error "Can't have two scripts in these..." end log("Taking text...") script = Buffer(true) script:copyfrom(h) + elseif counter == 2 then + if font then error "Can't have two fonts in these..." end + log("Taking font...") + font = Buffer(true) + font:copyfrom(h) else error("Too many files") end @@ -221,7 +226,7 @@ function process_arcroom(fname, h, size, ext) end outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].ftype), h, index[i].size, "room", handler) if handler and script and font then - if dump_mode and counter == 3 then + if dump_mode and ext == "room" then extract_room_script(fname .. string.format("/%04i", i), script, font) elseif dump_mode then extract_simple_script(fname .. string.format("/%04i", i), script, font) -- cgit v1.2.3 From eaadfce496989ff703ea864b66d615253bae9f8c Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 26 Oct 2012 20:34:02 -0700 Subject: Fixing my previous commit, restoring the room system. --- VP-roomwork.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VP-roomwork.lua b/VP-roomwork.lua index 6aacfcf..9bb590b 100644 --- a/VP-roomwork.lua +++ b/VP-roomwork.lua @@ -157,7 +157,7 @@ function process_arcroom(fname, h, size, ext) tell = h:tell() local handler = nil local counter = 1 - if dump_mode and ext == "room" and index[i].ftype == 4 then + if dump_mode and ext == "arm" and index[i].ftype == 4 then log("Preparing to dump script...") handler = function(fname, h, size, ext) if counter == 1 then @@ -173,7 +173,7 @@ function process_arcroom(fname, h, size, ext) end counter = counter + 1 end - elseif not dump_mode and ext == "room" and index[i].ftype == 4 and script and font then + elseif not dump_mode and ext == "arm" and index[i].ftype == 4 and script and font then old_script = Buffer(true) handler = function(fname, h, size, ext) local ret @@ -226,7 +226,7 @@ function process_arcroom(fname, h, size, ext) end outfile[i] = process_single_file(fname .. string.format("/%04i-%08X", i, index[i].ftype), h, index[i].size, "room", handler) if handler and script and font then - if dump_mode and ext == "room" then + if dump_mode and ext == "arm" then extract_room_script(fname .. string.format("/%04i", i), script, font) elseif dump_mode then extract_simple_script(fname .. string.format("/%04i", i), script, font) -- cgit v1.2.3 From 17c81623a7845c47d29cd29b80edb6a8200ecae1 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 26 Oct 2012 20:33:39 -0700 Subject: Adding one more script type; one with a brand new action table. --- VP-map.lua | 5 +++ VP-miscwork.lua | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ VP-textwork.lua | 38 +++++++++++++++++--- 3 files changed, 145 insertions(+), 4 deletions(-) diff --git a/VP-map.lua b/VP-map.lua index 334f7c7..54a382e 100644 --- a/VP-map.lua +++ b/VP-map.lua @@ -98,6 +98,11 @@ VP_map = { [4734] = { dir = "MISC/SCRIPT", ext = "sarc", ftype = "arcroom", }, + [4797] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", }, + [4798] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", }, + [4799] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", }, + [4807] = { dir = "MISC/UNKNOWN", ext = "carc", ftype = "carc", }, + -- -- Videos -- diff --git a/VP-miscwork.lua b/VP-miscwork.lua index 1818b30..1a5bc14 100644 --- a/VP-miscwork.lua +++ b/VP-miscwork.lua @@ -130,3 +130,109 @@ function process_cscript(fname, h, size, ext) 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 diff --git a/VP-textwork.lua b/VP-textwork.lua index 2d3f56c..c7bc9af 100644 --- a/VP-textwork.lua +++ b/VP-textwork.lua @@ -1,3 +1,9 @@ +function get_next_char(script) + local c = script:readU8() + if c >= 0x80 then c = (c - 0x80) + (script:readU8() * 128) end + return c +end + function get_next_utf8(str) local ret = "" local n @@ -86,14 +92,38 @@ function dump_special(script, code) error "Should not end up there" end +function dump_special2(script, code) + if code == 0 then + return "\n", "\n" + elseif code == 1 then + return "\n\n", "\n" + else + local a1, a2 + if code == 3 or code == 5 or code == 7 or code == 8 or code == 9 or code == 12 or code == 13 or code == 14 or code == 15 or code == 21 then + a1 = script:readU8() + return '', "" + elseif code == 20 then + a1 = script:readU8() + a2 = script:readU8() + return '', "" + else + return '', "" + end + end + error "Should not end up there" +end + function extract_char(script, lookup) - local - c = script:readU8() + local c = get_next_char(script) if c == 0 then return nil end - if c >= 0x80 then c = (c - 0x80) + (script:readU8() * 128) end if c >= 0x4000 then - return dump_special(script, c - 0x4000) + local code = c - 0x4000 + if second_style_script then + return dump_special2(script, code) + else + return dump_special(script, code) + end else local l = lookup[c] if not l and not sloppy_extract then error("Lookup failed for character " .. c) end -- cgit v1.2.3 From ec1a0172cc4afc937e0e4e9ac8b1b59ff563954f Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 14:24:54 -0700 Subject: Adding tag 'pause'. --- VP-textwork.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/VP-textwork.lua b/VP-textwork.lua index c7bc9af..453d4f8 100644 --- a/VP-textwork.lua +++ b/VP-textwork.lua @@ -40,6 +40,8 @@ function dump_special(script, code) return "\n", "\n" elseif code == 1 then return "\n\n", "\n" + elseif code == 2 then + return "", "" elseif code == 3 then local speed = script:readU8() if speed == 255 then @@ -97,6 +99,8 @@ function dump_special2(script, code) return "\n", "\n" elseif code == 1 then return "\n\n", "\n" + elseif code == 2 then + return "", "" else local a1, a2 if code == 3 or code == 5 or code == 7 or code == 8 or code == 9 or code == 12 or code == 13 or code == 14 or code == 15 or code == 21 then -- cgit v1.2.3 From 1845b90ac8e54ea6f4c6dd22a0278d70c2956db0 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 15:14:36 -0700 Subject: Adding a few more tags. --- VP-textwork.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/VP-textwork.lua b/VP-textwork.lua index 453d4f8..6b8ca6b 100644 --- a/VP-textwork.lua +++ b/VP-textwork.lua @@ -49,6 +49,8 @@ function dump_special(script, code) else return '', "" end + elseif code == 4 then + return '', "" elseif code == 5 then return '', "" elseif code == 7 then @@ -65,6 +67,15 @@ function dump_special(script, code) else return '', "" end + elseif code == 14 then + return '', "" + elseif code == 17 then + local t, u + t = script:readU8() + u = script:readU8() + return '', "" + elseif code == 18 then + return "", "" elseif code == 19 then local arg1, arg2 arg1 = script:readU8() @@ -74,16 +85,12 @@ function dump_special(script, code) else return '', "" end - elseif code == 14 then - return '', "" - elseif code == 4 then - return '', "" else local a1, a2 if code == 3 or code == 4 or code == 7 or code == 8 or code == 14 then a1 = script:readU8() return '', "" - elseif code == 6 or code == 12 or code == 17 or code == 19 then + elseif code == 6 or code == 12 or code == 19 then a1 = script:readU8() a2 = script:readU8() return '', "" -- cgit v1.2.3 From 8fa0f9de66fdb283ed9f74aabfca03f7844b4c3d Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 22:25:38 -0700 Subject: Making some tags a bit smarter. --- VP-textwork.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/VP-textwork.lua b/VP-textwork.lua index 6b8ca6b..acc196e 100644 --- a/VP-textwork.lua +++ b/VP-textwork.lua @@ -73,7 +73,13 @@ function dump_special(script, code) local t, u t = script:readU8() u = script:readU8() - return '', "" + if u == 0 then + return '', "" + elseif u == 1 then + return '', "" + else + return '', "" + end elseif code == 18 then return "", "" elseif code == 19 then -- cgit v1.2.3 From 74ffe8d105c70e0e205cccba360f832d83b4abda Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 22:32:50 -0700 Subject: Removing tabs. --- compil.lex | 190 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/compil.lex b/compil.lex index ad24a2c..504eaaf 100644 --- a/compil.lex +++ b/compil.lex @@ -23,181 +23,181 @@ %% "" { - fprintf(yyout, "rooms_txts = {\n"); - BEGIN(I); + fprintf(yyout, "rooms_txts = {\n"); + BEGIN(I); } -.* { - fprintf(stderr, "Invalid file, must begin with \n"); - errstate = 1; +.* { + fprintf(stderr, "Invalid file, must begin with \n"); + errstate = 1; } -"\n\n\n" { - int d = atoi(yytext + 10); - if (got_ptr) { - fprintf(yyout, "\x5d\x5d },\n"); - } - fprintf(yyout, " [%i] = { \x5b\x5b", d); - got_ptr = 1; +"\n\n\n" { + int d = atoi(yytext + 10); + if (got_ptr) { + fprintf(yyout, "\x5d\x5d },\n"); + } + fprintf(yyout, " [%i] = { \x5b\x5b", d); + got_ptr = 1; } -"\n\n" { - putcode(1); +"\n\n" { + putcode(1); } -"" { - putcode1(3, 255); +"" { + putcode1(3, 255); } -"" { - int d = atoi(yytext + 9); - putcode1(3, d); +"" { + int d = atoi(yytext + 9); + putcode1(3, d); } -"" { - int d = atoi(yytext + 9); - putcode1(4, d); +"" { + int d = atoi(yytext + 9); + putcode1(4, d); } -"" { - putcode(5); +"" { + putcode(5); } -"" { - putcode1(7, 1); +"" { + putcode1(7, 1); } -"" { - int d = atoi(yytext + 9); - putcode1(7, d); +"" { + int d = atoi(yytext + 9); + putcode1(7, d); } -"" { - putcode1(8, 1); +"" { + putcode1(8, 1); } -"" { - int d = atoi(yytext + 9); - putcode1(8, d); +"" { + int d = atoi(yytext + 9); + putcode1(8, d); } -"" { - putcode2(19, 255, 255); +"" { + putcode2(19, 255, 255); } -"""a2=\""[[:digit:]]+"\"/>" { - int d = atoi(yytext + 4); - putcode2(19, arg1, d); - BEGIN(I); +

"a2=\""[[:digit:]]+"\"/>" { + int d = atoi(yytext + 4); + putcode2(19, arg1, d); + BEGIN(I); } -"" { - int d = atoi(yytext + 8); - putcode1(14, d); +"" { + int d = atoi(yytext + 8); + putcode1(14, d); } -"" { - int d = atoi(yytext + 7); - putcode(d); +"" { + int d = atoi(yytext + 7); + putcode(d); } -"""a1=\""[[:digit:]]+"\"/>" { - int d = atoi(yytext + 4); - putcode1(cmd, d); - BEGIN(I); +"a1=\""[[:digit:]]+"\"/>" { + int d = atoi(yytext + 4); + putcode1(cmd, d); + BEGIN(I); } -"""a1=\""[[:digit:]]+"\" " { - arg1 = atoi(yytext + 4); - BEGIN(U22); +"a1=\""[[:digit:]]+"\" " { + arg1 = atoi(yytext + 4); + BEGIN(U22); } -"a2=\""[[:digit:]]+"\"/>" { - int d = atoi(yytext + 4); - putcode2(cmd, arg1, d); - BEGIN(I); +"a2=\""[[:digit:]]+"\"/>" { + int d = atoi(yytext + 4); + putcode2(cmd, arg1, d); + BEGIN(I); } -"\n" { - putcode(0); +"\n" { + putcode(0); } -"\n" { - fprintf(yyout, "\x5d\x5d}\n}\n"); - BEGIN(E); +"\n" { + fprintf(yyout, "\x5d\x5d}\n}\n"); + BEGIN(E); } -"abcdef<"[^\>\n]*"/>" { - yytext[strlen(yytext) - 2] = 0; - fprintf(stderr, "Error: Invalid command: '%s'\n", yytext + 1); - errstate = 1; +"abcdef<"[^\>\n]*"/>" { + yytext[strlen(yytext) - 2] = 0; + fprintf(stderr, "Error: Invalid command: '%s'\n", yytext + 1); + errstate = 1; } -. { - fputc(*yytext, yyout); +. { + fputc(*yytext, yyout); } -. { - fprintf(stderr, "Hu uh, something's wrong...\n"); +. { + fprintf(stderr, "Hu uh, something's wrong...\n"); } %% -int yywrap(void) { +int yywrap(void) { exit(errstate ? -1 : 0); } -int main(int argc, char ** argv) { +int main(int argc, char ** argv) { if ((argc < 2) || (argc > 3)) { - fprintf(stderr, "Usage: %s [input]\n", argv[0]); - exit(-1); + fprintf(stderr, "Usage: %s [input]\n", argv[0]); + exit(-1); } if (!(yyout = fopen(argv[1], "wb"))) { - fprintf(stderr, "Error: can't open file %s\n", argv[1]); - exit(-1); + fprintf(stderr, "Error: can't open file %s\n", argv[1]); + exit(-1); } if (argc == 3) { - if (!(yyin = fopen(argv[2], "rb"))) { - fprintf(stderr, "Error: can't open file %s\n", argv[2]); - exit(-1); - } + if (!(yyin = fopen(argv[2], "rb"))) { + fprintf(stderr, "Error: can't open file %s\n", argv[2]); + exit(-1); + } } fprintf(stderr, "Creating file %s\n", argv[1]); yylex(); exit(errstate ? -1 : 0); } -void unputs(char * s) { +void unputs(char * s) { int l = strlen(s), i; - + for (i = l - 1; i >= 0; i--) { - unput(s[i]); + unput(s[i]); } } -void putcode(int code) { +void putcode(int code) { fprintf(yyout, "\x5d\x5d, { %i }, \x5b\x5b", code); } -void putcode1(int code, int arg) { +void putcode1(int code, int arg) { fprintf(yyout, "\x5d\x5d, { %i, %i }, \x5b\x5b", code, arg); } -void putcode2(int code, int arg1, int arg2) { +void putcode2(int code, int arg1, int arg2) { fprintf(yyout, "\x5d\x5d, { %i, %i, %i }, \x5b\x5b", code, arg1, arg2); } -- cgit v1.2.3 From f37bccb877d23a3094e7b98f2742ed66fcdb00b6 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 22:52:35 -0700 Subject: Adding unknown tag support to the script compiler. --- compil.lex | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/compil.lex b/compil.lex index 504eaaf..1bac4f2 100644 --- a/compil.lex +++ b/compil.lex @@ -20,6 +20,13 @@ int errstate = 0; int got_ptr = 0; + const int max_tagsize = 64; + + char unknown_tag[65]; + char * unknown_tag_ptr; + + int in_unknown_tag = 0; + %% "" { @@ -149,6 +156,19 @@ } . { + if (*yytext == '<') { + in_unknown_tag = 1; + unknown_tag_ptr = unknown_tag; + } else if (*yytext == '>') { + *unknown_tag_ptr = 0; + fprintf(stderr, "Got an unknown tag: %s\n", unknown_tag); + in_unknown_tag = 0; + } else if (in_unknown_tag) { + *unknown_tag_ptr++ = *yytext; + if ((unknown_tag_ptr - unknown_tag) == max_tagsize) { + in_unknown_tag = 0; + } + } fputc(*yytext, yyout); } -- cgit v1.2.3 From 2365582733668c3018ee2b04a7cd27e57e3cc550 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 23:41:19 -0700 Subject: Fixing the delay tags. --- VP-textwork.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VP-textwork.lua b/VP-textwork.lua index acc196e..c3312f7 100644 --- a/VP-textwork.lua +++ b/VP-textwork.lua @@ -74,11 +74,11 @@ function dump_special(script, code) t = script:readU8() u = script:readU8() if u == 0 then - return '', "" + return '', "" elseif u == 1 then - return '', "" + return '', "" else - return '', "" + return '', "" end elseif code == 18 then return "", "" -- cgit v1.2.3 From 0fbf22d5fe5b7e07377ee9f133ab812e1a1fbdac Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 23:44:09 -0700 Subject: Adding the new tags in the compilation code. --- compil.lex | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/compil.lex b/compil.lex index 1bac4f2..b8cf4f0 100644 --- a/compil.lex +++ b/compil.lex @@ -3,6 +3,8 @@ %s I /* In port block */ %s P + /* In delay block */ +%s D /* In unknown 1 block */ %s U1 /* In unknown 2 block, arg1 */ @@ -97,6 +99,31 @@ BEGIN(P); } +"" { + putcode(18); + } + +""u=\""[[:digit:]]+"\"/>" { + int d = atoi(yytext + 3); + putcode2(17, d, arg1); + BEGIN(I); + } + +"" { + int t = atoi(yytext + 11); + putcode2(17, t, 0); + } + +"" { + int t = atoi(yytext + 11); + putcode2(17, t, 1); + } +

"a2=\""[[:digit:]]+"\"/>" { int d = atoi(yytext + 4); putcode2(19, arg1, d); -- cgit v1.2.3 From 6c1e07f91277d4ec5e2677707d96d1fd2641753c Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 28 Oct 2012 23:53:12 -0700 Subject: Removing useless check. --- compil.lex | 6 ------ 1 file changed, 6 deletions(-) diff --git a/compil.lex b/compil.lex index b8cf4f0..960cab9 100644 --- a/compil.lex +++ b/compil.lex @@ -176,12 +176,6 @@ BEGIN(E); } -"abcdef<"[^\>\n]*"/>" { - yytext[strlen(yytext) - 2] = 0; - fprintf(stderr, "Error: Invalid command: '%s'\n", yytext + 1); - errstate = 1; - } - . { if (*yytext == '<') { in_unknown_tag = 1; -- cgit v1.2.3 From 9eede342a1046ce8e26c87495737585d042add19 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 29 Oct 2012 00:55:15 -0700 Subject: First step in getting the windows re-inserted properly: parsing them and transforming them into Lua code. --- compil.lex | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 6 deletions(-) diff --git a/compil.lex b/compil.lex index 960cab9..d75f157 100644 --- a/compil.lex +++ b/compil.lex @@ -1,4 +1,12 @@ #include + /* Waiting for Window */ +%s WW + /* Waiting for Window Y */ +%s WWY + /* Waiting for Window W */ +%s WWW + /* Waiting for Window H */ +%s WWH /* In text block */ %s I /* In port block */ @@ -21,14 +29,21 @@ int arg1 = 0; int errstate = 0; int got_ptr = 0; + int current_ptr = 0; const int max_tagsize = 64; char unknown_tag[65]; - char * unknown_tag_ptr; + char * unknown_tag_ptr = unknown_tag; int in_unknown_tag = 0; + struct window { + int t, x, y, w, h; + }; + + struct window windows[8192]; + %% "" { @@ -42,12 +57,54 @@ } "\n\n\n" { - int d = atoi(yytext + 10); + current_ptr = atoi(yytext + 10); if (got_ptr) { fprintf(yyout, "\x5d\x5d },\n"); } - fprintf(yyout, " [%i] = { \x5b\x5b", d); + fprintf(yyout, " [%i] = { \x5b\x5b", current_ptr); got_ptr = 1; + BEGIN(WW); + } + +"\n" { + BEGIN(I); + } + +"\n" { + windows[current_ptr].t = 3; + BEGIN(I); + } + +"""y=\""[[:digit:]]+"\" " { + int d = atoi(yytext + 3); + windows[current_ptr].y = d; + BEGIN(WWW); + } + +"width=\""[[:digit:]]+"\" " { + int d = atoi(yytext + 7); + windows[current_ptr].w = d; + BEGIN(WWH); + } + +"height=\""[[:digit:]]+"\"/>" { + int d = atoi(yytext + 8); + windows[current_ptr].h = d; + BEGIN(I); } "\n\n" { @@ -172,7 +229,22 @@ } "\n" { - fprintf(yyout, "\x5d\x5d}\n}\n"); + int i; + fprintf(yyout, "\x5d\x5d}\n}\n\nwindows_data = {\n"); + for (i = 0; i < 8192; i++) { + switch (windows[i].t) { + case 1: + fprintf(yyout, " [%i] = { x = \"%i\", y = \"%i\", width = \"%i\", height = \"%i\" },\n", i, windows[i].x, windows[i].y, windows[i].w, windows[i].h); + break; + case 2: + fprintf(yyout, " [%i] = { x = \"var\", y = \"%i\", width = \"%i\", height = \"%i\" },\n", i, windows[i].y, windows[i].w, windows[i].h); + break; + case 3: + fprintf(yyout, " [%i] = { wtype = \"fixed\" },\n", current_ptr); + break; + } + } + fprintf(yyout, "}\n"); BEGIN(E); } @@ -180,7 +252,7 @@ if (*yytext == '<') { in_unknown_tag = 1; unknown_tag_ptr = unknown_tag; - } else if (*yytext == '>') { + } else if ((*yytext == '>') && in_unknown_tag) { *unknown_tag_ptr = 0; fprintf(stderr, "Got an unknown tag: %s\n", unknown_tag); in_unknown_tag = 0; @@ -194,7 +266,7 @@ } . { - fprintf(stderr, "Hu uh, something's wrong...\n"); + fprintf(stderr, "Hu uh, something's wrong... unexpected %s\n", yytext); } %% @@ -218,6 +290,7 @@ int main(int argc, char ** argv) { exit(-1); } } + memset(windows, 0, sizeof(windows)); fprintf(stderr, "Creating file %s\n", argv[1]); yylex(); exit(errstate ? -1 : 0); -- cgit v1.2.3 From ad728683a0f8896508bcf24dadf9161b158573af Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 29 Oct 2012 01:00:19 -0700 Subject: Oops. --- compil.lex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compil.lex b/compil.lex index d75f157..36db5c5 100644 --- a/compil.lex +++ b/compil.lex @@ -240,7 +240,7 @@ fprintf(yyout, " [%i] = { x = \"var\", y = \"%i\", width = \"%i\", height = \"%i\" },\n", i, windows[i].y, windows[i].w, windows[i].h); break; case 3: - fprintf(yyout, " [%i] = { wtype = \"fixed\" },\n", current_ptr); + fprintf(yyout, " [%i] = { wtype = \"fixed\" },\n", i); break; } } -- cgit v1.2.3