Files

34 lines
2.2 KiB
Python

"""#74 Q103(5): Turtle aspects on the stance bar (Codex q103-stance-presentation candidate tables) on f28ed44a."""
import json, hashlib, struct, sys
from pathlib import Path
H = Path(__file__).resolve().parent; sys.path.insert(0, str(H))
import frozen_store as fs
md5 = lambda b: hashlib.md5(b).hexdigest(); sha = lambda b: hashlib.sha256(b).hexdigest()
WHY = 'Q103(5) Turtle/Snake/Viper aspects on stance bar: SpellMisc display bit (Attributes[2] 0x10) for 45649/45652, SpellShapeshift orders 7/8/9 + missing druid order rows'
store = fs.Store(); root = store.root; lay = store.layout; assert lay['root_md5'] == fs.ROOT
T = {1003144: 'SpellMisc', 1139929: 'SpellShapeshift'}
want = {f: [] for f in T}
for g in lay['groups']:
f = 0
for i, (d,) in enumerate(struct.iter_unpack('<I', memoryview(root)[g['ids_offset']:g['ckeys_offset']])):
f += d
if f in want: want[f].append((g, g['ckeys_offset'] + i * 16))
f += 1
patched = bytearray(root); pins = []
for fid, name in sorted(T.items()):
en = [(g, at) for g, at in want[fid] if g['locale'] & 2 and not g.get('flags1')]; assert len(en) == 1, (fid, len(en))
g, at = en[0]; ck = root[at:at + 16].hex(); old = store.read(ck)[2]
assert old == (H / 'in' / f'{name}.db2').read_bytes(), name
new = (H / 'out' / f'{name}.db2').read_bytes()
patched[at:at + 16] = bytes.fromhex(md5(new))
d = H / 'pins' / str(fid); d.mkdir(parents=True, exist_ok=True)
(d / 'before.bin').write_bytes(old); (d / 'after.bin').write_bytes(new)
pin = dict(fdid=fid, table=name, parent_root=fs.ROOT, selected_group={}, encrypted_original=False,
original_decoded=dict(file='before.bin', md5=ck, sha256=sha(old)),
after_decoded=dict(file='after.bin', md5=md5(new), sha256=sha(new)), reason=WHY)
(d / 'pin.json').write_text(json.dumps(pin, indent=1) + '\n')
pins.append(dict(file=str(d / 'pin.json'), sha256=sha((d / 'pin.json').read_bytes()), type='wdc_enus'))
(H / 'components.json').write_text(json.dumps(pins, indent=2) + '\n')
(H / 'selected-root.json').write_text(json.dumps(dict(parent_build=fs.BUILD, parent_root=fs.ROOT, decoded_root_sha256=sha(bytes(patched)), parent_root_sha256=sha(root)), indent=2) + '\n')
print('pins', len(pins))