Files

55 lines
4.2 KiB
Python

"""#52 (2026-11-25): High Elf SD bodies = Octo Character\\BloodElf\\{Male,Female} models converted onto the native SD Blood Elf
FDIDs (117170/116921 + their skin FDIDs). The Classic store's own SD Blood Elf (never used by Classic) renders broken
(sideways pose, CreatureModelData 2208 box 1.4 deep); Octo's model is what Octo players see. Same pipeline as
content-gomodels (MD20 v256 -> m2_equipment_convert -> sequence hash -> MD21). Replaceable texture slots stay replaceable.
usage: build_body.py <out-dir> -> <out>/<fdid>.m2|.skin + bodies.json"""
import json, struct, sys, hashlib, shutil
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')
sys.path.insert(0, '/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/sdrace-f59e-20261125')
from casc_asset_package import model_container
import m2_equipment_convert as c, octo_mpq, frozen_store as fs
# Load only this helper from the owning checkout; external build inputs keep
# their existing import paths. A stale master checkout must not supply hashing.
import importlib.util
_sequence_hash_spec = importlib.util.spec_from_file_location(
"_owned_m2_sequence_hash", Path(__file__).resolve().parents[1] / "m2_sequence_hash.py")
_sequence_hash_module = importlib.util.module_from_spec(_sequence_hash_spec)
_sequence_hash_spec.loader.exec_module(_sequence_hash_module)
native_sequence_hash = _sequence_hash_module.native_sequence_hash
md5 = lambda b: hashlib.md5(b).hexdigest(); sha = lambda b: hashlib.sha256(b).hexdigest()
OUT = Path(sys.argv[1]); shutil.rmtree(OUT, ignore_errors=True); OUT.mkdir(parents=True)
BODIES = {'Character\\BloodElf\\Male\\BloodElfMale.m2': (117170, [469848, 469869]),
'Character\\BloodElf\\Female\\BloodElfFemale.m2': (116921, [469824, 469830])}
NEXT = [8840600]
src = OUT / 'src'; src.mkdir(); rows = []
for member in BODIES:
raw = bytearray(octo_mpq.read(member)); assert raw[:4] == b'MD20', member
struct.pack_into('<II', raw, 292, 0, 0); struct.pack_into('<II', raw, 300, 0, 0) # portrait cameras stripped (converter contract)
h = sha(raw); (src / f'{h}.m2').write_bytes(raw)
rows.append(dict(member=member, archive='octo', sha256=h, file=f'{h}.m2', magic='MD20', version=struct.unpack_from('<I', raw, 4)[0], fixups=[]))
json.dump(dict(matches=rows), open(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, drop_unreachable_events=True,
two_texture_rule=True, character=True)
res = {}
for mode in (True, False):
d = OUT / ('conva' if mode else 'convb')
for r in c.batch(src / 'manifest.json', d, canonicalize_rigid_views=mode, **kw)['records']:
if r['source_sha256'] not in res or (not res[r['source_sha256']][0]['structural_conversion_complete'] and r['structural_conversion_complete']):
res[r['source_sha256']] = (r, d)
bodies = {}
for member, (m2f, native_skins) in BODIES.items():
r, d = res[next(x['sha256'] for x in rows if x['member'] == member)]
if not r['structural_conversion_complete']:
bodies[member] = dict(blocked=r.get('blocked') or r.get('blockers')); continue
body, hashed = native_sequence_hash((d / (r['source_sha256'] + '.md20')).read_bytes())
skins = [(d / o['file']).read_bytes() for o in r['outputs'] if o['role'] == 'native-skin']
skfs = [native_skins[v] if v < len(native_skins) else (NEXT.__setitem__(0, NEXT[0] + 1) or NEXT[0] - 1) for v in range(len(skins))]
n, o = struct.unpack_from('<II', body, 80); types = [struct.unpack_from('<I', body, o + 16 * i)[0] for i in range(n)]
assert all(t != 0 for t in types), ('hardcoded textures need FDIDs', member, types)
m2 = model_container(body, skfs, [0] * n); (OUT / f'{m2f}.m2').write_bytes(m2)
for f, s in zip(skfs, skins): (OUT / f'{f}.skin').write_bytes(s)
bodies[member] = dict(m2=m2f, skins=skfs, texture_types=types, sequence_hash_rebuilt=hashed, box=list(struct.unpack_from('<6f', body, 0xA0)))
json.dump(bodies, open(OUT / 'bodies.json', 'w'), indent=1); print(json.dumps(bodies))