37 lines
1.9 KiB
Python
37 lines
1.9 KiB
Python
"""Export complete current ItemRow rarity evidence for inventory LC candidates."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
|
|
p = argparse.ArgumentParser(description=__doc__)
|
|
p.add_argument('--log', type=Path, required=True)
|
|
p.add_argument('--inventory', type=Path, required=True)
|
|
p.add_argument('--client-catalog', type=Path, required=True)
|
|
p.add_argument('--output', type=Path, required=True)
|
|
a = p.parse_args()
|
|
raw = a.log.read_bytes()
|
|
text = raw.decode('utf-8', errors='replace')
|
|
expected = {row['id'] for row in json.loads(a.inventory.read_text(encoding='utf-8'))['lightcones']}
|
|
identity = json.loads(a.client_catalog.read_text(encoding='utf-8'))
|
|
if not re.fullmatch(r'[0-9a-f]{64}', identity.get('client_assembly_sha256', '')) or not identity.get('evidence_id'):
|
|
raise SystemExit('Client catalog provenance missing')
|
|
rows = {}
|
|
for id_text, rarity_text in re.findall(r'\[GAC_LOOT_RARITY\] id=(\d+) rarity=(\d+)', text):
|
|
item, rarity = int(id_text), int(rarity_text)
|
|
if item not in expected or item in rows or rarity not in (3, 4, 5):
|
|
raise SystemExit('Duplicate, invalid or unexpected captured LC')
|
|
rows[item] = rarity
|
|
if rows.keys() != expected or f'[GAC_LOOT_RARITY] END count={len(expected)}' not in text:
|
|
raise SystemExit('Incomplete capture')
|
|
resource = {
|
|
'format_version': 1,
|
|
'client_assembly_sha256': identity['client_assembly_sha256'],
|
|
'source': 'Current Client ItemHelper.GetItem(candidate ID).Row.Rarity, bounded non-battle capture; candidate IDs from InventoryItemConfig, no rarity inference from IDs',
|
|
'capture_sha256': hashlib.sha256(raw).hexdigest(),
|
|
'lightcones': [{'id': item, 'rarity': rows[item]} for item in sorted(rows)],
|
|
}
|
|
a.output.write_text(json.dumps(resource, indent=2) + '\n', encoding='utf-8')
|
|
print(json.dumps({'rows': len(rows), 'rarities': {r: sum(v == r for v in rows.values()) for r in (3, 4, 5)}}))
|