Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
import json
import re
from pathlib import Path
ppl_path = Path('MasterPlayerFileGradeLevel.ppl')
if not ppl_path.exists():
raise FileNotFoundError(f"Missing file: {ppl_path}. Put the .ppl file in this folder.")
raw = ppl_path.read_bytes()
record_size = 256
if len(raw) % record_size != 0:
raise ValueError(f"File size {len(raw)} is not a multiple of {record_size}.")
num_records = len(raw) // record_size
records = []
for i in range(num_records):
chunk = raw[i*record_size:(i+1)*record_size]
name_bytes = chunk.split(b'\x00', 1)[0]
name = name_bytes.decode('latin1', errors='ignore').strip()
# the data after the name (skip the null byte after name)
start = len(name_bytes) + 1
body = chunk[start:]
# find embedded ASCII strings (club, nationality, etc.)
strings = re.findall(rb'[A-Za-z][A-Za-z\-\s]{2,24}', body)
strings_decoded = [s.decode('latin1', errors='ignore').strip() for s in strings]
club = None
for s in strings_decoded:
if s and s.upper() != name.upper() and len(s) >= 3:
club = s
break
def le_int(offset, size=2):
return int.from_bytes(chunk[offset:offset+size], 'little', signed=False)
stat_start = min(32, len(chunk))
stats = {
'v1': le_int(stat_start, 2) if stat_start+2 <= len(chunk) else None,
'v2': le_int(stat_start+2, 2) if stat_start+4 <= len(chunk) else None,
'v3': le_int(stat_start+4, 2) if stat_start+6 <= len(chunk) else None,
'v4': le_int(stat_start+6, 2) if stat_start+8 <= len(chunk) else None,
}
rec = {
'index': i+1,
'name': name or '',
'club': club or '',
'strings': strings_decoded,
'stat_bytes': chunk[:32].hex(),
'stats': stats,
'raw_hex': chunk.hex(),
}
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[:200]:
f.write(f"{rec['index']:4d}. {rec['name']} club={rec['club']}\n")
print('Wrote clean_players.json (records=' + str(len(records)) + ') and clean_players_summary.txt')