Files

79 lines
3.5 KiB
Python

"""Compose the verified LOCAL creator with the Source Undead facial-feature groups."""
import argparse
import hashlib
import sys
from pathlib import Path
OPS = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(OPS))
from source_appearance_groups import groups, render_solver
PARENT_SHA256 = 'cb2b2d41ff8d2f2c920b585b35978ede495effb00967f98850d48e1283425d05'
def compose(raw):
if hashlib.sha256(raw).hexdigest() != PARENT_SHA256:
raise ValueError('Expected the verified enUS 70334 CharacterCreate.lua, FDID 8209459')
profiles, _ = groups()
faces = {}
for key in (10, 11):
profile = profiles[key]
fields = {option: field for option, field in profile['fields'].items() if field == 5}
faces[key] = [fields, [], [], profile['groups'][2]]
solver = render_solver(faces)
select = """
local function GW_SourceUndeadFeatures(data)
if not GW_SourceSingleNameCreation() or type(data) ~= "table" then return; end
local race, sex = C_CharacterCreation.GetSelectedRace(), C_CharacterCreation.GetSelectedSex();
if race ~= 5 or (sex ~= 0 and sex ~= 1) then return; end
local fields, options = GW_SourceAppearanceGroups[10 + sex][1], GW_SourceAppearanceOptions(data);
for id in pairs(fields) do if not options[id] then return; end end
return fields;
end
"""
text = raw.decode()
def replace(old, new):
nonlocal text
if text.count(old) != 1:
raise ValueError('Expected unique creator anchor: ' + old.splitlines()[0])
text = text.replace(old, new, 1)
begin = 'local function GW_SourceDirectCreate(name)'
replace(begin, 'local GW_SourceCorrelateCustomizations;\nlocal GW_SourcePreferredChoice;\n' + solver + select + begin)
stage = ' if api(5, race + class * 256 + sex * 65536, 0)'
replace(stage, ''' local data = C_CharacterCreation.GetAvailableCustomizations();
if GW_SourceUndeadFeatures(data) then
local _, _, reason = GW_SourceCorrelateCustomizations(data, nil, 3, true);
if reason then return false, "appearance"; end
end
''' + stage)
replace('ipairs(C_CharacterCreation.GetAvailableCustomizations() or {})', 'ipairs(data or {})')
anchor = ' local changed = false;\n for _, category in ipairs(data) do'
replace(anchor, ''' local changed = false;
local featureOptions = GW_SourceUndeadFeatures(data);
if featureOptions then
local reason;
data, changed, reason = GW_SourceCorrelateCustomizations(data, GW_SourcePreferredChoice, 3);
if reason then return data, changed, reason; end
end
for _, category in ipairs(data) do''')
replace('if sourceOption and #kept > 0 then',
'if sourceOption and #kept > 0 and not (featureOptions and featureOptions[option.id]) then')
callback = 'function CharacterCreateMixin:SetCustomizationChoice(optionID, choiceID)\n'
replace(callback, callback + '\tGW_SourcePreferredChoice = {optionID, choiceID};\n')
end = '\tself:UpdateCharCustomizationFrame();\nend\n\nfunction CharacterCreateMixin:ResetCustomizationPreview'
replace(end, end.replace('\nend', '\n\tGW_SourcePreferredChoice = nil;\nend', 1))
return text.encode()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('parent', type=Path)
parser.add_argument('output', type=Path)
args = parser.parse_args()
result = compose(args.parent.read_bytes())
with args.output.open('xb') as stream:
stream.write(result)
print(hashlib.sha256(result).hexdigest(), args.output)