Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
import base64
import json
from pathlib import Path
import re
ppl_path = Path('MasterPlayerFileGradeLevel.ppl')
if not ppl_path.exists():
raise FileNotFoundError(f'Missing file: {ppl_path}. Place it in the script directory.')
with open(ppl_path, 'rb') as f:
raw = f.read()
record_size = 1008
if len(raw) % record_size != 0:
raise ValueError(f'File size {len(raw)} is not a multiple of {record_size}.')
records = []
for idx in range(len(raw) // record_size):
chunk = raw[idx*record_size:(idx+1)*record_size]
header = chunk[0:8].decode('ascii', errors='ignore')
name_bytes = chunk[8:8+32]
name = name_bytes.split(b'\x00', 1)[0].decode('ascii', errors='ignore').strip()
printable_fields = re.findall(rb'[ -~]{3,}', chunk)
found_strings = [s.decode('ascii', errors='ignore') for s in printable_fields]
# heuristic numeric fields
def u32(offset):
return int.from_bytes(chunk[offset:offset+4], 'little', signed=False)
rec = {
'index': idx+1,
'header': header,
'name': name or '',
'raw_base64': base64.b64encode(chunk).decode('ascii'),
'raw_hex_prefix': chunk[:48].hex(),
'field_0e_4': u32(0x0e),
'field_12_4': u32(0x12),
'field_16_4': u32(0x16),
'field_20_4': u32(0x20),
'strings': found_strings,
}
records.append(rec)
with open('clean_players.json', 'w', encoding='utf-8') as f:
json.dump(records, f, indent=2, ensure_ascii=False)
with open('clean_players_summary.txt', 'w', encoding='utf-8') as f:
f.write(f'Total records: {len(records)}\n')
for rec in records[:30]:
f.write(f"{rec['index']:4d}. {rec['name']} (header={rec['header']} string_count={len(rec['strings'])})\n")
print('Wrote clean_players.json and clean_players_summary.txt')