-- to use this get the package from http://greatstone.free.fr/hi2txt/ -- extract the hi2txt.zip and place it in your history path local dat = {} local env = {} local output local curset function env.open(file, size) if file == ".hi" then local path = "hi" local ini = emu.file(lfs.env_replace(manager:options().entries.inipath:value()), 1) local ret = ini:open("hiscore.ini") if not ret then local inifile = ini:read(ini:size()) for line in inifile:gmatch("[^\n\r]") do token, value = string.match(line, '([^ ]+) ([^ ]+)'); if token == "hi_path" then path = value break end end end file = path .. "/" .. curset .. ".hi" else file = lfs.env_replace(manager:options().entries.nvram_directory:value()) .. "/" .. curset .. "/" .. file end local f = io.open(file, "rb") local content = f:read("*all") f:close() if #content < size then content = content .. string.rep("\0", size - #content) end return content end function env.endianness(bytes, endian) local newbytes = {} if endian == "little_endian" then for i = 1, #bytes do newbytes[i] = bytes[#bytes - i + 1] end else newbytes = bytes end return newbytes end function env.byte_skip(bytes, skip) local newbytes = {} if skip == "odd" then -- lua lists are 1 based so use even indexes for i = 2, #bytes, 2 do newbytes[i/2] = bytes[i] end elseif skip == "even" then for i = 1, #bytes, 2 do newbytes[(i+1)/2] = bytes[i] end elseif skip == "1000" then for i = 1, #bytes, 4 do newbytes[(i+3)/4] = bytes[i] end elseif skip == "0100" then for i = 2, #bytes, 4 do newbytes[(i+2)/4] = bytes[i] end elseif skip == "0010" then for i = 3, #bytes, 4 do newbytes[(i+1)/4] = bytes[i] end elseif skip == "0001" then for i = 4, #bytes, 4 do newbytes[i/4] = bytes[i] end else skip = tonumber(skip) for i = 1, #bytes do if bytes[i] ~= skip then newbytes[#newbytes + 1] = bytes[i] end end end return newbytes end function env.byte_trim(bytes, val) val = tonumber(val) for i = 1, #bytes do if bytes[i] ~= val then return bytes end table.remove(bytes, 1) end return bytes end function env.byte_swap(bytes, val) local newbytes = {} val = tonumber(val) for i = 1, #bytes do local off = i + val - 1 - 2 * ((i - 1) % val) if off > #bytes then -- ?? break end newbytes[i] = bytes[off] end return newbytes end function env.nibble_skip(bytes, skip) local newbytes = {} if skip == "odd" then for i = 1, #bytes, 2 do val1 = bytes[i]:byte(1) val2 = bytes[i+1]:byte(1) newbytes[(i+1)/2] = string.char(((val1 & 0x0f) << 4) | (val2 & 0x0f)) end elseif skip == "even" then for i = 1, #bytes, 2 do val1 = bytes[i]:byte(1) val2 = bytes[i+1]:byte(1) newbytes[(i+1)/2] = string.char((val1 & 0xf0) | ((val2 & 0xf0) >> 4)) end end return newbytes end function env.bit_swap(bytes, swap) if swap == "yes" then for i = 1, #bytes do val = bytes[i]:byte(1) bytes[i] = string.char(((val & 1) << 7) | ((val & 2) << 5) | ((val & 4) << 3) | ((val & 8) << 1) | ((val & 0x10) >> 1) | ((val & 0x20) >> 3) | ((val & 0x40) >> 5) | ((val & 0x80) >> 7)) end end return bytes end function env.bitmask(bytes, mask) local newbytes = 0 bytes = string.unpack(">I" .. #bytes, table.concat(bytes)) for i = 1, #mask do newbytes = newbytes | (((bytes >> mask.ishift) & mask.mask) << mask.oshift) end bytes = {} while newbytes ~= 0 do bytes[#bytes + 1] = newbytes & 0xff newbytes = newbytes >> 8 end newbytes = {} for i = 1, #bytes do newbytes[i] = string.char(bytes[#bytes + 1 - i]) end return newbytes end function env.frombcd(val) local result = 0 local mul = 1 while val ~= 0 do result = result + ((val % 16) * mul) val = val >> 4 mul = mul * 10 end return result end function env.basechar(bytes, base) emu.print_verbose("data_hiscore: basechar " .. base .. " unimplemented\n") if base == "32" then elseif base == "40" then end return bytes end function env.charset_conv(bytes, charset) if type(charset) == "string" then local chartype, offset, delta = charset:match("CS_(%w*)%[?(%-?%d?%d?),?(%d?%d?)%]?") if chartype == "NUMBER" then end emu.print_verbose("data_hiscore: charset " .. chartype .. " unimplemented\n") return bytes end for num, char in ipairs(bytes) do char = string.byte(char) if charset[char] then bytes[num] = charset[char] elseif charset.default then bytes[num] = charset.default end end return bytes end function env.ascii_step(bytes, step) for num, char in ipairs(bytes) do bytes[num] = string.char(char:byte() / step) end return bytes end function env.ascii_offset(bytes, offset) for num, char in ipairs(bytes) do bytes[num] = string.char(char:byte() + offset) end return bytes end env.tostring = tostring env.type = type env.table = { pack = table.pack, concat = table.concat } env.string = { unpack = string.unpack, format = string.format, rep = string.rep, gsub = string.gsub, lower = string.lower, upper = string.upper } env.math = { min = math.min, max = math.max, floor = math.floor } do local function readonly(t) local mt = { __index = t, __newindex = function(t, k, v) return end } return setmetatable({}, mt) end env.table = readonly(env.table) env.string = readonly(env.string) env.math = readonly(env.math) env = readonly(env) end function dat.check(set, softlist) if softlist then return nil end local datpath local function xml_parse(file) local table datpath = file:fullpath():gsub(".zip", "/") local data = file:read(file:size()) data = data:match("(.*)") local function get_tags(str, parent) local arr = {} while str ~= "" do local tag, attr, stop tag, attr, stop, str = str:match("<([%w!_%-]+) ?(.-)(/?)[ %-]->(.*)") if not tag then return arr end if tag:sub(0, 3) ~= "!--" then local block = {} if stop ~= "/" then local nest nest, str = str:match("(.-)(.*)") local children = get_tags(nest, tag) if not next(children) then nest = nest:gsub("