"""Read the single MarketCategory resource indexed in Win64/03, without game access."""
import importlib.util,json,pathlib,re,struct,sys
spec=importlib.util.spec_from_file_location('local_assets','research/galaxy_asset_inventory.py')
saved=sys.argv;sys.argv=['inventory','artifacts/galaxy-query-research/commodity-tree/unused.json']
assets=importlib.util.module_from_spec(spec);spec.loader.exec_module(assets);sys.argv=saved
out=pathlib.Path('artifacts/galaxy-query-research/commodity-tree');out.mkdir(parents=True,exist_ok=True)
for path in (assets.ROOT/'03').iterdir():
if not path.is_file():continue
with path.open('rb') as f:header=f.read(262)
if header[:4]!=b'FREA':continue
decoded=pow(int.from_bytes(header[6:262],'big'),assets.E,assets.N).to_bytes(256,'big');sep=decoded.find(b'\0',2)
if sep<10 or b'MarketCategory' not in decoded[sep+37:]:continue
raw=assets.decode(path);(out/(path.name+'.fres')).write_bytes(raw)
rows=[dict(offset=m.start(),text=m.group().decode()) for m in re.finditer(rb'[A-Za-z_$][A-Za-z0-9_.$:/ -]{3,}',raw)]
(out/'resource-strings.json').write_text(json.dumps(rows,indent=2),encoding='utf-8')
(out/'source.json').write_text(json.dumps(dict(path=str(path),bytes=len(raw)),indent=2),encoding='utf-8')
print(path.name,len(raw),json.dumps(rows[:20]));break
else:raise RuntimeError('Indexed MarketCategory resource not found')
"""Read the single MarketCategory resource indexed in Win64/03, without game access."""
import importlib.util,json,pathlib,re,struct,sys
spec=importlib.util.spec_from_file_location('local_assets','research/galaxy_asset_inventory.py')
saved=sys.argv;sys.argv=['inventory','artifacts/galaxy-query-research/commodity-tree/unused.json']
assets=importlib.util.module_from_spec(spec);spec.loader.exec_module(assets);sys.argv=saved
out=pathlib.Path('artifacts/galaxy-query-research/commodity-tree');out.mkdir(parents=True,exist_ok=True)
for path in (assets.ROOT/'03').iterdir():
if not path.is_file():continue
with path.open('rb') as f:header=f.read(262)
if header[:4]!=b'FREA':continue
decoded=pow(int.from_bytes(header[6:262],'big'),assets.E,assets.N).to_bytes(256,'big');sep=decoded.find(b'\0',2)
if sep<10 or b'MarketCategory' not in decoded[sep+37:]:continue
raw=assets.decode(path);(out/(path.name+'.fres')).write_bytes(raw)
rows=[dict(offset=m.start(),text=m.group().decode()) for m in re.finditer(rb'[A-Za-z_$][A-Za-z0-9_.$:/ -]{3,}',raw)]
(out/'resource-strings.json').write_text(json.dumps(rows,indent=2),encoding='utf-8')
(out/'source.json').write_text(json.dumps(dict(path=str(path),bytes=len(raw)),indent=2),encoding='utf-8')
print(path.name,len(raw),json.dumps(rows[:20]));break
else:raise RuntimeError('Indexed MarketCategory resource not found')