92 lines
5.3 KiB
Python
92 lines
5.3 KiB
Python
"""#84 (2026-11-28): VolumeFog::MAX_INTERIOR_WMO_PARAMS assert (WorldSceneRender.cpp:830, count 65-91) near Undercity
|
|
(Brill), Stormwind (Elwynn) and BRM. Content 4371a22a gave Turtle street groups (MOGP 0x2000 with 0x8000/0x1000, outdoor
|
|
by the Turtle server rule) EXTERIOR 0x8 but kept INTERIOR 0x2000. Native 70334 WMOs never combine the two (native
|
|
undercity.wmo: 197 interior-only, 19 exterior-only groups). An EXTERIOR group is frustum-drawn from outside without
|
|
portals, and with 0x2000 still set each one is also an interior fog volume, so a distant city exceeds the 64-volume
|
|
limit (live capture at Brill: 140 records, 65 passing, all at Undercity). Native outdoor convention: EXTERIOR without
|
|
INTERIOR. Clear 0x2000 on those groups (root MOGI and group MOGP); 0x8 keeps them outdoor (mounting).
|
|
Catalogue-wide over every imported Turtle WMO root; reads the installed bytes."""
|
|
import json, hashlib, struct, sys, collections
|
|
from pathlib import Path
|
|
H = Path(__file__).resolve().parent; sys.path.insert(0, str(H))
|
|
import frozen_store as fs
|
|
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 = '#84: Turtle outdoor street group had EXTERIOR 0x8 + INTERIOR 0x2000 (never native) -> interior fog volume drawn from outside; clear 0x2000'
|
|
store = fs.Store(); root = store.root; lay = store.layout; assert lay['root_md5'] == fs.ROOT
|
|
|
|
|
|
def fix(f):
|
|
return f & ~0x2000 if (f & 0x2000) and (f & 0x8) and (f & 0xF000) != 0x2000 else f
|
|
|
|
|
|
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
|
|
|
|
|
|
cells = cells_for({r['root'] for r in ROOTS})
|
|
changes = {}; groups = {}; stats = collections.Counter()
|
|
for r in ROOTS:
|
|
fid = r['root']
|
|
if not cells[fid]: continue
|
|
g, at = enus_cell(cells, fid); rb = store.read(root[at:at + 16].hex())[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']; groups[fid] = (r['path'], struct.unpack_from(f'<{n // 4}I', rb, o), rb, c['MOGI'])
|
|
gcells = cells_for({fd for _, gf, _, _ in groups.values() for fd in gf if fd})
|
|
for fid, (path, gfid, rb, (mo, mn)) in groups.items():
|
|
newroot = bytearray(rb); changed = False
|
|
for i, fd in enumerate(gfid):
|
|
mf = struct.unpack_from('<I', rb, mo + i * 32)[0]; outdoor = fix(mf) != mf
|
|
if fd and gcells.get(fd): # the group MOGP decides (as content 4371a22a did); the root MOGI entry follows it
|
|
g, at = enus_cell(gcells, fd); gb = store.read(root[at:at + 16].hex())[2]
|
|
for t, o, n in chunks(gb):
|
|
if t == 'MOGP':
|
|
f = struct.unpack_from('<I', gb, o + 8)[0]; outdoor = fix(f) != f
|
|
if outdoor:
|
|
nb = bytearray(gb); struct.pack_into('<I', nb, o + 8, f & ~0x2000)
|
|
changes[fd] = (path.lower().replace('\\', '/')[:-4] + '_%03d.wmo' % i, gb, bytes(nb)); stats['group-mogp'] += 1
|
|
break
|
|
if outdoor and (mf & 0x2000) and (mf & 0x8):
|
|
struct.pack_into('<I', newroot, mo + i * 32, mf & ~0x2000); changed = True; stats['root-mogi'] += 1
|
|
elif outdoor: stats['root-entry-not-IE'] += 1
|
|
if changed: changes[fid] = (path.lower().replace('\\', '/'), 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)
|
|
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={}, encrypted_original=False,
|
|
original_decoded=dict(file='before.bin', md5=ckey, sha256=sha(old)),
|
|
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 = collections.Counter(n.split('/')[-1].split('_')[0].replace('.wmo', '') for n, _, _ in changes.values())
|
|
(H / 'prep-report.json').write_text(json.dumps(dict(stats=stats, pins=len(pins), by_wmo=by), indent=1) + '\n')
|
|
print('pins', len(pins), dict(stats), dict(by))
|