114 lines
3.8 KiB
Python
114 lines
3.8 KiB
Python
"""Read 1.12 client tables from the Octo/Turtle MPQs (highest-priority archive wins)
|
|
and dump what the tree addon needs: lock/skill info, map rectangles, zone names."""
|
|
import json
|
|
import os
|
|
import struct
|
|
import sys
|
|
|
|
# Needs a pure-Python mpq.py (MpqArchive with has/read_raw): put it next to this
|
|
# script, or point MPQ_PY_DIR at the folder that holds it.
|
|
sys.path.insert(0, os.environ.get("MPQ_PY_DIR", os.path.dirname(os.path.abspath(__file__))))
|
|
from mpq import MpqArchive # noqa: E402
|
|
|
|
DATA = os.path.expanduser(r"~\Documents\Turtle Wow\Data")
|
|
OUT = sys.argv[1]
|
|
|
|
# 1.12 load order: base archives, then patch.MPQ, patch-1..9, then patch-A..Z (later wins)
|
|
names = [n for n in os.listdir(DATA) if n.lower().endswith(".mpq") and os.path.getsize(os.path.join(DATA, n)) > 0]
|
|
base = [n for n in names if not n.lower().startswith("patch")]
|
|
patches = [n for n in names if n.lower().startswith("patch")]
|
|
|
|
|
|
def prio(n):
|
|
s = os.path.splitext(n)[0].lower()
|
|
if s == "patch":
|
|
return (0, "")
|
|
tag = s.split("-", 1)[1]
|
|
return (1 if tag.isdigit() else 2, tag)
|
|
|
|
|
|
order = sorted(base) + sorted(patches, key=prio)
|
|
archives = []
|
|
for n in order:
|
|
try:
|
|
archives.append((n, MpqArchive(os.path.join(DATA, n))))
|
|
except Exception as e: # noqa: BLE001
|
|
print("skip", n, e)
|
|
|
|
|
|
def read(name):
|
|
hit = None
|
|
for n, a in archives:
|
|
if a.has(name):
|
|
hit = (n, a)
|
|
if not hit:
|
|
raise KeyError(name)
|
|
return hit[0], hit[1].read_raw(name)
|
|
|
|
|
|
def dbc(name):
|
|
src, data = read("DBFilesClient\\" + name)
|
|
magic, nrec, nfield, rsize, ssize = struct.unpack_from("<4sIIII", data)
|
|
assert magic == b"WDBC", name
|
|
rows = [list(struct.unpack_from("<%dI" % nfield, data, 20 + i * rsize)) for i in range(nrec)]
|
|
strings = data[20 + nrec * rsize:]
|
|
|
|
def s(off):
|
|
if off >= len(strings):
|
|
return None
|
|
end = strings.find(b"\0", off)
|
|
return strings[off:end].decode("utf-8", "replace")
|
|
|
|
def f(v):
|
|
return struct.unpack("<f", struct.pack("<I", v))[0]
|
|
|
|
return src, nfield, rows, s, f
|
|
|
|
|
|
out = {}
|
|
|
|
src, nf, rows, s, f = dbc("SkillLine.dbc")
|
|
out["skillline_src"] = src
|
|
out["skills"] = [[r[0], r[1], s(r[3])] for r in rows if s(r[3]) and any(k in s(r[3]).lower() for k in ("surviv", "wood"))]
|
|
|
|
src, nf, rows, s, f = dbc("LockType.dbc")
|
|
out["locktype_src"] = src
|
|
out["locktypes"] = [[r[0], s(r[1])] for r in rows]
|
|
|
|
src, nf, rows, s, f = dbc("Lock.dbc")
|
|
out["lock_src"] = src
|
|
out["lock_nfield"] = nf
|
|
# 1.12 Lock.dbc: id, type[8], index[8], skill[8], action[8]
|
|
locks = []
|
|
for r in rows:
|
|
types, idx, skill = r[1:9], r[9:17], r[17:25]
|
|
for k in range(8):
|
|
if types[k] == 2: # lock type
|
|
locks.append([r[0], idx[k], skill[k]])
|
|
out["locks_by_type"] = {}
|
|
for lid, lt, sk in locks:
|
|
out["locks_by_type"].setdefault(str(lt), []).append([lid, sk])
|
|
|
|
src, nf, rows, s, f = dbc("WorldMapArea.dbc")
|
|
out["wma_src"] = src
|
|
out["wma_nfield"] = nf
|
|
# 1.12 WorldMapArea.dbc: id, mapId, areaId, areaName, locLeft, locRight, locTop, locBottom
|
|
out["wma"] = [[r[0], r[1], r[2], s(r[3]), f(r[4]), f(r[5]), f(r[6]), f(r[7])] for r in rows]
|
|
|
|
src, nf, rows, s, f = dbc("AreaTable.dbc")
|
|
out["area_src"] = src
|
|
out["area_nfield"] = nf
|
|
# 1.12 AreaTable.dbc: id, mapId, parent, areaBit, flags, soundPref, soundPrefUw, ambience, music, intro, explorationLevel, name_enUS ...
|
|
out["areas"] = {str(r[0]): [r[1], r[2], r[10], s(r[11])] for r in rows if r[2] == 0}
|
|
|
|
icons = ["simple_wood_1", "oak_wood_1", "pine_wood_1", "tropical_logs_1", "star_log_2", "INV_TradeskillItem_01"]
|
|
out["icons"] = {}
|
|
for ic in icons:
|
|
p = "Interface\\Icons\\%s.blp" % ic
|
|
out["icons"][ic] = [n for n, a in archives if a.has(p)]
|
|
|
|
with open(OUT, "w", encoding="utf-8") as fh:
|
|
json.dump(out, fh, indent=1)
|
|
print("archives:", [n for n, _ in archives])
|
|
print("wrote", OUT)
|