549 lines
30 KiB
Python
549 lines
30 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate a source-pinned, self-contained character appearance profile.
|
|
|
|
Input exports are read-only reference data. This enables no native route and
|
|
never creates characters, installs data or accesses authentication/processes.
|
|
"""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import re
|
|
from pathlib import Path
|
|
import character_creation as contract
|
|
|
|
OVERRIDES = Path(__file__).with_name('character_creation_profile_overrides.json')
|
|
|
|
|
|
# (sex, Source style, native choice). The selected 70334 type-0 geometry
|
|
# matches the original CharHairGeosets row for each pair. Female style 16
|
|
# wraps to choice 1545. Male styles outside these two have no native choice.
|
|
GOBLIN_HAIR_CHOICES = (
|
|
(0, 0, 1474), (0, 12, 1456),
|
|
(1, 1, 1546), (1, 2, 1547), (1, 3, 1548), (1, 4, 1549),
|
|
(1, 5, 1550), (1, 6, 1551), (1, 7, 1552), (1, 8, 1553),
|
|
(1, 9, 1554), (1, 10, 1555), (1, 11, 1556), (1, 12, 1557),
|
|
(1, 13, 1558), (1, 14, 1559), (1, 15, 1560), (1, 16, 1545),
|
|
)
|
|
|
|
|
|
def goblin_hair_conversions(records):
|
|
"""Replace only the reviewed base or previously applied conversions."""
|
|
records = [tuple(row) for row in records]
|
|
if any(len(row) != 9 for row in records):
|
|
raise ValueError('Malformed conversion row')
|
|
if len({row[0] for row in records}) != len(records):
|
|
raise ValueError('Duplicate conversion ID')
|
|
if not any(row[1] == 9 and row[3] == 3 for row in records):
|
|
return records
|
|
original = {(1406, 9, 0, 3, 0, 1456, 0, 0, -1)}
|
|
original.update((1494 + style, 9, 1, 3, style, 1544 + style, 0, 0, -1)
|
|
for style in range(1, 17))
|
|
chosen = [(100248 + index, 9, sex, 3, style, choice, 0, 0, -1)
|
|
for index, (sex, style, choice) in enumerate(GOBLIN_HAIR_CHOICES)]
|
|
ids = {row[0] for row in original} | {row[0] for row in chosen}
|
|
styles = {(sex, style) for sex, style, _ in GOBLIN_HAIR_CHOICES}
|
|
previous = {row for row in records if row[0] in ids or
|
|
(row[1] == 9 and row[3] == 3 and (row[2], row[4]) in styles)}
|
|
if previous == set(chosen):
|
|
return records
|
|
if previous != original:
|
|
raise ValueError('Goblin hair conversion input differs from the reviewed rows')
|
|
return [row for row in records if row not in original] + chosen
|
|
|
|
|
|
NIGHT_ELF_HAIR_COLOR_CONVERSIONS = (
|
|
(100300, 4, 0, 4, 8, 79137, 0, 0, -1),
|
|
(100301, 4, 0, 4, 9, 79138, 0, 0, -1),
|
|
(100302, 4, 1, 4, 8, 79139, 0, 0, -1),
|
|
(100303, 4, 1, 4, 9, 79140, 0, 0, -1),
|
|
)
|
|
NIGHT_ELF_HAIR_COLOR_CHOICES = ((79137, 43), (79138, 43), (79139, 52), (79140, 52))
|
|
|
|
|
|
def night_elf_hair_color_relations(conversions, choices):
|
|
"""Add original Night Elf color 8/9 relations to the reviewed profile."""
|
|
conversions = [tuple(row) for row in conversions]
|
|
choices = [tuple(row) for row in choices]
|
|
if any(len(row) != 9 for row in conversions) or any(len(row) != 2 for row in choices):
|
|
raise ValueError('Malformed appearance relation row')
|
|
if len({row[0] for row in conversions}) != len(conversions):
|
|
raise ValueError('Duplicate conversion ID')
|
|
if len({row[0] for row in choices}) != len(choices):
|
|
raise ValueError('Duplicate choice ID')
|
|
conversion_by_id = {row[0]: row for row in conversions}
|
|
choice_by_id = {row[0]: row for row in choices}
|
|
expected_conversions = {row[0]: row for row in NIGHT_ELF_HAIR_COLOR_CONVERSIONS}
|
|
expected_choices = {row[0]: row for row in NIGHT_ELF_HAIR_COLOR_CHOICES}
|
|
for row_id, row in expected_conversions.items():
|
|
if row_id in conversion_by_id and conversion_by_id[row_id] != row:
|
|
raise ValueError('Night Elf hair color conversion ID conflicts with reviewed relation')
|
|
for row_id, row in expected_choices.items():
|
|
if row_id in choice_by_id and choice_by_id[row_id] != row:
|
|
raise ValueError('Night Elf hair color choice ID conflicts with reviewed relation')
|
|
conversions.extend(row for row in NIGHT_ELF_HAIR_COLOR_CONVERSIONS
|
|
if row[0] not in conversion_by_id)
|
|
choices.extend(row for row in NIGHT_ELF_HAIR_COLOR_CHOICES if row[0] not in choice_by_id)
|
|
return conversions, choices
|
|
|
|
|
|
def creator_profile_relations(conversions, choices, overrides=None):
|
|
"""Apply the reviewed original-client creator mappings idempotently.
|
|
|
|
The rows come from the consolidated creator review branch. Keep the exact
|
|
current-row preimages for the fourteen corrections so regenerated profiles
|
|
fail closed if their source conversions have changed.
|
|
"""
|
|
if overrides is None:
|
|
overrides = json.loads(OVERRIDES.read_text())
|
|
conversions = [tuple(row) for row in conversions]
|
|
choices = [tuple(row) for row in choices]
|
|
if any(len(row) != 9 for row in conversions) or any(len(row) != 2 for row in choices):
|
|
raise ValueError('Malformed creator appearance relation row')
|
|
conversion_by_id = {row[0]: row for row in conversions}
|
|
choice_by_id = {row[0]: row for row in choices}
|
|
if len(conversion_by_id) != len(conversions) or len(choice_by_id) != len(choices):
|
|
raise ValueError('Duplicate creator appearance relation ID')
|
|
|
|
for correction in overrides['replaced_conversions']:
|
|
before, after = tuple(correction['before']), tuple(correction['after'])
|
|
if before[0] != after[0]:
|
|
raise ValueError('Creator conversion correction changes identity')
|
|
current = conversion_by_id.get(before[0])
|
|
if current == before:
|
|
conversion_by_id[before[0]] = after
|
|
elif current != after:
|
|
raise ValueError('Creator conversion preimage differs from reviewed row')
|
|
|
|
for raw in overrides['added_conversions']:
|
|
row = tuple(raw)
|
|
current = conversion_by_id.get(row[0])
|
|
if current is not None and current != row:
|
|
raise ValueError('Creator conversion ID conflicts with reviewed relation')
|
|
conversion_by_id[row[0]] = row
|
|
|
|
for raw in overrides['added_choices']:
|
|
row = tuple(raw)
|
|
current = choice_by_id.get(row[0])
|
|
if current is not None and current != row:
|
|
raise ValueError('Creator choice ID conflicts with reviewed relation')
|
|
choice_by_id[row[0]] = row
|
|
|
|
conversions = sorted(conversion_by_id.values())
|
|
choices = sorted(choice_by_id.values())
|
|
known_choices = set(choice_by_id)
|
|
if any(row[5] not in known_choices for row in conversions):
|
|
raise ValueError('Creator conversion refers to an unknown choice')
|
|
return conversions, choices
|
|
|
|
|
|
def apply_creator_profile_relations(header, overrides=None):
|
|
"""Add the reviewed creator mappings to an existing complete profile."""
|
|
conversion_pattern = r'(std::array<Conversion,)(\d+)(> Conversions\{\{\n)(.*?)(\}\};)'
|
|
choice_pattern = r'(std::array<Choice,)(\d+)(> Choices\{\{\n)(.*?)(\}\};)'
|
|
conversion_match = re.search(conversion_pattern, header, re.S)
|
|
choice_match = re.search(choice_pattern, header, re.S)
|
|
if not conversion_match or not choice_match:
|
|
raise ValueError('Appearance profile arrays absent')
|
|
parse_rows = lambda body: [tuple(map(int, row.split(',')))
|
|
for row in re.findall(r'\{([^{}]+)\}', body)]
|
|
conversions, choices = parse_rows(conversion_match[4]), parse_rows(choice_match[4])
|
|
if len(conversions) != int(conversion_match[2]) or len(choices) != int(choice_match[2]):
|
|
raise ValueError('Appearance profile array count differs')
|
|
updated_conversions, updated_choices = creator_profile_relations(conversions, choices, overrides)
|
|
if conversions == updated_conversions and choices == updated_choices:
|
|
return header
|
|
def replace(match, rows):
|
|
body = ''.join(' {' + ','.join(map(str, row)) + '},\n' for row in rows)
|
|
return match[1] + str(len(rows)) + match[3] + body + match[5]
|
|
header = header[:conversion_match.start()] + replace(conversion_match, updated_conversions) + header[conversion_match.end():]
|
|
choice_match = re.search(choice_pattern, header, re.S)
|
|
return header[:choice_match.start()] + replace(choice_match, updated_choices) + header[choice_match.end():]
|
|
|
|
|
|
def apply_goblin_hair_relations(header):
|
|
"""Retain raw export pins and any local extensions already in the profile."""
|
|
match = re.search(r'(std::array<Conversion,)(\d+)(> Conversions\{\{\n)(.*?)(\}\};)', header, re.S)
|
|
if not match:
|
|
raise ValueError('Conversion array absent')
|
|
records = [tuple(map(int, row.split(','))) for row in re.findall(r'\{([^{}]+)\}', match[4])]
|
|
if len(records) != int(match[2]):
|
|
raise ValueError('Conversion array count differs')
|
|
converted = goblin_hair_conversions(records)
|
|
if records == converted:
|
|
return header
|
|
body = ''.join(' {' + ','.join(map(str, row)) + '},\n' for row in converted)
|
|
array = match[1] + str(len(converted)) + match[3] + body + match[5]
|
|
return header[:match.start()] + array + header[match.end():]
|
|
|
|
|
|
def apply_night_elf_hair_color_relations(header):
|
|
"""Append the paired Night Elf conversions and choices to a full profile."""
|
|
conversion_pattern = r'(std::array<Conversion,)(\d+)(> Conversions\{\{\n)(.*?)(\}\};)'
|
|
choice_pattern = r'(std::array<Choice,)(\d+)(> Choices\{\{\n)(.*?)(\}\};)'
|
|
conversion_match = re.search(conversion_pattern, header, re.S)
|
|
choice_match = re.search(choice_pattern, header, re.S)
|
|
if not conversion_match or not choice_match:
|
|
raise ValueError('Appearance profile arrays absent')
|
|
parse_rows = lambda body: [tuple(map(int, row.split(',')))
|
|
for row in re.findall(r'\{([^{}]+)\}', body)]
|
|
conversions = parse_rows(conversion_match[4])
|
|
choices = parse_rows(choice_match[4])
|
|
if len(conversions) != int(conversion_match[2]) or len(choices) != int(choice_match[2]):
|
|
raise ValueError('Appearance profile array count differs')
|
|
new_conversions, new_choices = night_elf_hair_color_relations(conversions, choices)
|
|
if conversions == new_conversions and choices == new_choices:
|
|
return header
|
|
def replace(match, rows):
|
|
body = ''.join(' {' + ','.join(map(str, row)) + '},\n' for row in rows)
|
|
return match[1] + str(len(rows)) + match[3] + body + match[5]
|
|
header = header[:conversion_match.start()] + replace(conversion_match, new_conversions) + header[conversion_match.end():]
|
|
# The conversion replacement changes byte offsets, so locate Choices again.
|
|
choice_match = re.search(choice_pattern, header, re.S)
|
|
return header[:choice_match.start()] + replace(choice_match, new_choices) + header[choice_match.end():]
|
|
|
|
|
|
# (sex, Source style, native choice). The selected 70334 type-0 geometry
|
|
# matches the original CharHairGeosets row for each pair. Female style 16
|
|
# wraps to choice 1545. Male styles outside these two have no native choice.
|
|
GOBLIN_HAIR_CHOICES = (
|
|
(0, 0, 1474), (0, 12, 1456),
|
|
(1, 1, 1546), (1, 2, 1547), (1, 3, 1548), (1, 4, 1549),
|
|
(1, 5, 1550), (1, 6, 1551), (1, 7, 1552), (1, 8, 1553),
|
|
(1, 9, 1554), (1, 10, 1555), (1, 11, 1556), (1, 12, 1557),
|
|
(1, 13, 1558), (1, 14, 1559), (1, 15, 1560), (1, 16, 1545),
|
|
)
|
|
|
|
|
|
def goblin_hair_conversions(records):
|
|
"""Replace only the reviewed base or previously applied conversions."""
|
|
records = [tuple(row) for row in records]
|
|
if any(len(row) != 9 for row in records):
|
|
raise ValueError('Malformed conversion row')
|
|
if len({row[0] for row in records}) != len(records):
|
|
raise ValueError('Duplicate conversion ID')
|
|
if not any(row[1] == 9 and row[3] == 3 for row in records):
|
|
return records
|
|
original = {(1406, 9, 0, 3, 0, 1456, 0, 0, -1)}
|
|
original.update((1494 + style, 9, 1, 3, style, 1544 + style, 0, 0, -1)
|
|
for style in range(1, 17))
|
|
chosen = [(100248 + index, 9, sex, 3, style, choice, 0, 0, -1)
|
|
for index, (sex, style, choice) in enumerate(GOBLIN_HAIR_CHOICES)]
|
|
ids = {row[0] for row in original} | {row[0] for row in chosen}
|
|
styles = {(sex, style) for sex, style, _ in GOBLIN_HAIR_CHOICES}
|
|
previous = {row for row in records if row[0] in ids or
|
|
(row[1] == 9 and row[3] == 3 and (row[2], row[4]) in styles)}
|
|
if previous == set(chosen):
|
|
return records
|
|
if previous != original:
|
|
raise ValueError('Goblin hair conversion input differs from the reviewed rows')
|
|
return [row for row in records if row not in original] + chosen
|
|
|
|
|
|
def apply_goblin_hair_relations(header):
|
|
"""Retain raw export pins and any local extensions already in the profile."""
|
|
match = re.search(r'(std::array<Conversion,)(\d+)(> Conversions\{\{\n)(.*?)(\}\};)', header, re.S)
|
|
if not match:
|
|
raise ValueError('Conversion array absent')
|
|
records = [tuple(map(int, row.split(','))) for row in re.findall(r'\{([^{}]+)\}', match[4])]
|
|
if len(records) != int(match[2]):
|
|
raise ValueError('Conversion array count differs')
|
|
converted = goblin_hair_conversions(records)
|
|
if records == converted:
|
|
return header
|
|
body = ''.join(' {' + ','.join(map(str, row)) + '},\n' for row in converted)
|
|
array = match[1] + str(len(converted)) + match[3] + body + match[5]
|
|
return header[:match.start()] + array + header[match.end():]
|
|
|
|
|
|
def add_gnome_skin_faces(conversions, choices, sections):
|
|
"""Restore missing upper-face choices for the sixth original Gnome skin."""
|
|
result = list(map(tuple, conversions))
|
|
parents = {r['ID']: r['ChrCustomizationOptionID'] for r in choices}
|
|
bindings = ((1, 86, 1246, 100345, (0, 3, 5)),
|
|
(0, 81, 1185, 100342, (0, 2, 3)))
|
|
for sex, option, first_choice, first_id, faces in bindings:
|
|
original = {(r['section'], r['variation']) for r in sections if
|
|
(r['race'], r['sex'], r['color'], r['flags']) == (7, sex, 5, 0)}
|
|
if (0, 0) not in original:
|
|
continue
|
|
for ident, face in enumerate(faces, first_id):
|
|
choice = first_choice + face
|
|
mapping = (7, sex, 2, face, choice, 1)
|
|
if (1, face) not in original or parents.get(choice) != option:
|
|
raise ValueError('Missing original Gnome face or native face choice')
|
|
if not any(row[1:] == mapping + (0, -1) for row in result):
|
|
raise ValueError('Unexpected base Gnome face relation')
|
|
target = (ident,) + mapping + (5, -1)
|
|
existing = [r for r in result if r[0] == ident or
|
|
(r[1:5] == target[1:5] and r[6:8] == (1, 5)
|
|
and parents.get(r[5]) == option)]
|
|
if not existing:
|
|
result.append(target)
|
|
elif existing != [target]:
|
|
raise ValueError('Conflicting Gnome skin-specific face relation')
|
|
return result
|
|
|
|
|
|
def add_reviewed_face_dependencies(conversions, choices, sections):
|
|
"""Bind the reviewed Dwarf, Tauren and Troll face pairs on their authored skins."""
|
|
result = list(map(tuple, conversions))
|
|
parents = dict(choices)
|
|
authored = {(r['race'], r['sex'], r['section'], r['variation'], r['color'])
|
|
for r in sections if r['flags'] == 0}
|
|
for raw in json.loads(OVERRIDES.read_text())['added_conversions']:
|
|
row = tuple(raw)
|
|
ident, race, sex, field, face, choice, dependency, skin, discriminator = row
|
|
if not 100500 <= ident <= 100557 or (race, sex, 0, 0, skin) not in authored:
|
|
continue
|
|
if (field, dependency, discriminator) != (2, 1, -1) or (race, sex, 1, face, skin) not in authored:
|
|
raise ValueError('Skin-dependent face lacks its original face section')
|
|
if choice not in parents or not any(
|
|
r[1:6] == row[1:6] and r[6] == 1 and r[7] != skin for r in result):
|
|
raise ValueError('Missing native choice or existing sibling skin relation')
|
|
matched = [r for r in result if r[0] == ident or
|
|
(r[1:5] == row[1:5] and parents.get(r[5]) == parents[choice]
|
|
and (r[6] == 0 or r[6:8] == (1, skin)))]
|
|
if not matched:
|
|
result.append(row)
|
|
elif matched != [row]:
|
|
raise ValueError('Conflicting skin-dependent face conversion')
|
|
return result
|
|
|
|
|
|
def original_beard_relations(conversions, choices, facial):
|
|
"""Use each staged beard selector with the corresponding neutral eyebrow option."""
|
|
conversions = list(map(tuple, conversions))
|
|
choices = list(map(tuple, choices))
|
|
indexed = dict(choices)
|
|
for race, count, template, option, first_choice, first_id, brow_option, base_rows in (
|
|
(7, 12, 78867, 9486, 79155, 100326, 784,
|
|
tuple(zip(range(4952, 4967, 2), (8765, 8766, 8767, 8768, 8769, 8770, 8766, 8767)))),
|
|
(4, 14, 78908, 9490, 79141, 100304, 738,
|
|
tuple(zip(range(4657, 4651, -1), (8091, 8083, 8083, 8084, 8085, 8086)))),
|
|
):
|
|
domain = {v for r, sex, v in facial if (r, sex) == (race, 0)}
|
|
if not domain:
|
|
continue
|
|
neutral_brow = base_rows[0][1]
|
|
if domain != set(range(count)) or indexed.get(template) != option or indexed.get(neutral_brow) != brow_option:
|
|
raise ValueError('Unexpected facial-hair domain or native option')
|
|
original = [(row_id, race, 0, 5, i, brow, 0, 0, -1)
|
|
for i, (row_id, brow) in enumerate(base_rows)]
|
|
neutral = [row[:5] + (neutral_brow,) + row[6:] for row in original]
|
|
additions = []
|
|
for variant in range(count):
|
|
beard = first_choice + variant
|
|
if beard not in indexed:
|
|
choices.append((beard, option))
|
|
indexed[beard] = option
|
|
elif indexed[beard] != option:
|
|
raise ValueError('Beard choice ID belongs to another option')
|
|
for choice in ((beard,) if variant < len(original) else (neutral_brow, beard)):
|
|
additions.append((first_id + len(additions), race, 0, 5, variant, choice, 0, 0, -1))
|
|
ids = {row[0] for row in neutral + additions}
|
|
selected = [row for row in conversions if row[0] in ids or row[1:4] == (race, 0, 5)]
|
|
if sorted(selected) == sorted(neutral + additions):
|
|
continue
|
|
if sorted(selected) != sorted(original):
|
|
raise ValueError('Beard conversion input differs from reviewed rows')
|
|
replacements = {row[0]: row for row in neutral}
|
|
conversions = [replacements.get(row[0], row) for row in conversions] + additions
|
|
return conversions, choices
|
|
|
|
|
|
def night_elf_color_faces(conversions, choices, sections):
|
|
"""Apply the original hair colors 8/9 and distinguish face 0 on male skins 9/10."""
|
|
choices = list(map(tuple, choices))
|
|
result = list(map(tuple, conversions))
|
|
indexed = dict(choices)
|
|
for sex, option, donor in ((0, 43, 749), (1, 52, 858)):
|
|
colors = {r['color'] for r in sections if
|
|
(r['race'], r['sex'], r['section'], r['flags']) == (4, sex, 3, 0)}
|
|
if not colors:
|
|
continue
|
|
if not {8, 9} <= colors or indexed.get(donor) != option:
|
|
raise ValueError('Unexpected original Night Elf hair colors or native parent')
|
|
for i in range(2):
|
|
index = 2*sex + i
|
|
choice = 79137 + index
|
|
if choice not in indexed:
|
|
choices.append((choice, option))
|
|
elif indexed[choice] != option:
|
|
raise ValueError('Night Elf hair choice belongs to another option')
|
|
row = (100300 + index, 4, sex, 4, 8 + i, choice, 0, 0, -1)
|
|
matches = [r for r in result if r[0] == row[0] or r[1:5] == row[1:5]]
|
|
if not matches:
|
|
result.append(row)
|
|
elif matches != [row]:
|
|
raise ValueError('Conflicting Night Elf hair color relation')
|
|
eligible_faces = {(r['color'], r['variation']) for r in sections if
|
|
(r['race'], r['sex'], r['section'], r['flags']) == (4, 0, 1, 0)}
|
|
for i, row in enumerate(result):
|
|
if row[0] in (7773, 7774):
|
|
skin = row[0] - 7764
|
|
if row[1:5] != (4, 0, 2, 0) or row[5] not in (719, 728) or row[6:] != (1, skin, -1):
|
|
raise ValueError('Unexpected Night Elf face relation')
|
|
if (skin, 0) not in eligible_faces or indexed.get(719) != 41 or indexed.get(728) != 41:
|
|
raise ValueError('Missing original Night Elf face or native face option')
|
|
result[i] = row[:5] + (719,) + row[6:]
|
|
return result, choices
|
|
|
|
|
|
def staged_hair_and_dwarf_beards(conversions, choices, hair, facial):
|
|
"""Bind staged Human and Undead hairstyles and the three parts of each original Dwarf beard."""
|
|
result = list(map(tuple, conversions))
|
|
indexed = dict(choices)
|
|
additions = []
|
|
options = {}
|
|
for race, first_style, first_choice, option, first_row in (
|
|
(1, 24, 79132, 16, 100268),
|
|
(5, 15, 79130, 65, 100266),
|
|
):
|
|
styles = {style for r, sex, style in hair if (r, sex) == (race, 1)}
|
|
if not styles:
|
|
continue
|
|
if not {first_style, first_style + 1} <= styles:
|
|
raise ValueError('Missing original hair geosets')
|
|
for offset in range(2):
|
|
choice = first_choice + offset
|
|
options[choice] = option
|
|
additions.append((first_row + offset, race, 1, 3, first_style + offset, choice, 0, 0, -1))
|
|
if any((race, sex) == (3, 0) for race, sex, _ in facial):
|
|
styles = {style for race, sex, style in facial if (race, sex) == (3, 0)}
|
|
if not set(range(11, 21)) <= styles:
|
|
raise ValueError('Missing original Dwarf facial styles')
|
|
options.update({79134: 34, 79135: 34, 79136: 936})
|
|
# Preserve the staged conversion IDs. Style 11 was the last model added.
|
|
for index, style in enumerate((*range(12, 21), 11)):
|
|
beard = 79135 if style == 11 else 79134
|
|
moustache = {11: 79136, 12: 15450}.get(style, 15441 + style - 13)
|
|
if indexed.get(15451) != 937 or (style != 11 and indexed.get(moustache) != 936):
|
|
raise ValueError('Unexpected Dwarf facial component option')
|
|
for slot, choice in enumerate((beard, moustache, 15451)):
|
|
additions.append((100270 + 3 * index + slot, 3, 0, 5, style, choice, 0, 0, -1))
|
|
for choice, option in options.items():
|
|
if indexed.setdefault(choice, option) != option:
|
|
raise ValueError('Staged choice belongs to another option')
|
|
ids = {row[0] for row in additions}
|
|
selectors = {row[1:5] for row in additions}
|
|
existing = [row for row in result if row[0] in ids or row[1:5] in selectors]
|
|
if any(row not in additions for row in existing) or len(set(existing)) != len(existing):
|
|
raise ValueError('Conflicting hairstyle or Dwarf beard conversion')
|
|
result.extend(row for row in additions if row not in existing)
|
|
return result, list(indexed.items())
|
|
|
|
|
|
def reapply_appearance_relations(header):
|
|
"""Preserve source export hashes and existing local profile extensions."""
|
|
def records(name):
|
|
match = re.search(r'std::array<\w+,(\d+)> ' + name + r'\{\{\n(.*?)\}\};', header, re.S)
|
|
if not match:
|
|
raise ValueError(f'Missing {name} array')
|
|
rows = [tuple(map(int, row.split(','))) for row in re.findall(r'\{([^{}]+)\}', match[2])]
|
|
if len(rows) != int(match[1]):
|
|
raise ValueError(f'{name} row count differs')
|
|
return match, rows
|
|
|
|
match, current = records('Conversions')
|
|
choices = [dict(zip(('ID', 'ChrCustomizationOptionID'), row)) for row in records('Choices')[1]]
|
|
sections = [dict(zip(('id', 'race', 'sex', 'section', 'variation', 'color', 'flags'), row))
|
|
for row in records('Sections')[1]]
|
|
updated = add_gnome_skin_faces(goblin_hair_conversions(current), choices, sections)
|
|
choice_match, choice_rows = records('Choices')
|
|
updated, updated_choices = original_beard_relations(updated, choice_rows, records('FacialHair')[1])
|
|
updated, updated_choices = night_elf_color_faces(updated, updated_choices, sections)
|
|
updated, updated_choices = staged_hair_and_dwarf_beards(
|
|
updated, updated_choices, records('HairGeosets')[1], records('FacialHair')[1])
|
|
updated = add_reviewed_face_dependencies(updated, updated_choices, sections)
|
|
# Replace from the end so original match positions stay valid.
|
|
for block, before, after in ((choice_match, choice_rows, updated_choices), (match, current, updated)):
|
|
if before != after:
|
|
body = ''.join(' {' + ','.join(map(str, row)) + '},\n' for row in after)
|
|
header = (header[:block.start(1)] + str(len(after)) + header[block.end(1):block.start(2)]
|
|
+ body + header[block.end(2):])
|
|
return header
|
|
|
|
|
|
def add_female_piercings(conversions, choices, facial_rows):
|
|
"""Bind the original Orc and Dwarf facial settings to their native piercing choices."""
|
|
return _add_facial_choices(conversions, choices, facial_rows, FEMALE_PIERCINGS)
|
|
|
|
|
|
FEMALE_PIERCINGS = ((2, 1, 9495, 78943, 100221, 7), (3, 1, 9496, 78950, 100228, 6))
|
|
MALE_BEARDS = ((1, 0, 9494, 78934, 100201, 9), (2, 0, 9493, 78923, 100210, 11))
|
|
|
|
|
|
def _add_facial_choices(conversions, choices, facial_rows, groups):
|
|
parents = {row['ID']: row['ChrCustomizationOptionID'] for row in choices}
|
|
settings = {(row['race'], row['sex'], row['variation']) for row in facial_rows}
|
|
result = list(map(tuple, conversions))
|
|
for race, sex, option, first_choice, first_id, count in groups:
|
|
if not any(parents.get(first_choice + i) == option for i in range(count)):
|
|
continue
|
|
for value in range(count):
|
|
choice = first_choice + value
|
|
if parents.get(choice) != option or (race, sex, value) not in settings:
|
|
raise ValueError('Facial choice or original facial setting differs')
|
|
row = (first_id + value, race, sex, 5, value, choice, 0, 0, -1)
|
|
matches = [r for r in result if r[0] == row[0] or
|
|
(r[1] == race and r[2] in (-1, sex) and r[5] == choice)]
|
|
if not matches:
|
|
result.append(row)
|
|
elif matches != [row]:
|
|
raise ValueError('Conflicting facial choice conversion')
|
|
return result
|
|
|
|
|
|
def prepare(directory,output):
|
|
get=lambda name:json.loads((directory/name).read_text())
|
|
values={n:get(n) for n in ['ChrCustomizationConversion.json','ChrCustomizationChoice.json','source-charsections.json','source-facial-hair.json','source-hair-geosets.json']}
|
|
schema=contract.AppearanceSchema(*values.values())
|
|
pins={name:hashlib.sha256((directory/name).read_bytes()).hexdigest() for name in values}
|
|
rows=[]
|
|
def array(kind,name,records):
|
|
rows.append('inline constexpr std::array<'+kind+','+str(len(records))+'> '+name+'{{')
|
|
rows.extend(' {'+','.join(str(v) for v in record)+'},' for record in records)
|
|
rows.append('}};')
|
|
rows+=['// Generated exact appearance relation profile; no implicit defaults or eligibility aliases.',
|
|
'#pragma once','#include "gateway/character_creation.hpp"',
|
|
'namespace gateway::character_creation::profile {']
|
|
for index,(name,pin) in enumerate(pins.items()):rows.append('inline constexpr char InputSha'+str(index)+'[]="'+pin+'"; // '+name)
|
|
conversions = goblin_hair_conversions([[r[k] for k in ['ID','ChrRacesID','Sex','OptionID','Data','ChrCustomizationChoiceID','DependentOptionID','DependentData','Field_3_4_0_45166_007']] for r in values['ChrCustomizationConversion.json']])
|
|
conversions = _add_facial_choices(conversions, values['ChrCustomizationChoice.json'],
|
|
values['source-facial-hair.json'], FEMALE_PIERCINGS + MALE_BEARDS)
|
|
conversions = add_gnome_skin_faces(conversions, values['ChrCustomizationChoice.json'],
|
|
values['source-charsections.json'])
|
|
choices = [(r['ID'], r['ChrCustomizationOptionID']) for r in values['ChrCustomizationChoice.json']]
|
|
facial = [(r['race'], r['sex'], r['variation']) for r in values['source-facial-hair.json']]
|
|
conversions, choices = original_beard_relations(conversions, choices, facial)
|
|
conversions, choices = night_elf_color_faces(conversions, choices, values['source-charsections.json'])
|
|
hair = [(r['race'], r['sex'], r['variation']) for r in values['source-hair-geosets.json']]
|
|
conversions, choices = staged_hair_and_dwarf_beards(conversions, choices, hair, facial)
|
|
conversions = add_reviewed_face_dependencies(conversions, choices, values['source-charsections.json'])
|
|
array('Conversion','Conversions',conversions)
|
|
array('Choice','Choices',choices)
|
|
array('Section','Sections',[[r[k] for k in ['id','race','sex','section','variation','color','flags']] for r in values['source-charsections.json']])
|
|
for filename,name in [('source-facial-hair.json','FacialHair'),('source-hair-geosets.json','HairGeosets')]:array('Hair',name,[[r[k] for k in ['race','sex','variation']] for r in values[filename]])
|
|
rows+=['} // namespace gateway::character_creation::profile','']
|
|
text='\n'.join(rows);output.parent.mkdir(parents=True,exist_ok=True);output.write_text(text)
|
|
report={'input_sha256':pins,'header_sha256':hashlib.sha256(text.encode()).hexdigest(),'native_conversion_rows':len(conversions),'native_choice_rows':len(choices),'source_section_rows':len(values['source-charsections.json']),'source_facial_rows':len(values['source-facial-hair.json']),'source_hair_rows':len(values['source-hair-geosets.json']),'held_conversion_rows':schema.held_conversion_rows,'eligibility_embedded':False,'no_route_enabled':True}
|
|
(directory/'profile-generation.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
return report
|
|
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser(description=__doc__)
|
|
source=parser.add_mutually_exclusive_group(required=True)
|
|
source.add_argument('--input-dir', type=Path)
|
|
source.add_argument('--source-profile', type=Path, help='Reapply relations to an existing complete profile, retaining its other local extensions.')
|
|
parser.add_argument('--output',type=Path,required=True)
|
|
args=parser.parse_args()
|
|
if args.source_profile:
|
|
text=reapply_appearance_relations(args.source_profile.read_text())
|
|
args.output.parent.mkdir(parents=True,exist_ok=True)
|
|
args.output.write_text(text)
|
|
return
|
|
result=prepare(args.input_dir,args.output)
|
|
print('Generated exact appearance profile: '+str(result['native_conversion_rows'])+' conversion rows; '+str(len(result['held_conversion_rows']))+' signed-sex rows held.')
|
|
if __name__=='__main__':main()
|