Files

55 lines
3.7 KiB
Python

"""White item models (owner 2026-11-28: Lawbringer Helmet 47000 white on Blesisi). Catalogue rule over every used
ItemDisplayInfo slot whose imported models (FDID >= 8,000,000) draw a texture of type 2 (item texture): the client takes
it from ItemDisplayInfoModelMatRes / IDI.ModelMaterialResourcesID. 14 imported displays have neither, so the race
variants with a type-2 slot render white while the variants with a hardcoded TXID texture are textured. The correct
material is that same model set's own imported TXID texture (TextureFileData.MaterialResourcesID); Octo source names
agree (47000: Helm_Plate_RaidPaladin_A_01OutlandBlue = 8530330). Slots with no imported texture (invisible_weapon.mdx)
are left. Writes setrows-idi.json (ModelMaterialResourcesID) and addrows-mmr.json (TextureType 2 rows)."""
import sys, struct, json, collections
from pathlib import Path
H = Path(__file__).resolve().parent; sys.path.insert(0, str(H)); sys.path.insert(0, '/mnt/Games/@project/wt-master-merge/ops/claude_recipe_parity')
import dbd, frozen_store as fs
st = fs.Store(); root = st.root; ck = {}
for g in st.layout['groups']:
if not (g['locale'] & 2) or g.get('flags1'): continue
f = 0
for i, (d,) in enumerate(struct.iter_unpack('<I', memoryview(root)[g['ids_offset']:g['ckeys_offset']])):
f += d; ck.setdefault(f, root[g['ckeys_offset'] + i * 16:g['ckeys_offset'] + i * 16 + 16].hex()); f += 1
T = lambda n: dbd.table(n, str(H / 'in' / f'{n}.db2'))['rows']
idi = T('ItemDisplayInfo'); mmr = T('ItemDisplayInfoModelMatRes'); mfd = T('ModelFileData'); tfd = T('TextureFileData'); ia = T('ItemAppearance')
byres = collections.defaultdict(list)
for r in mfd.values(): byres[r['ModelResourcesID']].append(r['FileDataID'])
have = collections.defaultdict(set)
for r in mmr.values(): have[r['ItemDisplayInfoID']].add(r['ModelIndex'])
mat = {r['FileDataID']: r['MaterialResourcesID'] for r in tfd.values() if r['MaterialResourcesID']}
def tex(fid):
b = st.read(ck[fid])[2]; o = 0; tx = []; md = None
while o + 8 <= len(b):
t = b[o:o + 4]; s = struct.unpack_from('<I', b, o + 4)[0]
if t == b'TXID': tx = list(struct.unpack_from('<%dI' % (s // 4), b, o + 8))
if t == b'MD21': md = b[o + 8:o + 8 + s]
o += 8 + s
n, ofs = struct.unpack_from('<II', md, 0x50)
return [struct.unpack_from('<I', md, ofs + i * 16)[0] for i in range(n)], tx
setidi, addmmr, skipped = {}, [], []; nid = max(mmr)
for d in sorted({a['ItemDisplayInfoID'] for a in ia.values()}):
r = idi.get(d)
if not r: continue
for mi in (0, 1):
res = r['ModelResourcesID'][mi]; files = [f for f in byres.get(res, []) if f >= 8000000 and f in ck]
if not files: continue
need, mats = False, set()
for f in files:
ty, tx = tex(f); need |= 2 in ty
mats |= {mat[tx[k]] for k, t in enumerate(ty) if t == 0 and k < len(tx) and tx[k] >= 8000000 and tx[k] in mat}
if not need or (r['ModelMaterialResourcesID'][mi] and mi in have[d]): continue
if len(mats) != 1: skipped.append(dict(display=d, model=mi, res=res, mats=sorted(mats))); continue
m = mats.pop(); cur = r['ModelMaterialResourcesID'][mi] or m
v = list(setidi.get(d, r['ModelMaterialResourcesID'])); v[mi] = cur; setidi[d] = v
if mi not in have[d]:
nid += 1; addmmr.append(dict(ID=nid, MaterialResourcesID=cur, TextureType=2, ModelIndex=mi, ItemDisplayInfoID=d))
json.dump([dict(ID=d, ModelMaterialResourcesID=v) for d, v in sorted(setidi.items())], open(H / 'setrows-idi.json', 'w'), indent=1)
json.dump(addmmr, open(H / 'addrows-mmr.json', 'w'), indent=1)
json.dump(skipped, open(H / 'skipped.json', 'w'), indent=1)
print('idi', len(setidi), 'mmr', len(addmmr), 'skipped', skipped)