101 lines
5.0 KiB
Python
101 lines
5.0 KiB
Python
"""Pins for content 9547 -> WMO outdoor flags.
|
|
|
|
Turtle/1.12 WMO groups use MOGP/MOGI flag 0x2000 together with 0x8000 (or 0x1000)
|
|
for walkable city streets; the 1.12 client and the Turtle server
|
|
(GridMap.cpp IsOutdoorWMO: outdoor unless (flags & 0xF000) == 0x2000) treat them
|
|
as OUTDOORS. The 70334 client decides outdoor from the EXTERIOR bit 0x8, so
|
|
Stormwind/Undercity streets were "Can only use outside". For every imported Turtle
|
|
WMO root, set 0x8 on each group the server rule calls outdoor and that lacks it.
|
|
All other bits (lighting) are kept. Catalogue-wide; reads the installed bytes.
|
|
"""
|
|
import json, hashlib, struct, sys
|
|
from pathlib import Path
|
|
H = Path(__file__).resolve().parent; sys.path.insert(0, str(H))
|
|
import frozen_store as fs
|
|
C = fs.casc
|
|
md5 = lambda b: hashlib.md5(b).hexdigest(); sha = lambda b: hashlib.sha256(b).hexdigest()
|
|
ROOTS = json.loads(Path('/mnt/Games/@project/gateway/runtime/continuation-20261110/map-wdt/indoor-wmoid-rows-mapsZ48J.private.json').read_text())['roots']
|
|
WHY = "Turtle street group: server rule (flags&0xF000)!=0x2000 = outdoor; 70334 needs EXTERIOR 0x8 (owner: can't mount in Stormwind/Undercity)"
|
|
store = fs.Store()
|
|
root = store.root; lay = store.layout; assert lay['root_md5'] == fs.ROOT
|
|
|
|
def cells_for(fids):
|
|
cells = {f: [] for f in fids}
|
|
for g in lay['groups']:
|
|
f = 0
|
|
for i, (d,) in enumerate(struct.iter_unpack('<I', memoryview(root)[g['ids_offset']:g['ckeys_offset']])):
|
|
f += d
|
|
if f in cells: cells[f].append((g, g['ckeys_offset'] + i * 16))
|
|
f += 1
|
|
return cells
|
|
|
|
def enus_cell(cells, fid):
|
|
en = [(g, at) for g, at in cells[fid] if g['locale'] & 2 and not g.get('flags1')]
|
|
assert len(en) == 1, (fid, len(en))
|
|
return en[0]
|
|
|
|
def chunks(b):
|
|
o = 0
|
|
while o + 8 <= len(b):
|
|
n = struct.unpack_from('<I', b, o + 4)[0]
|
|
yield b[o:o + 4][::-1].decode('latin1'), o + 8, n
|
|
o += 8 + n
|
|
|
|
def outdoor_fix(f):
|
|
return f | 0x8 if (f & 0x2000) and (f & 0xF000) != 0x2000 and not (f & 0x8) else f
|
|
|
|
root_fids = [r['root'] for r in ROOTS]
|
|
cells = cells_for(set(root_fids))
|
|
changes = {} # fid -> (name, old, new)
|
|
group_fids = {}
|
|
for r in ROOTS:
|
|
fid = r['root']
|
|
if not cells[fid]: continue
|
|
g, at = enus_cell(cells, fid); ck = root[at:at + 16].hex()
|
|
rb = store.read(ck)[2]
|
|
c = {t: (o, n) for t, o, n in chunks(rb)}
|
|
if 'GFID' not in c or 'MOGI' not in c: continue
|
|
o, n = c['GFID']; gfid = struct.unpack_from(f'<{n // 4}I', rb, o)
|
|
group_fids[fid] = (r['path'], gfid, rb, c['MOGI'])
|
|
|
|
all_groups = {fd for _, gf, _, _ in group_fids.values() for fd in gf if fd}
|
|
gcells = cells_for(all_groups)
|
|
for fid, (path, gfid, rb, (mo, mn)) in group_fids.items():
|
|
newroot = bytearray(rb); root_changed = False
|
|
for i, fd in enumerate(gfid):
|
|
if not fd or not gcells.get(fd): continue
|
|
g, at = enus_cell(gcells, fd); ck = root[at:at + 16].hex()
|
|
gb = store.read(ck)[2]
|
|
for t, o, n in chunks(gb):
|
|
if t == 'MOGP':
|
|
f = struct.unpack_from('<I', gb, o + 8)[0]; nf = outdoor_fix(f)
|
|
if nf != f:
|
|
nb = bytearray(gb); struct.pack_into('<I', nb, o + 8, nf)
|
|
changes[fd] = (path.lower().replace('\\', '/')[:-4] + '_%03d.wmo' % i, bytes(gb), bytes(nb))
|
|
break
|
|
mf = struct.unpack_from('<I', rb, mo + i * 32)[0]; nmf = outdoor_fix(mf)
|
|
if fd in changes and nmf == mf and not (mf & 0x8): nmf = mf | 0x8
|
|
if nmf != mf:
|
|
struct.pack_into('<I', newroot, mo + i * 32, nmf); root_changed = True
|
|
if root_changed:
|
|
changes[fid] = (path.lower().replace('\\', '/'), bytes(rb), bytes(newroot))
|
|
|
|
allcells = {**cells, **gcells}
|
|
patched = bytearray(root); pins = []
|
|
for fid, (name, old, new) in sorted(changes.items()):
|
|
g, at = enus_cell(allcells, fid); ckey = root[at:at + 16].hex()
|
|
assert ckey == md5(old)
|
|
assert sum(1 for g2, a2 in allcells[fid] if root[a2:a2 + 16].hex() == ckey) == 1
|
|
patched[at:at + 16] = bytes.fromhex(md5(new))
|
|
d = H / 'pins' / str(fid); d.mkdir(parents=True, exist_ok=True)
|
|
(d / 'before.bin').write_bytes(old); (d / 'after.bin').write_bytes(new)
|
|
pin = dict(fdid=fid, table=name, parent_root=fs.ROOT, selected_group={}, original_decoded=dict(file='before.bin', md5=ckey, sha256=sha(old)),
|
|
encrypted_original=False, after_decoded=dict(file='after.bin', md5=md5(new), sha256=sha(new)), reason=WHY)
|
|
(d / 'pin.json').write_text(json.dumps(pin, indent=1) + '\n')
|
|
pins.append(dict(file=str(d / 'pin.json'), sha256=sha((d / 'pin.json').read_bytes()), type='wdc_enus'))
|
|
(H / 'components.json').write_text(json.dumps(pins, indent=2) + '\n')
|
|
(H / 'selected-root.json').write_text(json.dumps(dict(parent_build=fs.BUILD, parent_root=fs.ROOT, decoded_root_sha256=sha(bytes(patched)), parent_root_sha256=sha(root)), indent=2) + '\n')
|
|
by = {}
|
|
for fid, (name, _, _) in changes.items(): by.setdefault(name.split('/')[-1].split('_')[0].replace('.wmo', ''), 0); by[name.split('/')[-1].split('_')[0].replace('.wmo', '')] += 1
|
|
print('pins', len(pins), by)
|