-- 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('