Files

92 lines
6.5 KiB
Python

"""Octo-only helms with no files in the client (2026-11-23): extract every per-race head from Octo's MPQs, convert
(m2_equipment_convert, same options as conv4.py), wrap as MD21 on new FDIDs 8810400+ and apply the HD-head refit
(ops/helm-refit-20261123: one uniform scale + offset per race/gender, report.json 'transforms'), exactly as refit.py
does for the installed Octo heads: vertices, normals, bone pivots (+translation keys when scaled), attachment /
particle / ribbon / light positions, bounding box. Output models/helms/out + helms.json (name -> race/gender files)."""
import json, struct, sys, hashlib, re, shutil
import numpy as np
from pathlib import Path
sys.path.insert(0, '/mnt/Games/@project/wt-master-merge/ops'); sys.path.insert(0, '/mnt/Games/@project/gateway/ops/maps14-20261122')
import m2_equipment_convert as c, octo_mpq
from casc_asset_package import model_container
W = Path(__file__).resolve().parent; H = W / 'models/helms'
FAM = ['custom_shaman_tier_01_helm_001', 'custom_conehat_001', 'brraptor_helm_taloncrown', 'brmooncloth_helm_cloth',
'brhuntblood_helm_coifmask', 'brtalon_helm_plate_d_04', 'helm_mail_ahnqiraj_a_01']
RACES = {'hu', 'or', 'dw', 'ni', 'sc', 'ta', 'gn', 'tr', 'go', 'be'}
T = json.load(open('/mnt/Games/@project/wt-master-merge/ops/helm-refit-20261123/report.json'))['transforms']
ck = json.load(open(W / 'root-ckeys.json')); root = set(json.load(open('/tmp/claude-1000/-home-praxis-Projects/c41b4c2f-f4c2-4e21-8c6d-a961250d8864/scratchpad/root-ids-049a.json')))
lf = {}
for l in open('/mnt/Games/@project/listfiles/community-listfile.csv', errors='replace'):
i, _, p = l.rstrip('\n').partition(';'); lf[p.lower()] = int(i)
md5 = lambda b: hashlib.md5(b).hexdigest()
shutil.rmtree(H, ignore_errors=True); (H / 'src').mkdir(parents=True); (H / 'out').mkdir()
names = {}
for n, a in octo_mpq.archives():
try: lst = a.read('(listfile)').decode('latin1').splitlines()
except Exception: continue
for p in lst:
m = re.fullmatch(r'item\\objectcomponents\\head\\(.+)_([a-z]{2})([mf])\.m2', p.lower())
if m and m.group(1) in FAM and m.group(2) in RACES: names.setdefault(p.lower(), p)
rows = []
for low, p in sorted(names.items()):
raw = octo_mpq.read(p); sha = hashlib.sha256(raw).hexdigest(); (H / 'src' / f'{sha}.m2').write_bytes(raw)
rows.append(dict(member=low.replace('\\', '/'), archive='octo', sha256=sha, file=f'{sha}.m2'))
json.dump(dict(matches=rows), open(H / 'src/manifest.json', 'w'), indent=1)
kw = dict(allow_qualified_cutout_shader16=True, paired_single_texture_rule=True, convert_ribbons=True, convert_particles=True,
downgrade_hermite=True, convert_uv_animation=True, convert_lights=True, resample_step_visibility=True)
def tex_fdid(path):
raw = octo_mpq.read(path); h = md5(raw) if raw else None
if h and h in ck: return min(ck[h])
f = lf.get(path.lower().replace('\\', '/'))
return f if f in root else None
VT = np.dtype([('p', '<3f'), ('w', 'u1', 4), ('b', 'u1', 4), ('n', '<3f'), ('t', '<2f', 2)])
def refit(data, key):
t = T[key]; s_ = t['scale']; off = np.array(t['offset']); M = np.vstack([np.eye(3) * s_, off]); L = M[:3]; m0 = 8
n, o = struct.unpack_from('<II', data, m0 + 60)
v = np.frombuffer(bytes(data[m0 + o:m0 + o + 48 * n]), VT).copy()
v['p'] = (np.c_[v['p'], np.ones(n)] @ M).astype('<f4')
nn = v['n'] @ L; nn /= np.maximum(np.linalg.norm(nn, axis=1, keepdims=True), 1e-9); v['n'] = nn.astype('<f4')
data[m0 + o:m0 + o + 48 * n] = v.tobytes()
nb, ob = struct.unpack_from('<II', data, m0 + 44)
for i in range(nb):
b = m0 + ob + 88 * i; pv = np.array(struct.unpack_from('<3f', data, b + 76)); struct.pack_into('<3f', data, b + 76, *(s_ * pv + off))
if s_ != 1.0:
na, oa = struct.unpack_from('<II', data, b + 16 + 12)
for j in range(na):
nk, ok = struct.unpack_from('<II', data, m0 + oa + 8 * j)
for q in range(nk):
at = m0 + ok + 12 * q; struct.pack_into('<3f', data, at, *(s_ * np.array(struct.unpack_from('<3f', data, at))))
for o2off, stride, pos in ((240, 40, 8), (296, 492, 8), (288, 176, 8), (264, 156, 4)):
n2, o2 = struct.unpack_from('<II', data, m0 + o2off)
for i in range(n2):
at = m0 + o2 + stride * i + pos; p0 = np.array(struct.unpack_from('<3f', data, at)); struct.pack_into('<3f', data, at, *(s_ * p0 + off))
lo, hi = v['p'].min(0), v['p'].max(0)
struct.pack_into('<7f', data, m0 + 160, *lo, *hi, float(np.linalg.norm(hi - lo) / 2))
for mode, can in (('a', True), ('b', False)):
shutil.rmtree(H / f'conv{mode}', ignore_errors=True); c.batch(H / 'src/manifest.json', H / f'conv{mode}', canonicalize_rigid_views=can, **kw)
ra = {r['source_sha256']: r for r in json.load(open(H / 'conva/manifest.json'))['records']}
rb = {r['source_sha256']: r for r in json.load(open(H / 'convb/manifest.json'))['records']}
nxt = 8810400; art = []; helms = {}; blocked = []
for row in rows:
r, d = ra[row['sha256']], 'conva'
if not r['structural_conversion_complete']: r, d = rb[row['sha256']], 'convb'
if not r['structural_conversion_complete']: blocked.append((row['member'], r['blocked'])); continue
body = (H / d / f"{row['sha256']}.md20").read_bytes()
skins = [(H / d / o['file']).read_bytes() for o in r['outputs'] if o['role'] == 'native-skin']
n, o = struct.unpack_from('<II', body, 80); txid = []
for i in range(n):
k, _, ln, no = struct.unpack_from('<IIII', body, o + 16 * i)
txid.append((tex_fdid(body[no:no + ln].rstrip(b'\0').decode('latin1')) or -1) if k == 0 else 0)
if -1 in txid: blocked.append((row['member'], 'hardcoded texture not in client')); continue
m = re.fullmatch(r'item/objectcomponents/head/(.+)_([a-z]{2})([mf])\.m2', row['member']); fam, race, g = m.groups()
m2f = nxt; skf = list(range(nxt + 1, nxt + 1 + len(skins))); nxt += 1 + len(skins)
data = bytearray(model_container(body, skf, txid)); refit(data, race + g)
(H / 'out' / f'{m2f}.m2').write_bytes(bytes(data))
art.append(dict(file_data_id=m2f, path=row['member'], ckey=md5(bytes(data)), kind='M2', file=str(H / 'out' / f'{m2f}.m2')))
for v_, (f, sk) in enumerate(zip(skf, skins)):
(H / 'out' / f'{f}.skin').write_bytes(sk)
art.append(dict(file_data_id=f, path=row['member'][:-3] + f'{v_:02}.skin', ckey=md5(sk), kind='SKIN', file=str(H / 'out' / f'{f}.skin')))
helms.setdefault(fam, {})[f'{race}{g}'] = m2f
json.dump(dict(helms=helms, art=art, blocked=blocked), open(W / 'helms.json', 'w'), indent=1)
print('extracted', len(rows), 'helms', {k: len(v) for k, v in helms.items()}, 'blocked', len(blocked), blocked[:4])