108 lines
6.6 KiB
Python
108 lines
6.6 KiB
Python
"""#34 WMO part (2026-11-25): the 28 spawned GameObject displays whose model is a WMO (houses, tents, planks...) that the
|
|
70334 client lacks. Octo WMO family -> source_map_wdt.numeric_wmo_family (the maps14 Turtle-map converter) with bindings
|
|
against the CURRENT store: textures = client FDID with identical bytes / native path in store / new BLP; doodads = native
|
|
M2 in store (else absent, MODI 0); groups + root = retail listfile FDIDs when not in store, else new FDIDs after
|
|
go-models.json next_free. Writes go-wmo.json (wmos, art, holds, next_free)."""
|
|
import json, struct, sys, hashlib
|
|
from pathlib import Path
|
|
sys.path.insert(0, '/mnt/Games/@project/wt-master-merge/ops'); sys.path.insert(0, '/mnt/Games/@project/wt-master-merge/ops/maps14-20261122')
|
|
import octo_mpq as O, source_map_wdt as smw, map_asset_preflight as terrain, frozen_store as fs
|
|
def chunks(b):
|
|
i = 0
|
|
while i + 8 <= len(b):
|
|
t = b[i:i+4][::-1].decode('latin1'); n = struct.unpack_from('<I', b, i+4)[0]; yield t, b[i+8:i+8+n]; i += 8 + n
|
|
W = Path(__file__).resolve().parent
|
|
md5 = lambda b: hashlib.md5(b).hexdigest()
|
|
norm = lambda p: p.replace('\\', '/').lower()
|
|
st = fs.Store(); root = st.root; fids = set(); ck = {}
|
|
for g in st.layout['groups']:
|
|
f = 0
|
|
for i, (d,) in enumerate(struct.iter_unpack('<I', memoryview(root)[g['ids_offset']:g['ckeys_offset']])):
|
|
f += d; fids.add(f); ck.setdefault(root[g['ckeys_offset'] + 16 * i:g['ckeys_offset'] + 16 * i + 16].hex(), set()).add(f); f += 1
|
|
lf = {}
|
|
for l in open('/mnt/Games/@project/listfiles/community-listfile.csv', errors='replace'):
|
|
i, _, p = l.rstrip('\n').partition(';'); lf.setdefault(p.lower(), int(i))
|
|
prev = json.load(open(W / 'go-models.json')); FREE = [prev['next_free']]
|
|
def new_fdid():
|
|
FREE[0] += 1; return FREE[0] - 1
|
|
def read(p):
|
|
try: return O.read(p.replace('/', '\\'))
|
|
except Exception: return None
|
|
art = []; new_tex = {}; used = set()
|
|
def add_art(fid, path, data, kind):
|
|
p = ''.join(ch if ch.isalnum() or ch in '_./-' else '_' for ch in path.lower())
|
|
if p in used: b, e = p.rsplit('.', 1); p = f'{b}_{fid}.{e}'
|
|
used.add(p); out = W / 'out' / f'{fid}.{kind.lower().replace("wmo-group", "wmo").replace("wmo-root", "wmo")}'
|
|
out.write_bytes(data); art.append(dict(file_data_id=fid, path=p, ckey=md5(data), kind=kind, file=str(out)))
|
|
def tex_fdid(path):
|
|
raw = read(path)
|
|
if raw is None:
|
|
f = lf.get(norm(path)); return f if f in fids else None
|
|
h = md5(raw)
|
|
if h in ck: return min(ck[h])
|
|
f = lf.get(norm(path))
|
|
if f in fids: return f
|
|
if h not in new_tex:
|
|
new_tex[h] = new_fdid(); add_art(new_tex[h], norm(path), raw, 'BLP')
|
|
return new_tex[h]
|
|
def model_fdi(p):
|
|
q = norm(p).rsplit('.', 1)[0] + '.m2'; f = lf.get(q); return f if f in fids else None
|
|
def names(raw, tag):
|
|
b = dict(chunks(raw)).get(tag, b''); out = []; i = 0
|
|
while i < len(b):
|
|
j = b.index(b'\0', i)
|
|
if j > i: out.append(b[i:j].decode('latin1'))
|
|
i = j + 1
|
|
return out
|
|
def null_absent_secondary(raw):
|
|
c = list(chunks(raw)); d = dict(c); tx = d['MOTX']; m = bytearray(d['MOMT'])
|
|
name = lambda o: tx[o:tx.index(b'\0', o)].decode('latin1')
|
|
empty = next((struct.unpack_from('<I', m, k + 24)[0] for k in range(0, len(m), 64) if not name(struct.unpack_from('<I', m, k + 24)[0])), None)
|
|
nulled = []
|
|
for k in range(0, len(m), 64):
|
|
o = struct.unpack_from('<I', m, k + 24)[0]; n = name(o)
|
|
if n and tex_fdid(n) is None and empty is not None: struct.pack_into('<I', m, k + 24, empty); nulled.append(n)
|
|
if not nulled: return raw, []
|
|
return b''.join(t[::-1].encode() + struct.pack('<I', len(m if t == 'MOMT' else b)) + (bytes(m) if t == 'MOMT' else b) for t, b in c), nulled
|
|
def tuples(raw):
|
|
m = dict(chunks(raw))['MOMT']
|
|
return {struct.unpack_from('<3I', m, k)[:1] + (struct.unpack_from('<I', m, k + 4)[0], struct.unpack_from('<I', m, k + 8)[0]) for k in range(0, len(m), 64)}
|
|
def LEG(raw):
|
|
m = dict(chunks(raw))['MOMT']
|
|
return terrain._WMO_LEGACY_MATERIAL_PROFILE if any(struct.unpack_from('<I', m, k + 36)[0] for k in range(0, len(m), 64)) else None
|
|
def SKY(raw):
|
|
n = dict(chunks(raw)).get('MOSB', b'').rstrip(b'\0').decode('latin1')
|
|
return {'sky_binding': model_fdi(n)} if n else {}
|
|
maps = {int(a): [int(x) for x in b.split(',')] for a, b in (l.rstrip('\n').split('\t') for l in open(W / 'wmo-maps.tsv') if l.strip())}
|
|
todo = [r for r in json.load(open(W / 'classified.json')) if r['kind'] == 'wmo']
|
|
wmos = {}; holds = []; by_path = {}
|
|
for r in todo: by_path.setdefault(r['octo_model'], []).append(r['display'])
|
|
for p, displays in sorted(by_path.items()):
|
|
raw = read(p)
|
|
if raw is None: holds.append(dict(path=p, displays=displays, reason='no Octo root')); continue
|
|
n = struct.unpack_from('<I', dict(chunks(raw))['MOHD'], 4)[0]; base = p[:-4]
|
|
groups = {i: read(f'{base}_{i:03d}.wmo') for i in range(n)}
|
|
if any(v is None for v in groups.values()): holds.append(dict(path=p, displays=displays, reason='missing group')); continue
|
|
raw, nulled = null_absent_secondary(raw)
|
|
tex = {norm(t): f for t in names(raw, 'MOTX') if (f := tex_fdid(t))}
|
|
dood = {norm(d): f for d in names(raw, 'MODN') if (f := model_fdi(d))}
|
|
gb = []
|
|
for i in range(n):
|
|
f = lf.get(f'{norm(base)}_{i:03d}.wmo'); gb.append(f if f and f not in fids else new_fdid())
|
|
mids = sorted({m for d in displays for m in maps.get(d, [])})
|
|
try:
|
|
rootb, conv, audit = smw.numeric_wmo_family(raw, p, groups, map_ids=mids, texture_bindings=tex, group_bindings=gb, doodad_bindings=dood,
|
|
legacy_material_profile=LEG(raw), **SKY(raw),
|
|
native_observed_tuples=tuples(raw) & (smw.NATIVE_OBSERVED_MATERIAL_TUPLES | smw.NATIVE_FLAG_UNION_MATERIAL_TUPLES))
|
|
except Exception as e:
|
|
holds.append(dict(path=p, displays=displays, reason=f'{type(e).__name__}: {e}'[:300])); continue
|
|
rf = lf.get(norm(p)); rf = rf if rf and rf not in fids else new_fdid()
|
|
for i, g in conv.items(): add_art(gb[i], f'{norm(base)}_{i:03d}.wmo', g, 'WMO-GROUP')
|
|
add_art(rf, norm(p), rootb, 'WMO-ROOT')
|
|
mohd = dict(chunks(rootb))['MOHD']; box = list(struct.unpack_from('<6f', mohd, 36))
|
|
wmos[p] = dict(displays=displays, root=rf, groups=gb, box=box, maps=mids, absent_doodads=len(audit['absent_doodads']), nulled_secondary=nulled)
|
|
json.dump(dict(wmos=wmos, art=art, holds=holds, next_free=FREE[0]), open(W / 'go-wmo.json', 'w'), indent=1)
|
|
print('wmos', len(wmos), 'displays', sum(len(v['displays']) for v in wmos.values()), 'held', len(holds), 'art', len(art), 'new textures', len(new_tex),
|
|
'absent doodads', sum(v['absent_doodads'] for v in wmos.values()))
|
|
[print('HOLD', h) for h in holds]
|