56 lines
3.4 KiB
Python
56 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""#124 Earthen Ring: stage a content child that replaces Faction.db2 (FDID 1361972, enUS) with the pallet-patched table.
|
|
|
|
compose.py --root DIR --parent FROZEN_PARENT_CANDIDATE --client LOCAL_CLIENT --after Faction.patched.db2
|
|
|
|
The parent's Faction.db2 is read from the frozen parent store and must equal the patch input (pallet_patch.py checks the
|
|
row diff). Builds pins/1361972 + components.json + selected-root.json and calls the shared compose_prepared pipeline.
|
|
The candidate stays OFFLINE_UNINSTALLED / HOLD.
|
|
"""
|
|
import argparse, hashlib, struct, sys
|
|
from pathlib import Path
|
|
OPS = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(OPS / 'addon_source_authority')); sys.path.insert(0, str(OPS))
|
|
from compose_content import compose_prepared, load, save, sha, module # noqa: E402
|
|
from casc_asset_package import root_groups # noqa: E402
|
|
|
|
FDID = 1361972
|
|
|
|
|
|
def main():
|
|
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
for n in ('root', 'parent', 'client', 'after'): p.add_argument('--' + n, type=Path, required=True)
|
|
p.add_argument('--before', type=Path, required=True, help='parent Faction.db2 (decoded) the patch was made from')
|
|
a = p.parse_args()
|
|
meta = load(a.parent / 'metadata.json'); raw = (a.parent / 'decoded/root.bin').read_bytes()
|
|
pin = dict(build_info_sha256=sha(a.client / '.build.info'), build_key=meta['key'], root_md5=hashlib.md5(raw).hexdigest())
|
|
if sha(a.parent / '.build.info.candidate') != pin['build_info_sha256']:
|
|
raise ValueError('LOCAL client is not on the frozen parent')
|
|
before = a.before.read_bytes(); after = a.after.read_bytes()
|
|
bmd5 = hashlib.md5(before).hexdigest(); amd5 = hashlib.md5(after).hexdigest()
|
|
cells = []
|
|
for g in root_groups(raw)['groups']:
|
|
ident = 0
|
|
for n, (d,) in enumerate(struct.iter_unpack('<I', raw[g['ids_offset']:g['ckeys_offset']])):
|
|
ident += d
|
|
if ident == FDID and g['locale'] & 2 and raw[g['ckeys_offset'] + 16 * n:g['ckeys_offset'] + 16 * n + 16].hex() == bmd5:
|
|
cells.append(g['ckeys_offset'] + 16 * n)
|
|
ident += 1
|
|
if len(cells) != 1: raise ValueError(f'unique enUS Faction.db2 cell with the parent ckey required, found {len(cells)}')
|
|
patched = bytearray(raw); patched[cells[0]:cells[0] + 16] = bytes.fromhex(amd5)
|
|
root = a.root; d = root / 'pins' / str(FDID); d.mkdir(parents=True, exist_ok=True)
|
|
(d / 'before.bin').write_bytes(before); (d / 'after.bin').write_bytes(after)
|
|
save(d / 'pin.json', dict(fdid=FDID, table='dbfilesclient/faction.db2', parent_root=pin['root_md5'],
|
|
original_decoded=dict(file='before.bin', md5=bmd5, sha256=sha(d / 'before.bin')),
|
|
after_decoded=dict(file='after.bin', md5=amd5, sha256=sha(d / 'after.bin'))))
|
|
save(root / 'components.json', [dict(type='wdc_enus', file=str(d / 'pin.json'), sha256=sha(d / 'pin.json'))])
|
|
save(root / 'selected-root.json', dict(parent_root=pin['root_md5'], parent_build=pin['build_key'],
|
|
parent_root_sha256=hashlib.sha256(raw).hexdigest(),
|
|
decoded_root_sha256=hashlib.sha256(patched).hexdigest()))
|
|
save(root / 'native-content-parent.json', pin); save(root / 'current-content-parent-path.json', [str(a.parent)])
|
|
compose_prepared(root, root, a.parent, a.client, pin)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|