63 lines
2.9 KiB
Python
63 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""2026-11-25 (Noctis crash, ERROR #135 "Invalid Choice ID 79143" in CharacterSelect_SelectCharacter):
|
|
the appearance profile must never send a ChrCustomizationChoice the client table lacks. The reviewed creator overrides
|
|
added 33 choices (79130..79166: extra Turtle hair/facial-hair variants) that no client build has as rows, so every
|
|
character using one (all Night Elf and Gnome males, some Dwarf/Human female/Undead female styles) crashed char select.
|
|
|
|
Rule: drop every profile Choice absent from the client's ChrCustomizationChoice dump, and every Conversion that targets
|
|
one (the same source value keeps its other, native conversions). Dropped choices are moved to overrides 'held_choices'
|
|
until real Choice+Element rows for them are ported into the client DB2s.
|
|
|
|
usage: drop_absent_choices.py <ChrCustomizationChoice dump tsv> [--check]
|
|
"""
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
OPS = Path(__file__).resolve().parent
|
|
HEADER = OPS.parent / 'include/gateway/character_creation_profile.hpp'
|
|
OVERRIDES = OPS / 'character_creation_profile_overrides.json'
|
|
CONV = r'(std::array<Conversion,)(\d+)(> Conversions\{\{\n)(.*?)(\}\};)'
|
|
CHOICE = r'(std::array<Choice,)(\d+)(> Choices\{\{\n)(.*?)(\}\};)'
|
|
|
|
|
|
def rows(body):
|
|
return [tuple(map(int, r.split(','))) for r in re.findall(r'\{([^{}]+)\}', body)]
|
|
|
|
|
|
def put(header, pattern, kept):
|
|
m = re.search(pattern, header, re.S)
|
|
body = ''.join(' {' + ','.join(map(str, r)) + '},\n' for r in kept)
|
|
return header[:m.start()] + m[1] + str(len(kept)) + m[3] + body + m[5] + header[m.end():]
|
|
|
|
|
|
def main(dump, check=False):
|
|
client = {int(m) for m in re.findall(r'(?m)^(\d+)\t', open(dump).read())}
|
|
header = HEADER.read_text()
|
|
choices = rows(re.search(CHOICE, header, re.S)[4])
|
|
conversions = rows(re.search(CONV, header, re.S)[4])
|
|
absent = {c[0] for c in choices if c[0] not in client} | {c[5] for c in conversions if c[5] not in client}
|
|
if check:
|
|
print('absent', sorted(absent))
|
|
return 1 if absent else 0
|
|
if not absent:
|
|
print('profile clean')
|
|
return 0
|
|
header = put(header, CONV, [c for c in conversions if c[5] not in absent])
|
|
header = put(header, CHOICE, [c for c in choices if c[0] not in absent])
|
|
HEADER.write_text(header)
|
|
ov = json.loads(OVERRIDES.read_text())
|
|
held = [c for c in ov['added_choices'] if c[0] in absent]
|
|
ov['added_choices'] = [c for c in ov['added_choices'] if c[0] not in absent]
|
|
ov['held_conversions'] = ov.get('held_conversions', []) + [c for c in ov['added_conversions'] if c[5] in absent]
|
|
ov['added_conversions'] = [c for c in ov['added_conversions'] if c[5] not in absent]
|
|
ov['held_choices'] = ov.get('held_choices', []) + held
|
|
OVERRIDES.write_text(json.dumps(ov, indent=2) + '\n')
|
|
print('dropped choices', len(absent), sorted(absent))
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main(sys.argv[1], '--check' in sys.argv[2:]))
|