24 lines
945 B
Python
24 lines
945 B
Python
"""Read a table/file from the parent frozen store by FDID (enUS group)."""
|
|
import struct, sys
|
|
from pathlib import Path
|
|
H = Path(__file__).resolve().parent; sys.path.insert(0, str(H))
|
|
import frozen_store as fs
|
|
_st = None
|
|
def store():
|
|
global _st
|
|
if _st is None: _st = fs.Store()
|
|
return _st
|
|
def get(fid):
|
|
st = store(); root = st.root; hits = []
|
|
for g in st.layout['groups']:
|
|
f = 0
|
|
for i, (d,) in enumerate(struct.iter_unpack('<I', memoryview(root)[g['ids_offset']:g['ckeys_offset']])):
|
|
f += d
|
|
if f == fid: hits.append((g, root[g['ckeys_offset'] + 16 * i:g['ckeys_offset'] + 16 * i + 16].hex()))
|
|
f += 1
|
|
en = [ck for g, ck in hits if g['locale'] & 2 and not g.get('flags1')] or [ck for g, ck in hits]
|
|
return st.read(en[0])[2]
|
|
if __name__ == '__main__':
|
|
for a in sys.argv[1:]:
|
|
fid, out = a.split('=', 1); Path(out).write_bytes(get(int(fid))); print(fid, out)
|