From 168fa7d9574a6cfbbc3bc0657e48a12e3c6e35fd Mon Sep 17 00:00:00 2001 From: trevor Date: Mon, 13 Dec 2021 22:05:44 -0500 Subject: [PATCH 1/6] Make it easy to get the dialog files. --- addons/libs/dialog.lua | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/addons/libs/dialog.lua b/addons/libs/dialog.lua index 01473c0e3..2cf28f244 100644 --- a/addons/libs/dialog.lua +++ b/addons/libs/dialog.lua @@ -186,6 +186,50 @@ end dialog.decode_string = dialog.encode_string +-- If a zone has a dialog message dat file, this function will +-- return a file descriptor for it in "read/binary" mode. +function dialog.dat(zone_id) + local dat_id + if zone_id < 256 then + dat_id = zone_id + 6420 + else + dat_id = zone_id + 85335 + end + + local dat_path = windower.ffxi_path + local path + local vtable = dat_path .. 'VTABLE.DAT' + local ftable = dat_path .. 'FTABLE.DAT' + local n = 1 + local rom = dat_path .. 'ROM/' + repeat + local f = io.open(vtable, 'rb') + f:seek('set', dat_id) + if byte(f:read(1)) > 0 then + local f = io.open(ftable, 'rb') + local dat = f:read('*a') + f:close() + + local offset = 2*dat_id+1 + local packed_16bit = byte(dat, offset + 1) * 256 + byte(dat, offset) + local dir = floor(packed_16bit / 128) + local file = packed_16bit - dir * 128 + + path = rom .. tostring(dir) .. '/' .. tostring(file) .. '.DAT' + end + f:close() + n = n + 1 + local d = tostring(n) + rom = dat_path .. 'ROM' .. d .. '/' + vtable = rom .. 'VTABLE' .. d .. '.DAT' + ftable = rom .. 'FTABLE' .. d .. '.DAT' + until path or not windower.dir_exists(rom) + + if path then + return io.open(path, 'rb') + end +end + dialog.dev = {} -- Returns the hex offset of the dialog entry with the given ID. From b4d33cf70ddc28174217132f6d55e27f4f9ba474 Mon Sep 17 00:00:00 2001 From: trevor Date: Tue, 14 Dec 2021 01:01:31 -0500 Subject: [PATCH 2/6] Shadowing Turn off shadows to reduce lag --- addons/libs/dialog.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/libs/dialog.lua b/addons/libs/dialog.lua index 2cf28f244..87c335d8f 100644 --- a/addons/libs/dialog.lua +++ b/addons/libs/dialog.lua @@ -203,8 +203,8 @@ function dialog.dat(zone_id) local n = 1 local rom = dat_path .. 'ROM/' repeat - local f = io.open(vtable, 'rb') - f:seek('set', dat_id) + local v = io.open(vtable, 'rb') + v:seek('set', dat_id) if byte(f:read(1)) > 0 then local f = io.open(ftable, 'rb') local dat = f:read('*a') @@ -217,7 +217,7 @@ function dialog.dat(zone_id) path = rom .. tostring(dir) .. '/' .. tostring(file) .. '.DAT' end - f:close() + v:close() n = n + 1 local d = tostring(n) rom = dat_path .. 'ROM' .. d .. '/' From a1200c6c3068dd0ff4bb40b82d2a97a59ba9530b Mon Sep 17 00:00:00 2001 From: trevor Date: Tue, 14 Dec 2021 01:26:23 -0500 Subject: [PATCH 3/6] Japanese dats --- addons/libs/dialog.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/libs/dialog.lua b/addons/libs/dialog.lua index 87c335d8f..02f4ef06f 100644 --- a/addons/libs/dialog.lua +++ b/addons/libs/dialog.lua @@ -188,13 +188,18 @@ dialog.decode_string = dialog.encode_string -- If a zone has a dialog message dat file, this function will -- return a file descriptor for it in "read/binary" mode. -function dialog.dat(zone_id) +function dialog.open_dat_by_zone_id(zone_id, language) local dat_id - if zone_id < 256 then - dat_id = zone_id + 6420 - else - dat_id = zone_id + 85335 - end + if zone_id < 256 then + dat_id = zone_id + 6120 + else + dat_id = zone_id + 85035 + end + if language == 'english' then + dat_id = dat_id + 300 + elseif language ~= 'japanese' then + return io.tmpfile() + end local dat_path = windower.ffxi_path local path From 497f5fbf1158f7a541f8ffb445e61ed34241de3b Mon Sep 17 00:00:00 2001 From: trevor Date: Tue, 14 Dec 2021 02:48:04 -0500 Subject: [PATCH 4/6] It would have been funny --- addons/libs/dialog.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/libs/dialog.lua b/addons/libs/dialog.lua index 02f4ef06f..8be08663b 100644 --- a/addons/libs/dialog.lua +++ b/addons/libs/dialog.lua @@ -198,7 +198,12 @@ function dialog.open_dat_by_zone_id(zone_id, language) if language == 'english' then dat_id = dat_id + 300 elseif language ~= 'japanese' then - return io.tmpfile() + print( + _addon and _addon.name or '???', + 'Dialog library: open_dat_by_zone_id expected ' + .. '"english" or "japanese". (Got: ' .. language .. ')' + ) + return end local dat_path = windower.ffxi_path From fce08482b6f537acdc567d5b19affe919a6c9b13 Mon Sep 17 00:00:00 2001 From: trevor Date: Tue, 14 Dec 2021 18:43:53 -0500 Subject: [PATCH 5/6] Missed formatting --- addons/libs/dialog.lua | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/addons/libs/dialog.lua b/addons/libs/dialog.lua index 8be08663b..0599fb8ef 100644 --- a/addons/libs/dialog.lua +++ b/addons/libs/dialog.lua @@ -190,21 +190,21 @@ dialog.decode_string = dialog.encode_string -- return a file descriptor for it in "read/binary" mode. function dialog.open_dat_by_zone_id(zone_id, language) local dat_id - if zone_id < 256 then - dat_id = zone_id + 6120 - else - dat_id = zone_id + 85035 - end - if language == 'english' then - dat_id = dat_id + 300 - elseif language ~= 'japanese' then - print( - _addon and _addon.name or '???', - 'Dialog library: open_dat_by_zone_id expected ' - .. '"english" or "japanese". (Got: ' .. language .. ')' - ) - return - end + if zone_id < 256 then + dat_id = zone_id + 6120 + else + dat_id = zone_id + 85035 + end + if language == 'english' then + dat_id = dat_id + 300 + elseif language ~= 'japanese' then + print( + _addon and _addon.name or '???', + 'Dialog library: open_dat_by_zone_id expected ' + .. '"english" or "japanese". (Got: ' .. language .. ')' + ) + return + end local dat_path = windower.ffxi_path local path @@ -215,7 +215,7 @@ function dialog.open_dat_by_zone_id(zone_id, language) repeat local v = io.open(vtable, 'rb') v:seek('set', dat_id) - if byte(f:read(1)) > 0 then + if byte(v:read(1)) > 0 then local f = io.open(ftable, 'rb') local dat = f:read('*a') f:close() From 930a13601ec0fbabe9d16528c568c7aaf19c26a6 Mon Sep 17 00:00:00 2001 From: trevor Date: Tue, 14 Dec 2021 18:50:30 -0500 Subject: [PATCH 6/6] Prevent id overlap They're pretty close! --- addons/libs/dialog.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/libs/dialog.lua b/addons/libs/dialog.lua index 0599fb8ef..7565c92be 100644 --- a/addons/libs/dialog.lua +++ b/addons/libs/dialog.lua @@ -190,10 +190,17 @@ dialog.decode_string = dialog.encode_string -- return a file descriptor for it in "read/binary" mode. function dialog.open_dat_by_zone_id(zone_id, language) local dat_id - if zone_id < 256 then - dat_id = zone_id + 6120 - else + if zone_id > 299 then + -- The English dialog files are currently 300 ids + -- ahead of the Japanese dialog files. If a zone with + -- id 300 or greater is added, SE will have to move to + -- a new range of ids which someone will need to locate. + print('Dialog library: zone id out of range.') + return + elseif zone_id > 255 then dat_id = zone_id + 85035 + else + dat_id = zone_id + 6120 end if language == 'english' then dat_id = dat_id + 300