Files

68 lines
3.1 KiB
Python

"""Pin the two LOCAL 32_48 terrain replacements against cccac96c."""
import hashlib
import json
import struct
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE.parents[0]))
import casc_asset_package as casc
BASE = Path('/mnt/Games/@project/gateway/runtime/continuation-20261113/claude-lane/content/faction124-cccac96c-frozen-candidate')
INPUT = Path('/mnt/Games/@project/editor-export-127')
sha = lambda raw: hashlib.sha256(raw).hexdigest()
md5 = lambda raw: hashlib.md5(raw).hexdigest()
def main():
meta = json.loads((BASE / 'metadata.json').read_text())
root = (BASE / 'decoded/root.bin').read_bytes()
layout = casc.root_groups(root)
assert meta['key'] == 'cccac96c42c324fd49b9ec88ccf305d6'
assert layout['root_md5'] == '49532bea4e5b96c419f424bf366cea3e'
patched = bytearray(root)
pins = []
for fdid, name in ((8555287, 'root.adt'), (8758024, 'obj0.adt')):
before = (INPUT / 'base' / name).read_bytes()
after = (INPUT / 'edited' / name).read_bytes()
controls = casc.root_controls_batch(root, layout, {fdid})[fdid]
selected = [row for row in controls if row['group']['locale'] & 2 and not row['group']['flags1']]
assert len(selected) == 1 and selected[0]['content_key'] == md5(before)
folder = HERE / 'pins' / str(fdid)
folder.mkdir(parents=True, exist_ok=True)
(folder / 'before.bin').write_bytes(before)
(folder / 'after.bin').write_bytes(after)
pin = dict(fdid=fdid, table='world/maps/azeroth/azeroth_32_48.' + name,
parent_root=layout['root_md5'], selected_group={},
original_decoded=dict(file='before.bin', md5=md5(before), sha256=sha(before)),
encrypted_original=False,
after_decoded=dict(file='after.bin', md5=md5(after), sha256=sha(after)),
reason='21bb LOCAL-only Noggit terrain extraction')
pin_file = folder / 'pin.json'
pin_file.write_text(json.dumps(pin, indent=2) + '\n')
pins.append(dict(file=str(pin_file), sha256=sha(pin_file.read_bytes()), type='wdc_enus'))
# The selected enUS cell is unique for each role in this parent ROOT.
found = []
for group in layout['groups']:
ident = 0
for i, (delta,) in enumerate(struct.iter_unpack('<I', root[group['ids_offset']:group['ckeys_offset']])):
ident += delta
if ident == fdid:
at = group['ckeys_offset'] + i * 16
if group['locale'] & 2 and root[at:at + 16].hex() == md5(before):
found.append(at)
break
ident += 1
assert len(found) == 1
patched[found[0]:found[0] + 16] = bytes.fromhex(md5(after))
(HERE / 'components.json').write_text(json.dumps(pins, indent=2) + '\n')
(HERE / 'selected-root.json').write_text(json.dumps(dict(parent_build=meta['key'],
parent_root=layout['root_md5'], decoded_root_sha256=sha(bytes(patched)),
parent_root_sha256=sha(root)), indent=2) + '\n')
print('pins', len(pins))
if __name__ == '__main__':
main()