Files

111 lines
7.5 KiB
Python

"""Batch 6 (2026-11-23, from build5.py): + helms converted by helmconv.py (helms.json), Octo-missing helm textures left empty.
Batch 5 notes: (2026-11-23): Octo-only helms whose per-race head files are already in the client (helm refit, unlisted
paths in ops/helm-refit-20261123/unlisted-heads.json) but have no ModelFileData / ComponentModelFileData rows.
Per helm: one new ModelResources; per file a ModelFileData row and a ComponentModelFileData row (race from the
suffix, GenderIndex 0 male / 1 female, PositionIndex -1, as native helm_cloth_a_01_*). Then display rows like
build4 (geosets, HelmetGeosetVis only for kept pairs, model material + ItemDisplayInfoModelMatRes), IA, IMA."""
import json, re, sys, subprocess, collections
from pathlib import Path
sys.path.insert(0, '/mnt/Games/@project/gateway/ops/maps14-20261122'); import octo_mpq
W = Path(__file__).resolve().parent
C = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/item-helms6-8b18-20261123')
S = '/tmp/claude-1000/-home-praxis-Projects/c41b4c2f-f4c2-4e21-8c6d-a961250d8864/scratchpad'
TOOL = ['dotnet', '/mnt/Games/@project/wt-merge/ops/db2-bake-20261122/tool/bin/Debug/net10.0/Db2Bake.dll', 'dump', str(C / 'inputs/before'), '/mnt/Games/@project/tools/WoWDBDefs/definitions']
def dump(t):
for l in subprocess.run(TOOL + [t], capture_output=True, text=True, check=True).stdout.splitlines():
x = l.split('\t'); yield dict(a.split('=', 1) for a in x[1:])
RACE = {'hu': 1, 'or': 2, 'dw': 3, 'ni': 4, 'sc': 5, 'ta': 6, 'gn': 7, 'tr': 8, 'go': 9, 'be': 10, 'dr': 11}
u = json.load(open('/mnt/Games/@project/wt-master-merge/ops/helm-refit-20261123/unlisted-heads.json'))
root = set(json.load(open(f'{S}/root-ids-049a.json')))
ck = json.load(open(W / 'root-ckeys.json'))
tfd = {int(r['FileDataID']): int(r['MaterialResourcesID']) for r in dump('TextureFileData')}
mfd = {int(r['FileDataID']): int(r['ModelResourcesID']) for r in dump('ModelFileData')}
nmmr = 1 + max(int(r['ID']) for r in dump('ItemDisplayInfoModelMatRes'))
items = {int(r['ID']): r for r in (dict(a.split('=', 1) for a in l.rstrip('\n').split('\t')[1:]) for l in open(f'{S}/itemdb2/Item.tsv'))}
prev = ('add', 'add2', 'add3', 'add4', 'add5')
apps = collections.defaultdict(list)
for f in prev:
for r in json.load(open(W / f'{f}-ItemAppearance.json')): apps[r['ItemDisplayInfoID']].append(r['ID'])
prev_ia = json.load(open(f'{S}/ia-add.json')) + [r for f in prev for r in json.load(open(W / f'{f}-ItemAppearance.json'))]
prev_ima = json.load(open(f'{S}/ima-add.json')) + [r for f in prev for r in json.load(open(W / f'{f}-ItemModifiedAppearance.json'))]
nia = max(r['ID'] for r in prev_ia) + 1; nima = max(r['ID'] for r in prev_ima) + 1
nmr = max(tfd.values()) + 1; nmres = max(v for v in mfd.values() if v < 2200000) + 1
done_before = {r['ID'] for f in prev for r in json.load(open(W / f'{f}-ItemDisplayInfo.json'))}
HELM_KEEP = {(245, 245), (247, 247), (248, 306), (249, 305)}
R = json.load(open(W / 'resolved.json')); plan = json.load(open(f'{S}/ima-plan.json'))
out = collections.defaultdict(list); holds = []; done = {}; res_of = {}; used = set(); alias = []; nalias = 8810350
NEW = json.load(open(W / 'helms.json'))['helms']
def heads(name):
if name in NEW: return {(RACE[k[:2]], 0 if k[2] == 'm' else 1): f for k, f in NEW[name].items()}
fs = {}
for p, f in u.items():
m = re.fullmatch(r'item/objectcomponents/head/' + re.escape(name) + r'_([a-z]{2})([mf])\.m2', p)
if m and m.group(1) in RACE and f in root: fs[(RACE[m.group(1)], 0 if m.group(2) == 'm' else 1)] = f
return fs
def helm_res(name, fs):
global nmres
if name in res_of: return res_of[name]
r = nmres; nmres += 1; res_of[name] = r
for (race, g), f in sorted(fs.items()):
assert f not in mfd, (name, f)
if f in used: # same bytes already serve another helm: alias FDID on the same content
global nalias
alias.append(dict(file_data_id=nalias, source_fdid=f, path=f"item/objectcomponents/head/{name}_{[k for k, v in RACE.items() if v == race][0]}{'mf'[g]}_octo2.m2"))
f = nalias; nalias += 1
used.add(f)
out['ModelFileData'].append(dict(ID=f, GeoBox=[0] * 6, FileDataID=f, Flags=0, LodCount=0, ModelResourcesID=r))
out['ComponentModelFileData'].append(dict(ID=f, GenderIndex=g, ClassID=0, RaceID=race, PositionIndex=-1))
return r
def tex_fdids(p):
of = {k: v for k, v in p.get('octo_files', {}).items() if v}
if of: return sorted({v[0] for v in of.values()})
for d in ('head', 'shoulder', 'weapon', 'shield', 'cape'): # Octo file not in the listfile: find its bytes in the client
try: raw = octo_mpq.read(f'Item\\ObjectComponents\\{d}\\{p["name"]}.blp')
except Exception: continue
if not raw: continue
try: pass
except Exception: continue
import hashlib; h = hashlib.md5(raw).hexdigest()
if h in ck: return [min(ck[h])]
return []
def mat_res(fids):
global nmr
have = {tfd[f] for f in fids if f in tfd}
if have: return min(have) if all(f in tfd for f in fids) else None
m = nmr; nmr += 1
for f in fids: out['TextureFileData'].append(dict(ID=f, FileDataID=f, UsageType=0, MaterialResourcesID=m)); tfd[f] = m
return m
for x in R:
d = x['display']
if x['cls'] in ('icon-only', 'no-octo-row') or d in done_before: continue
mp = [p for p in x['parts'] if p['kind'] == 'model']
if not mp or not all(p['name'].lower().startswith(('helm', 'custom_', 'br')) for p in mp): continue
if len(mp) != 1: holds.append((d, 'helm display with %d models' % len(mp))); continue
name = mp[0]['name'].lower().rsplit('.', 1)[0]; fs = heads(name)
if len(fs) < 4: holds.append((d, f'{name}: {len(fs)} per-race files in client')); continue
mmr = [0, 0]; bad = None; missing = []
for p in x['parts']:
if p['kind'] == 'modeltex':
fl = tex_fdids(p)
if not fl: missing.append(p['name']); continue # absent on Octo too: slot stays empty there
mmr[p['side']] = mat_res(fl)
elif p['kind'] == 'body': bad = 'helm with body texture'; break
if bad: holds.append((d, bad)); continue
hv = tuple(x['helmvis']); hv = list(hv) if hv in HELM_KEEP else [0, 0]
out['ItemDisplayInfo'].append(dict(ID=d, ItemVisual=x['item_visual'], Flags=0, ModelResourcesID=[helm_res(name, fs), 0], ModelMaterialResourcesID=mmr,
ModelType=[0, 0], GeosetGroup=list(x['geosets']) + [0] * 3, AttachmentGeosetGroup=[0] * 6, HelmetGeosetVis=hv))
for i, m in enumerate(mmr):
if m: out['ItemDisplayInfoModelMatRes'].append(dict(ID=nmmr, MaterialResourcesID=m, TextureType=2, ModelIndex=i, ItemDisplayInfoID=d)); nmmr += 1
done[d] = (len(fs), missing)
for item, d, inv in plan['conv']:
if d not in done: continue
if d in apps: a = min(apps[d])
else:
a = nia; nia += 1; apps[d].append(a)
out['ItemAppearance'].append(dict(ID=a, DisplayType=0, ItemDisplayInfoID=d, DefaultIconFileDataID=int(items[item]['IconFileDataID']), UiOrder=0, TransmogPlayerConditionID=0))
out['ItemModifiedAppearance'].append(dict(ID=nima, ItemID=item, ItemAppearanceModifierID=0, ItemAppearanceID=a, OrderIndex=0, TransmogSourceTypeEnum=0, Flags=0)); nima += 1
for t, rows in out.items(): json.dump(rows, open(W / f'add6-{t}.json', 'w'))
json.dump(holds, open(W / 'add6-holds.json', 'w'), indent=0)
json.dump(alias, open(W / 'add6-alias.json', 'w'), indent=0)
print('aliases', len(alias)); print({t: len(v) for t, v in out.items()}, 'displays', len(done), done, 'holds', holds)