From 942a030afd348ab2e02eac8054b43e3c3a72ea48 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 15 Nov 2021 13:53:59 +0800 Subject: *rename --- .../Libraries/lua-addons/addons/libs/dialog.lua | 227 +++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 Data/BuiltIn/Libraries/lua-addons/addons/libs/dialog.lua (limited to 'Data/BuiltIn/Libraries/lua-addons/addons/libs/dialog.lua') diff --git a/Data/BuiltIn/Libraries/lua-addons/addons/libs/dialog.lua b/Data/BuiltIn/Libraries/lua-addons/addons/libs/dialog.lua new file mode 100644 index 0000000..5598175 --- /dev/null +++ b/Data/BuiltIn/Libraries/lua-addons/addons/libs/dialog.lua @@ -0,0 +1,227 @@ +-- This library was written to help find the ID of a known +-- action message corresponding to an entry in the dialog tables. +-- While the IDs can be collected in-game, they occasionally +-- change and would otherwise need to be manually updated. +-- It can also be used to find and decode an entry given the ID. + +-- Common parameters: +-- +-- dat: Either the entire content of the zone dialog DAT file or +-- a file descriptor. +-- i.e. either local dat = io.open('path/to/dialog/DAT', 'rb') +-- or dat = dat:read('*a') +-- The functions are expected to be faster when passed a string, +-- but will use less memory when receiving a file descriptor. +-- +-- entry: The string you are looking for. Whether or not the string +-- is expected to be encoded should be indicated in the parameter's +-- name. If you do not know the entire string, use dev.find_substring +-- and serialize the result. + +local xor = require('bit').bxor +local floor = require('math').floor +local string = require('string') +local find = string.find +local sub = string.sub +local gsub = string.gsub +local format = string.format +local char = string.char +local byte = string.byte +require('pack') +local unpack = string.unpack +local pack = string.pack + +local function decode(int) + return xor(int, 0x80808080) +end +local encode = decode + +local function binary_search(pos, dat, n) + local l, r, m = 1, n + while l < r do + m = floor((l + r) / 2) + if decode(unpack(' last_offset then + break + elseif offset == last_offset then + next_pos = #dat + 1 + else + next_pos = decode(unpack('