Files
WoW-Hybrid-gateway/ops/single_name_creation_ui.py

794 lines
48 KiB
Python

#!/usr/bin/env python3
"""Build an isolated source-pinned single-name creation UI; never install it.
Normal NEW characters use one unchanged name and empty surname. The actual
source server remains the authority for validity, availability and creation.
No native API is overridden and no availability-success result is synthesized.
"""
import argparse,hashlib,json,re
from pathlib import Path
SOURCE_FDID=8209459
SOURCE_PATH='interface/addons/blizzard_charactercreate/camelot/blizzard_charactercreate.lua'
SOURCE_SHA256='01a40a1cb2159d8f0bef28d363f424b61ba5442678183ccf9ac34d76554461c2'
POLICY='source-single-name-new-character-ui-v1'
RANDOM_RESULT_ANCHOR='''\t\tself.NameAvailabilityState.lastRandomName = name;
\t\tself.NameAvailabilityState.lastRandomSurname = surname;
\t\tself.EditBox:SetText(name);
'''
RANDOM_RESULT_GUARD='''\t\tif GW_SourceSingleNameCreation() and (type(name) ~= "string" or name == "" or name == PENDING_RANDOM_NAME) then
\t\t\tself.RandomNameButton.pendingRequest = false;
\t\t\treturn; -- An empty native result must not erase a Source name.
\t\tend
'''
HELPER='''-- Source-compatible creation only. Existing/service/reincarnation flows are unchanged.
local function GW_SourceSingleNameCreation()
local frame = CharacterCreateFrame;
if not frame or type(frame.HasService) ~= "function" or type(frame.GetExistingCharacterID) ~= "function" then
return false;
end
if frame:HasService() or frame:GetExistingCharacterID() then
return false;
end
if not C_Reincarnation or type(C_Reincarnation.IsReincarnating) ~= "function" or C_Reincarnation.IsReincarnating() then
return false;
end
if not C_GameRules or type(C_GameRules.IsPlunderstorm) ~= "function" or C_GameRules.IsPlunderstorm() then
return false;
end
return true;
end
'''
RACE_MENU_POLICY='source-distinct-races-extra-elf-creation-disabled-v1'
FUTURE_RACE_PLACEHOLDER_POLICY='source-disabled-future-race-portraits-v1'
FUTURE_RACE_PORTRAITS={'Ogre':236695,'Furbolg':236696}
SKYBORNE_HIDDEN_RACE_IDS=(95,96)
SKYBORNE_HIDE_POLICY='new-character-create-skyborne-hidden-v1'
SKYBORNE_HIDE_HELPER='''-- Hide only the two existing Skyborne creation choices; do not mutate race rows.
local function GW_SkyborneCreationHidden(raceData)
if not GW_SourceSingleNameCreation() or type(raceData) ~= "table" then
return false;
end
return raceData.raceID == 95 or raceData.raceID == 96;
end
'''
DISABLED_CREATION_RACES=(27,29)
RACE_OBSERVATION_POLICY='private-original-create-race-availability-v1'
RACE_OBSERVATION_HELPER='''-- Private diagnostic: report only original public race IDs and enabled states.
local GW_SourceRaceObservationSent = false;
local GW_SourceRaceLogSent = false;
local function GW_ObserveSourceRaceAvailability(races)
if GW_SourceRaceObservationSent or type(races) ~= "table" then
return;
end
local rows = {};
for index, raceData in ipairs(races) do
if index > 64 then
rows[#rows + 1] = "truncated";
break;
end
if type(raceData) == "table" and type(raceData.raceID) == "number" and raceData.raceID >= 1 and raceData.raceID <= 255 and raceData.raceID % 1 == 0 then
local enabled = raceData.enabled == true and "1" or (raceData.enabled == false and "0" or "?");
rows[#rows + 1] = tostring(raceData.raceID) .. ":" .. enabled;
end
end
local message = "GW_CREATE_RACE_AVAILABILITY " .. table.concat(rows, ",");
local shown = pcall(function()
if type(CreateFrame) ~= "function" or not CharacterCreateFrame then error("private overlay unavailable"); end
local frame = CreateFrame("Frame", nil, CharacterCreateFrame);
frame:SetFrameStrata("TOOLTIP");
frame:SetSize(1200, 40);
frame:SetPoint("TOP", CharacterCreateFrame, "TOP", 0, -75);
local text = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge");
text:SetAllPoints(frame);
text:SetText(message);
frame:Show();
end);
if shown then GW_SourceRaceObservationSent = true; end
if not GW_SourceRaceLogSent and type(C_Log) == "table" and type(C_Log.LogMessage) == "function" then
local logged = pcall(C_Log.LogMessage, message);
if logged then GW_SourceRaceLogSent = true; end
end
end
'''
RACE_MENU_HELPER='''-- Keep native race definitions and existing characters intact.
local function GW_SourceRaceCreationDisabled(raceData)
if not GW_SourceSingleNameCreation() or not raceData then
return false;
end
return raceData.raceID == 27 or raceData.raceID == 29;
end
'''
FUTURE_RACE_PLACEHOLDER_HELPER='''-- Presentation only: these frames are not race records or selection buttons.
local function GW_ShowFutureRacePlaceholders(owner, lastButtons)
local frames = owner.GW_FutureRacePlaceholders;
if not GW_SourceSingleNameCreation() then
if frames then
for _, frame in pairs(frames) do frame:Hide(); end
end
return;
end
if not frames then
frames = {};
owner.GW_FutureRacePlaceholders = frames;
end
local entries = {
{"CharacterCreateAllianceButtonTemplate", "Furbolg", 236696},
{"CharacterCreateHordeButtonTemplate", "Ogre", 236695},
};
for _, entry in ipairs(entries) do
local last = lastButtons[entry[1]];
local frame = frames[entry[1]];
if last then
if not frame then
frame = CreateFrame("Frame", nil, owner);
frame:EnableMouse(false);
frame.Icon = frame:CreateTexture(nil, "ARTWORK");
frame.Icon:SetAllPoints(frame);
frame.Icon:SetTexture(entry[3]);
frame.Icon:SetDesaturated(true);
frame.Icon:SetAlpha(1);
frames[entry[1]] = frame;
end
local width, height = last:GetWidth(), last:GetHeight();
frame:SetSize(width > 0 and width or 64, height > 0 and height or 64);
frame:ClearAllPoints();
frame:SetPoint("TOP", last, "BOTTOM", 0, -8);
frame:Show();
elseif frame then
frame:Hide();
end
end
end
'''
SKYBORNE_VISIBLE_FILTER='''\tif GW_SourceSingleNameCreation() then
\t\tlocal visibleRaces = {};
\t\tfor _, raceData in ipairs(races) do
\t\t\tif not GW_SkyborneCreationHidden(raceData) then
\t\t\t\tvisibleRaces[#visibleRaces + 1] = raceData;
\t\t\tend
\t\tend
\t\traces = visibleRaces;
\tend
'''
def transform(raw,*,disable_extra_elves=False,observe_race_availability=False,show_future_placeholders=False,furbolg_portrait_fdid=236696,hide_skyborne=False):
if type(hide_skyborne)is not bool:
raise ValueError('Explicit boolean Skyborne visibility policy required')
if type(disable_extra_elves)is not bool:
raise ValueError('Explicit boolean creation-menu policy required')
if type(observe_race_availability)is not bool:
raise ValueError('Explicit boolean private race observation policy required')
if type(show_future_placeholders)is not bool:
raise ValueError('Explicit boolean future-race placeholder policy required')
if type(furbolg_portrait_fdid)is not int or not 1<=furbolg_portrait_fdid<=0xffffffff:
raise ValueError('Positive Furbolg portrait FileDataID required')
if not show_future_placeholders and furbolg_portrait_fdid!=236696:
raise ValueError('A custom portrait requires future-race placeholders')
if type(raw) is not bytes or not 1<=len(raw)<=262144 or hashlib.sha256(raw).hexdigest()!=SOURCE_SHA256:
raise ValueError('Exact original70334 Camelot creation Lua required')
newline=b'\r\n'
if b'\r\n' not in raw or b'GW_SourceSingleNameCreation' in raw:raise ValueError('Original source framing differs')
def replace(old,new,count=1):
nonlocal raw
a=old.encode().replace(b'\n',newline);b=new.encode().replace(b'\n',newline)
if raw.count(a)!=count:raise ValueError('Original UI anchor cardinality differs')
raw=raw.replace(a,b)
replace('if C_CharacterCreation.AreRegionalUniqueNamesEnabled() then','if not GW_SourceSingleNameCreation() and C_CharacterCreation.AreRegionalUniqueNamesEnabled() then',2)
replace('function CharacterCreateMixin:GetSelectedSurname()\n','function CharacterCreateMixin:GetSelectedSurname()\n\tif GW_SourceSingleNameCreation() then\n\t\treturn "";\n\tend\n')
replace('function CharacterCreateEditBoxSurnameMixin:ShouldShow()\n\treturn C_CharacterCreation.AreRegionalUniqueNamesEnabled();','function CharacterCreateEditBoxSurnameMixin:ShouldShow()\n\treturn not GW_SourceSingleNameCreation() and C_CharacterCreation.AreRegionalUniqueNamesEnabled();')
replace('function NameChoiceMixin:OnShow()\n','''function NameChoiceMixin:OnShow()
\tif GW_SourceSingleNameCreation() then
\t\tself.EditBoxSurname:Hide();
\t\tself.Label:SetText(NAME);
\t\tself.EditBox.instructionsText = nil;
\t\tself.EditBox.tooltipText = nil;
\tend
''')
replace(RANDOM_RESULT_ANCHOR,RANDOM_RESULT_GUARD+RANDOM_RESULT_ANCHOR)
replace('function CharacterCreateNameAvailabilityStateMixin:OnEvent(event, ...)\n','''function CharacterCreateNameAvailabilityStateMixin:OnEvent(event, ...)
\tif GW_SourceSingleNameCreation() then
\t\treturn; -- No modern availability query owns this new source character.
\tend
''')
replace('''function CharacterCreateNameAvailabilityStateMixin:CheckName(nameToCheck, surnameToCheck)
\tself:Hide();
\tself:UpdateNavBlocker(nil);
\tself:Cancel();
''','''function CharacterCreateNameAvailabilityStateMixin:CheckName(nameToCheck, surnameToCheck)
\tself:Hide();
\tself:UpdateNavBlocker(nil);
\tself:Cancel();
\tif GW_SourceSingleNameCreation() then
\t\treturn; -- Server checks the one name on genuine CreateCharacter/result.
\tend
''')
if disable_extra_elves:
replace('function CharacterCreateRaceAndClassMixin:IsRaceValid(raceData, faction)\n',
'function CharacterCreateRaceAndClassMixin:IsRaceValid(raceData, faction)\n\tif GW_SourceRaceCreationDisabled(raceData) then\n\t\treturn false;\n\tend\n')
replace('function CharacterCreateRaceButtonMixin:OnClick()\n',
'function CharacterCreateRaceButtonMixin:OnClick()\n\tif GW_SourceRaceCreationDisabled(self.raceData) then\n\t\treturn;\n\tend\n')
replace('function CharacterCreateMixin:UpdateForwardButton()\n',
'function CharacterCreateMixin:UpdateForwardButton()\n\tif GW_SourceRaceCreationDisabled(RaceAndClassFrame and RaceAndClassFrame.selectedRaceData) then\n\t\tself.ForwardButton:SetEnabled(false);\n\t\treturn;\n\tend\n')
replace('function CharacterCreateMixin:CreateCharacter()\n',
'function CharacterCreateMixin:CreateCharacter()\n\tif GW_SourceRaceCreationDisabled(RaceAndClassFrame and RaceAndClassFrame.selectedRaceData) then\n\t\treturn;\n\tend\n')
if observe_race_availability:
replace('function CharacterCreateRaceAndClassMixin:UpdateRaceButtons(releaseButtons)\n',
'function CharacterCreateRaceAndClassMixin:UpdateRaceButtons(releaseButtons)\n\t-- Observation is inserted at the original availability call below.\n')
old='function CharacterCreateRaceAndClassMixin:UpdateRaceButtons(releaseButtons)\n\t-- Observation is inserted at the original availability call below.\n'
start=raw.index(old.encode().replace(b'\n',newline))
anchor=b'\tlocal races = C_CharacterCreation.GetAvailableRaces();'+newline
end=raw.find(b'\nfunction ',start+1)
if end<0 or raw[start:end].count(anchor)!=1:raise ValueError('Original race availability anchor differs')
at=raw.index(anchor,start,end)+len(anchor)
raw=raw[:at]+b'\tGW_ObserveSourceRaceAvailability(races);'+newline+raw[at:]
if show_future_placeholders:
replace('\tlocal templateCount = {};\n',
'\tlocal templateCount = {};\n\tlocal GW_LastRaceButtons = {};\n')
replace('\t\t\tbutton:SetRace(raceData, self.selectedRaceID, self.selectedFaction, templateCount[buttonTemplate]);\n',
'\t\t\tbutton:SetRace(raceData, self.selectedRaceID, self.selectedFaction, templateCount[buttonTemplate]);\n\t\t\tGW_LastRaceButtons[buttonTemplate] = button;\n')
replace('\t\tend\n\tend\nend\n\nlocal function SortClasses(classData1, classData2)',
'\t\tend\n\tend\n\tGW_ShowFutureRacePlaceholders(self, GW_LastRaceButtons);\nend\n\nlocal function SortClasses(classData1, classData2)')
if hide_skyborne:
# Filter only the local rendered-button list; keep the native table intact.
replace('function CharacterCreateRaceAndClassMixin:IsRaceValid(raceData, faction)\n',
'function CharacterCreateRaceAndClassMixin:IsRaceValid(raceData, faction)\n\tif GW_SkyborneCreationHidden(raceData) then\n\t\treturn false;\n\tend\n')
start=raw.index(b'function CharacterCreateRaceAndClassMixin:UpdateRaceButtons(releaseButtons)')
end=raw.index(b'local function SortClasses(classData1, classData2)',start)
anchor=b'\tlocal races = C_CharacterCreation.GetAvailableRaces();'+newline
if raw[start:end].count(anchor)!=1:raise ValueError('Original race-button list anchor differs')
at=raw.index(anchor,start,end)+len(anchor)
if observe_race_availability:
observed=b'\tGW_ObserveSourceRaceAvailability(races);'+newline
if raw[at:at+len(observed)]!=observed:raise ValueError('Private observation ordering differs')
at+=len(observed)
filter_code=SKYBORNE_VISIBLE_FILTER.encode().replace(b'\n',newline)
raw=raw[:at]+filter_code+raw[at:]
placeholder_helper=FUTURE_RACE_PLACEHOLDER_HELPER
if furbolg_portrait_fdid!=236696:
old='{"CharacterCreateAllianceButtonTemplate", "Furbolg", 236696}'
if placeholder_helper.count(old)!=1:raise ValueError('Furbolg portrait anchor differs')
placeholder_helper=placeholder_helper.replace(old,'{"CharacterCreateAllianceButtonTemplate", "Furbolg", '+str(furbolg_portrait_fdid)+'}',1)
helper=HELPER+(SKYBORNE_HIDE_HELPER if hide_skyborne else '')+(RACE_MENU_HELPER if disable_extra_elves else '')+(RACE_OBSERVATION_HELPER if observe_race_availability else '')+(placeholder_helper if show_future_placeholders else '')
return helper.encode().replace(b'\n',newline)+raw
def rebase_source_creator_skin_choices(raw, *, expected_sha256, profile_header=None):
"""Remove out-of-range original skins from the independent NEW-character menu."""
return _filter_source_creator_choices(raw, expected_sha256, profile_header, skin_only=True)
def rebase_source_creator_choices(raw, *, expected_sha256, profile_header=None, include_hair_colors=True):
"""Filter independent creator options against the original appearance records."""
return _filter_source_creator_choices(raw, expected_sha256, profile_header, skin_only=not include_hair_colors)
def _filter_source_creator_choices(raw, expected_sha256, profile_header, *, skin_only):
if hashlib.sha256(raw).hexdigest()!=expected_sha256:
raise ValueError('Creation UI parent SHA differs')
from source_appearance_groups import profile
schema,_=profile(profile_header)
domains = {}
face_skins = set()
if not skin_only:
for race, sex, section, style, color in schema.sections:
if section == 1 and schema.creator_skin_allowed(race, sex, color) and (race, sex, 0, 0, color) in schema.sections:
domains.setdefault((race, sex, 2), set()).add(style)
face_skins.add((race, sex, style, color))
elif section == 3 and (race, sex, style) in schema.hair:
domains.setdefault((race, sex, 3), set()).add(style)
domains.setdefault((race, sex, 4), set()).add(color)
for race, sex, feature in schema.facial:
domains.setdefault((race, sex, 5), set()).add(feature)
def unavailable(race, sex, field, value, dependent, dependent_value):
if field == 1:
return not schema.creator_skin_allowed(race, sex, value)
values = domains.get((race, sex, field))
if values is None:
return False
if field == 2 and dependent == 1:
return (race, sex, value, dependent_value) not in face_skins
return value not in values
anchor=b'local GW_SOURCE_ALLOWED_CHOICES = {'
if raw.count(anchor)!=1:
raise ValueError('Independent Source choice table differs')
start=raw.index(anchor)+len(anchor)
end=raw.index(b'};',start)
rows=raw[start:end].splitlines(keepends=True)
seen=set()
removed={}
for index,row in enumerate(rows):
if not row.strip():continue
match=re.fullmatch(rb'(\s*\[(\d+)\] = \{)([\d,]+)(\},\s*)',row)
if not match:raise ValueError('Source choice row differs')
key=int(match[2])
race,sex=divmod(key,2)
if key in seen or (race,sex) not in schema.creator_skin_counts:
raise ValueError('Unknown or duplicate Source race/sex')
seen.add(key)
kept=[];excluded=[]
for token in match[3].split(b','):
choice=int(token)
relations=schema.relations.get((race,sex,choice),())
if relations and all(unavailable(race,sex,*relation) for relation in relations):
excluded.append(choice)
else:
kept.append(token)
if excluded:
if not {schema.choices[c] for c in excluded}<={schema.choices.get(int(c)) for c in kept}:
raise ValueError('Source option would lose every available choice')
rows[index]=match[1]+b','.join(kept)+match[4]
removed[key]=excluded
return raw[:start]+b''.join(rows)+raw[end:],removed
def rebase_hide_creator_choices(raw, *, expected_sha256, choices, profile_header=None):
"""#36: drop out-of-range skins (rebase_source_creator_skin_choices) and every shop-only choice from the NEW-character
allow-list. Shop choices carry a renderable all-class Req (the client draws only met Reqs), so the creator relies on
this list to keep them out; the Source option of each race/sex must keep at least one choice."""
hide = {int(c) for c in choices}
existing = re.search(rb'local GW_SOURCE_CREATOR_HIDDEN = \{([^}]*)\};\n', raw)
if existing:
# Already rebased (#36 on a later parent, e.g. #101): skins are rebased, extend the hidden set and allow-list only.
if hashlib.sha256(raw).hexdigest() != expected_sha256:
raise ValueError('Creator Lua hash differs')
removed = {}
hide |= {int(c) for c in re.findall(rb'\[(\d+)\]=true', existing[1])}
else:
raw, removed = rebase_source_creator_skin_choices(raw, expected_sha256=expected_sha256, profile_header=profile_header)
anchor = b'local GW_SOURCE_ALLOWED_CHOICES = {'
start = raw.index(anchor) + len(anchor); end = raw.index(b'};', start)
rows = raw[start:end].splitlines(keepends=True)
for index, row in enumerate(rows):
match = re.fullmatch(rb'(\s*\[(\d+)\] = \{)([\d,]+)(\},\s*)', row)
if not match:
continue
kept = [tok for tok in match[3].split(b',') if int(tok) not in hide]
gone = [int(tok) for tok in match[3].split(b',') if int(tok) in hide]
if gone:
if not kept:
raise ValueError('Source race/sex would lose every choice')
rows[index] = match[1] + b','.join(kept) + match[4]
removed.setdefault(int(match[2]), []).extend(gone)
raw = raw[:start] + b''.join(rows) + raw[end:]
if existing:
table = b'local GW_SOURCE_CREATOR_HIDDEN = {' + b','.join(b'[%d]=true' % c for c in sorted(hide)) + b'};\n'
return raw.replace(existing[0], table), removed
# SD variant options (ChrModelAltVariantChoice targets) are not Source options, so the allow-list never sees them:
# every option also drops the hidden set.
lookup = b'local GW_AllowedLookup = {};'
loop_old = (b' local kept, sourceOption = {}, false;\n'
b' for _, choice in ipairs(option.choices or {}) do\n'
b' if GW_SOURCE_CHOICE_OPTION[choice.id] == option.id then sourceOption = true; end\n'
b' if allowed[choice.id] then kept[#kept + 1] = choice; end\n'
b' end\n'
b' if sourceOption and #kept > 0')
loop_new = (b' local kept, sourceOption, hiddenOption = {}, false, false;\n'
b' for _, choice in ipairs(option.choices or {}) do\n'
b' if GW_SOURCE_CHOICE_OPTION[choice.id] == option.id then sourceOption = true; end\n'
b' if GW_SOURCE_CREATOR_HIDDEN[choice.id] then hiddenOption = true; end\n'
b' end\n'
b' for _, choice in ipairs(option.choices or {}) do\n'
b' if not GW_SOURCE_CREATOR_HIDDEN[choice.id] and (not sourceOption or allowed[choice.id]) then kept[#kept + 1] = choice; end\n'
b' end\n'
b' if (sourceOption or hiddenOption) and #kept > 0')
if raw.count(lookup) != 1 or raw.count(loop_old) != 1 or b'GW_SOURCE_CREATOR_HIDDEN' in raw:
raise ValueError('Creator filter differs')
table = b'local GW_SOURCE_CREATOR_HIDDEN = {' + b','.join(b'[%d]=true' % c for c in sorted(hide)) + b'};\n'
raw = raw.replace(lookup, table + lookup).replace(loop_old, loop_new)
return raw, removed
def rebase_correlated_source_appearance(raw, *, expected_sha256, profile_header=None):
"""Replace independent choice allowlists with the existing profile's groups."""
if hashlib.sha256(raw).hexdigest() != expected_sha256:
raise ValueError('Creation UI parent SHA differs')
from source_appearance_groups import helper
grouped, report = helper(profile_header)
text = raw.decode('utf-8')
start = text.index('local GW_SOURCE_ALLOWED_CHOICES = {')
end = text.index('-- Native create result codes', start)
text = text[:start] + grouped + '\n' + text[end:]
anchor = 'local function GW_SourceDirectCreate(name)'
if text.count(anchor) != 1:raise ValueError('Original Source create helper differs')
text = text.replace(anchor, 'local GW_SourceCorrelateCustomizations;\nlocal GW_SourcePreferredChoice;\n' + anchor)
before = ' if api(5, race + class * 256 + sex * 65536, 0) ~= 0 then return false, "begin"; end'
after = ' local gwCreationData, _, gwAppearanceError = GW_SourceCorrelateCustomizations(C_CharacterCreation.GetAvailableCustomizations());\n if gwAppearanceError then return false, "appearance"; end\n' + before
if text.count(before) != 1:raise ValueError('Original Source stage boundary differs')
text = text.replace(before, after)
before = ' for _, category in ipairs(C_CharacterCreation.GetAvailableCustomizations() or {}) do'
if text.count(before) != 1:raise ValueError('Original Source customization collection differs')
text = text.replace(before, ' for _, category in ipairs(gwCreationData or {}) do')
before = 'function CharacterCreateMixin:SetCustomizationChoice(optionID, choiceID)\n\tC_CharacterCreation.SetCustomizationChoice(optionID, choiceID);'
after = before.replace('\n\tC_', '\n\tGW_SourcePreferredChoice = {optionID, choiceID};\n\tC_')
if text.count(before) != 1:raise ValueError('Original choice callback differs')
text = text.replace(before, after)
before = '\tself:UpdateCharCustomizationFrame();\nend\n\nfunction CharacterCreateMixin:ResetCustomizationPreview'
after = before.replace('\nend', '\n\tGW_SourcePreferredChoice = nil;\nend', 1)
if text.count(before) != 1:raise ValueError('Original choice callback completion differs')
text = text.replace(before, after)
text = text.replace('The server could not accept this appearance or name.', 'This appearance or name could not be prepared for the server.')
return text.encode('utf-8'), report
def rebase_remove_creation_surname_sentinel(raw, *, expected_sha256):
"""Restore the original call's surname getter on the witnessed UI body.
Source NEW creation already returns an empty surname from that getter;
other modes retain the original surname behavior. This does not establish
native validation, packet dispatch, or successful character creation.
"""
if hashlib.sha256(raw).hexdigest() != expected_sha256:
raise ValueError('Create UI identity differs')
newline = b'\r\n' if b'\r\n' in raw else b'\n'
old = (b'\t\t-- Private Source-only bridge: the matching gateway strips this exact local validation sentinel.' + newline +
b'\t\tlocal gwSurname = GW_SourceSingleNameCreation() and "Control" or self:GetSelectedSurname();' + newline +
b'\t\tC_CharacterCreation.CreateCharacter(self:GetSelectedName(), gwSurname, ZoneChoiceFrame.useNPE, RaceAndClassFrame:GetCreateCharacterFaction());')
new = (b'\t\tC_CharacterCreation.CreateCharacter(self:GetSelectedName(), self:GetSelectedSurname(), ZoneChoiceFrame.useNPE, RaceAndClassFrame:GetCreateCharacterFaction());')
if raw.count(old) != 1 or raw.count(b'function CharacterCreateMixin:GetSelectedSurname()') != 1:
raise ValueError('Witnessed Create UI sentinel anchors differ')
return raw.replace(old, new, 1)
def rebase_random_result_guard(raw, *, expected_sha256):
"""Add the Source random-result guard to an exact projected Create UI."""
if not isinstance(raw,bytes) or not isinstance(expected_sha256,str) or hashlib.sha256(raw).hexdigest()!=expected_sha256:
raise ValueError('Pinned projected Create UI differs')
newline=b'\r\n' if b'\r\n' in raw else b'\n'
anchor=RANDOM_RESULT_ANCHOR.encode().replace(b'\n',newline)
guard=RANDOM_RESULT_GUARD.encode().replace(b'\n',newline)
if b'local function GW_SourceSingleNameCreation()' not in raw or raw.count(anchor)!=1 or guard in raw:
raise ValueError('Projected random-result handler differs or is already guarded')
return raw.replace(anchor,guard+anchor,1)
def rebase_high_elf_meditation_trait(raw, *, expected_sha256):
"""Include the fourth original High Elf trait in the English creator race details."""
if hashlib.sha256(raw).hexdigest() != expected_sha256:
raise ValueError('Creation UI parent SHA differs')
lines = [
b' [10] = {',
br' {icon=8560813, description="Bow Specialization\nIncreases bow skill."},',
br' {icon=8560811, description="Enchanting Specialization\nIncreases Enchanting skill."},',
br' {icon=8560812, description="Swiftness of the Rangers\nIncreases Agility."},',
b' },',
]
newline = b'\r\n' if b'\r\n' in raw else b'\n'
old = newline.join(lines)
if raw.count(old) != 1:
raise ValueError('Expected the three existing English High Elf racial traits')
meditation = br""" {icon=135933, description="Quel'dorei Meditation\nMay meditate, restoring vital resources."},"""
return raw.replace(old, newline.join([lines[0], lines[1], lines[3], lines[2], meditation, lines[4]]), 1)
def rebase_hide_skyborne(raw, *, expected_sha256):
"""Apply the existing Skyborne policy to an exact projected Create UI body."""
if not isinstance(raw,bytes) or not isinstance(expected_sha256,str) or hashlib.sha256(raw).hexdigest()!=expected_sha256:
raise ValueError('Pinned projected Create UI differs')
newline=b'\r\n' if b'\r\n' in raw else b'\n'
if b'GW_SkyborneCreationHidden' in raw:
raise ValueError('Skyborne policy already present')
helper_anchor=b'local GW_SourceRaceDetails = {'
valid_anchor=b'function CharacterCreateRaceAndClassMixin:IsRaceValid(raceData, faction)'+newline
start_anchor=b'function CharacterCreateRaceAndClassMixin:UpdateRaceButtons(releaseButtons)'
end_anchor=b'local function SortClasses(classData1, classData2)'
filter_anchor=b'\traces = GW_ProjectSourceRaceList(races, self.selectedSexID);'+newline
if any(raw.count(anchor)!=1 for anchor in (helper_anchor,valid_anchor,start_anchor,end_anchor)):
raise ValueError('Projected Create UI anchors differ')
start=raw.index(start_anchor);end=raw.index(end_anchor,start)
if raw[start:end].count(filter_anchor)!=1:
raise ValueError('Projected race button anchor differs')
raw=raw.replace(helper_anchor,SKYBORNE_HIDE_HELPER.encode().replace(b'\n',newline)+helper_anchor,1)
raw=raw.replace(valid_anchor,valid_anchor+b'\tif GW_SkyborneCreationHidden(raceData) then'+newline+b'\t\treturn false;'+newline+b'\tend'+newline,1)
start=raw.index(start_anchor);end=raw.index(end_anchor,start)
at=raw.index(filter_anchor,start,end)+len(filter_anchor)
return raw[:at]+SKYBORNE_VISIBLE_FILTER.encode().replace(b'\n',newline)+raw[at:]
def rebase_source_race_atlas_guard(raw, *, expected_sha256):
"""Keep the projected Source race buttons inside the original atlas contract.
RingedFrameTemplate passes the race icon through SetNormalAtlas, which needs
a nonempty atlas string. Native Source race rows may omit that field. The
existing 9/10 projection remains presentation only and native race IDs stay
unchanged.
"""
if not isinstance(raw, bytes) or not isinstance(expected_sha256, str) or hashlib.sha256(raw).hexdigest() != expected_sha256:
raise ValueError('Pinned projected Create UI differs')
newline = b'\r\n' if b'\r\n' in raw else b'\n'
old = '''local function GW_RaceAtlasFallback(raceData, sexID)
local original = raceData.createScreenIconAtlas;
if original ~= nil or not GW_SourceSingleNameCreation() then return original; end
local race = raceData.raceID;
if race ~= 9 and race ~= 10 then return original; end
if not Enum or not Enum.UnitSex then return original; end
local sex;
if sexID == Enum.UnitSex.Male then sex = "male";
elseif sexID == Enum.UnitSex.Female then sex = "female";
else return original; end
if not C_Texture or type(C_Texture.GetAtlasInfo) ~= "function" then return original; end
local atlas = "raceicon128-" .. (race == 9 and "goblin" or "bloodelf") .. "-" .. sex;
local ok, info = pcall(C_Texture.GetAtlasInfo, atlas);
if ok and info then return atlas; end
return original;
end'''.encode().replace(b'\n', newline)
new = '''local function GW_RaceAtlasFallback(raceData, sexID)
local original = raceData and raceData.createScreenIconAtlas;
if type(original) == "string" and original ~= "" then return original; end
if not GW_SourceSingleNameCreation() or not raceData then return nil; end
local race = raceData.raceID;
if race ~= 9 and race ~= 10 then return nil; end
local sex = (Enum and Enum.UnitSex and sexID == Enum.UnitSex.Female) and "female" or "male";
return "raceicon128-" .. (race == 9 and "goblin" or "bloodelf") .. "-" .. sex;
end'''.encode().replace(b'\n', newline)
old_call = b'\tself:SetIconAtlas(GW_RaceAtlasFallback(raceData, RaceAndClassFrame and RaceAndClassFrame.selectedSexID));'
new_call = (b'\tlocal gwAtlas = GW_RaceAtlasFallback(raceData, RaceAndClassFrame and RaceAndClassFrame.selectedSexID);' + newline +
b'\tif gwAtlas then self:SetIconAtlas(gwAtlas); end')
if raw.count(old) != 1 or raw.count(old_call) != 1 or raw.count(b'GW_ProjectSourceRaceList(races, self.selectedSexID)') != 1:
raise ValueError('Projected race atlas anchors differ')
return raw.replace(old, new, 1).replace(old_call, new_call, 1)
def rebase_future_race_portrait_frame(raw, *, expected_sha256):
"""Restore the inert portrait border and caption on the exact Source UI."""
if not isinstance(raw, bytes) or not isinstance(expected_sha256, str) or hashlib.sha256(raw).hexdigest() != expected_sha256:
raise ValueError('Pinned projected Create UI differs')
newline = b'\r\n' if b'\r\n' in raw else b'\n'
old = ''' frame.Icon:SetTexture(entry[3]);
frame.Icon:SetDesaturated(true);
frame.Icon:SetAlpha(1);
frames[entry[1]] = frame;'''.encode().replace(b'\n', newline)
new = ''' frame.Icon:SetTexture(entry[3]);
frame.Icon:SetDesaturated(true);
frame.Icon:SetAlpha(1);
frame.Border = frame:CreateTexture(nil, "OVERLAY");
frame.Border:SetAtlas("character-create-icon-frame");
frame.Border:SetPoint("CENTER", frame, "CENTER");
frame.Border:SetSize(86, 86);
frame.Border:SetDesaturated(true);
frame.Label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalMed2Outline");
frame.Label:SetPoint("TOP", frame, "BOTTOM", 2, 7);
frame.Label:SetText(entry[2]);
frame.Label:SetTextColor(0.65, 0.65, 0.65, 1);
frames[entry[1]] = frame;'''.encode().replace(b'\n', newline)
if raw.count(old) != 1 or raw.count(b'{"CharacterCreateAllianceButtonTemplate", "Furbolg", 8560817}') != 1:
raise ValueError('Projected future portrait anchors differ')
return raw.replace(old, new, 1)
def rebase_witnessed_name_width(raw, *, expected_sha256):
"""Try the witnessed original texture width in the Source name layout.
The native witness measured the edit texture at 314 units. This candidate
retains narrow-screen fitting and requires native visual acceptance.
"""
if not isinstance(raw,bytes) or not isinstance(expected_sha256,str) or hashlib.sha256(raw).hexdigest()!=expected_sha256:
raise ValueError('Pinned projected Create UI differs')
newline=b'\r\n' if b'\r\n' in raw else b'\n'
old=''' local hasSurname = self.EditBoxSurname:IsShown();
local desiredWidth = hasSurname and 560 or 384;
local parent = self:GetParent();
local parentWidth = parent and parent:GetWidth() or 0;
local width = parentWidth > 32 and math.min(desiredWidth, parentWidth - 32) or desiredWidth;
local boxWidth = math.max(1, math.min(210, (width - 96) / (hasSurname and 2 or 1)));
'''.encode().replace(b'\n',newline)
new=''' local hasSurname = self.EditBoxSurname:IsShown();
local sourceSingle = GW_SourceSingleNameCreation() and not hasSurname;
local desiredWidth = hasSurname and 560 or (sourceSingle and 448 or 384);
local parent = self:GetParent();
local parentWidth = parent and parent:GetWidth() or 0;
local width = parentWidth > 32 and math.min(desiredWidth, parentWidth - 32) or desiredWidth;
local maxBoxWidth = sourceSingle and 314 or 210;
local boxWidth = math.max(1, math.min(maxBoxWidth, (width - 96) / (hasSurname and 2 or 1)));
'''.encode().replace(b'\n',newline)
anchor=b'function NameChoiceMixin:UpdateNameLayout()'+newline
if raw.count(anchor)!=1 or raw.count(old)!=1 or b'local function GW_SourceSingleNameCreation()' not in raw:
raise ValueError('Witnessed name layout anchors differ')
return raw.replace(old,new,1)
NAME_BORDER_HELPER='''-- Use the original SharedXML three-piece input artwork on the witnessed field.
local function GW_RestoreNameBorder(frame)
local saved = frame.GW_NameBorder;
if not saved then return; end
saved.original:SetAlpha(saved.alpha);
for _, texture in ipairs(saved.parts) do texture:Hide(); end
end
local function GW_UseCompleteNameBorder(frame)
if not GW_SourceSingleNameCreation() or not frame:IsShown() then return; end
local edit = frame.EditBox;
if not edit or type(edit.GetRegions) ~= "function" or type(edit.CreateTexture) ~= "function" then return; end
local regions = { edit:GetRegions() };
local original = regions[4];
if not original or type(original.GetObjectType) ~= "function" or original:GetObjectType() ~= "Texture" then return; end
local saved = frame.GW_NameBorder;
if saved then
if saved.original ~= original then return; end
original:SetAlpha(0);
for _, texture in ipairs(saved.parts) do texture:Show(); end
return;
end
if type(original.GetAlpha) ~= "function" or type(original.SetAlpha) ~= "function" or type(original.GetLeft) ~= "function" or type(original.GetRight) ~= "function" or type(original.GetTop) ~= "function" or type(original.GetBottom) ~= "function" or type(edit.GetLeft) ~= "function" or type(edit.GetRight) ~= "function" or type(edit.GetTop) ~= "function" or type(edit.GetBottom) ~= "function" then return; end
local l,r,t,b = original:GetLeft(), original:GetRight(), original:GetTop(), original:GetBottom();
local el,er,et,eb = edit:GetLeft(), edit:GetRight(), edit:GetTop(), edit:GetBottom();
if type(l) ~= "number" or type(r) ~= "number" or type(t) ~= "number" or type(b) ~= "number" or type(el) ~= "number" or type(er) ~= "number" or type(et) ~= "number" or type(eb) ~= "number" then return; end
if math.abs(l-el) > 2 or math.abs(r-er) > 2 or math.abs(t-et) > 2 or math.abs(b-eb) > 2 then return; end
local parts = {};
local ok = pcall(function()
for i, atlas in ipairs({"common-search-border-left", "common-search-border-right", "common-search-border-middle"}) do
local texture = edit:CreateTexture(nil, "BACKGROUND");
parts[i] = texture;
texture:Hide();
texture:SetAtlas(atlas, false);
end
local left, right, middle = parts[1], parts[2], parts[3];
left:SetSize(8, 20); left:SetPoint("LEFT", edit, "LEFT", 0, 0);
right:SetSize(8, 20); right:SetPoint("RIGHT", edit, "RIGHT", 0, 0);
middle:SetSize(10, 20);
middle:SetPoint("LEFT", left, "RIGHT", 0, 0);
middle:SetPoint("RIGHT", right, "LEFT", 0, 0);
end);
if not ok then
for _, texture in ipairs(parts) do pcall(function() texture:Hide(); end); end
return;
end
frame.GW_NameBorder = {original = original, alpha = original:GetAlpha(), parts = parts};
original:SetAlpha(0);
for _, texture in ipairs(parts) do texture:Show(); end
end
'''
def rebase_name_border(raw, *, expected_sha256):
"""Replace the witnessed Source-name texture with retained SharedXML art."""
if not isinstance(raw,bytes) or not isinstance(expected_sha256,str) or hashlib.sha256(raw).hexdigest()!=expected_sha256:
raise ValueError('Pinned projected Create UI differs')
newline=b'\r\n' if b'\r\n' in raw else b'\n'
before=b'local function GW_ScheduleNameGeometry(frame)'+newline
call=b'GW_FitNameBackdrop(frame); GW_ObserveNameGeometry(frame);'
hide=b'function NameChoiceMixin:OnHide()'+newline
if raw.count(before)!=1 or raw.count(call)!=1 or raw.count(hide)!=1 or b'GW_UseCompleteNameBorder' in raw:
raise ValueError('Witnessed name-border anchors differ')
raw=raw.replace(before,NAME_BORDER_HELPER.encode().replace(b'\n',newline)+before,1)
raw=raw.replace(call,b'GW_FitNameBackdrop(frame); GW_UseCompleteNameBorder(frame); GW_ObserveNameGeometry(frame);',1)
return raw.replace(hide,hide+b'\tGW_RestoreNameBorder(self);'+newline+b'\tself.GW_NameGeometryScheduled = nil;'+newline,1)
def rebase_clean_name_border(raw, *, expected_sha256):
"""Apply the witnessed single-name layout to the exact clean r3b UI body.
The released clean UI omitted the earlier private width/border candidates.
Keep its creation and race handling byte-for-byte; only the name frame's
Source-mode geometry and original SharedXML border presentation change.
"""
if not isinstance(raw, bytes) or not isinstance(expected_sha256, str) or hashlib.sha256(raw).hexdigest() != expected_sha256:
raise ValueError('Pinned clean CharacterCreate UI differs')
newline = b'\r\n' if b'\r\n' in raw else b'\n'
anchor = b'NameChoiceMixin = {}' + newline + newline
on_show = b'\tself:RegisterEvent("RANDOM_CHARACTER_NAME_RESULT");' + newline
on_hide = b'function NameChoiceMixin:OnHide()' + newline
if (raw.count(anchor) != 1 or raw.count(on_show) != 1 or raw.count(on_hide) != 1
or b'local function GW_SourceSingleNameCreation()' not in raw
or b'GW_UseCompleteNameBorder' in raw or b'UpdateNameLayout' in raw):
raise ValueError('Clean name-frame anchors differ')
layout = '''-- Preserve the original parent -> dice -> name -> surname anchor chain.
function NameChoiceMixin:UpdateNameLayout()
if not GW_SourceSingleNameCreation() then return; end
local parent = self:GetParent();
local parentWidth = parent and parent:GetWidth() or 0;
local width = parentWidth > 32 and math.min(448, parentWidth - 32) or 448;
local boxWidth = math.max(1, math.min(314, width - 96));
self:SetWidth(width);
self.EditBox:SetWidth(boxWidth);
self.RandomNameButton:ClearAllPoints();
self.EditBox:ClearAllPoints();
self.RandomNameButton:SetPoint("RIGHT", self, "CENTER", -boxWidth / 2 - 8, -10);
self.EditBox:SetPoint("LEFT", self.RandomNameButton, "RIGHT", 8, 0);
end
-- Repair the witnessed left-overhang only if the layout is narrower than its texture.
local function GW_FitNameBackdrop(frame)
if not GW_SourceSingleNameCreation() or not frame:IsShown() then return; end
local edit = frame.EditBox;
if not edit or type(edit.GetRegions) ~= "function" then return; end
local regions = { edit:GetRegions() };
local texture = regions[4];
if not texture or type(texture.GetObjectType) ~= "function" or texture:GetObjectType() ~= "Texture" then return; end
if type(texture.GetLeft) ~= "function" or type(texture.GetRight) ~= "function" or type(texture.GetTop) ~= "function" or type(texture.GetBottom) ~= "function" or type(texture.ClearAllPoints) ~= "function" or type(texture.SetPoint) ~= "function" then return; end
local l, r, t, b = texture:GetLeft(), texture:GetRight(), texture:GetTop(), texture:GetBottom();
local el, er, et, eb = edit:GetLeft(), edit:GetRight(), edit:GetTop(), edit:GetBottom();
if type(l) ~= "number" or type(r) ~= "number" or type(t) ~= "number" or type(b) ~= "number" or type(el) ~= "number" or type(er) ~= "number" or type(et) ~= "number" or type(eb) ~= "number" then return; end
if l >= el - 2 or math.abs(r-er) > 2 or math.abs(t-et) > 2 or math.abs(b-eb) > 2 then return; end
texture:ClearAllPoints();
texture:SetPoint("TOPLEFT", edit, "TOPLEFT", 0, 0);
texture:SetPoint("BOTTOMRIGHT", edit, "BOTTOMRIGHT", 0, 0);
end
'''
scheduler = '''local function GW_ScheduleNameBackdrop(frame)
if frame.GW_NameBackdropScheduled or not C_Timer or type(C_Timer.After) ~= "function" then return; end
frame.GW_NameBackdropScheduled = true;
C_Timer.After(0, function()
if not frame:IsShown() then return; end
GW_FitNameBackdrop(frame);
end);
end
'''
# The original edit backdrop is 314 units wide after UpdateNameLayout.
# Adding SharedXML's three-piece border creates a second left cap beside
# the dice in native Customize, so retain the original fitted backdrop.
body = (layout + scheduler).encode().replace(b'\n', newline)
raw = raw.replace(anchor, anchor + body, 1)
raw = raw.replace(on_show,
b'\tself:UpdateNameLayout();' + newline +
b'\tGW_ScheduleNameBackdrop(self);' + newline + on_show, 1)
return raw.replace(on_hide,
on_hide + b'\tself.GW_NameBackdropScheduled = nil;' + newline, 1)
def prepare(source,output,*,disable_extra_elves=False,observe_race_availability=False,show_future_placeholders=False,furbolg_portrait_fdid=236696,hide_skyborne=False):
source=Path(source);output=Path(output)
if source.is_symlink() or not source.is_file():raise ValueError('Regular original UI input required')
original=source.read_bytes();patched=transform(original,disable_extra_elves=disable_extra_elves,observe_race_availability=observe_race_availability,show_future_placeholders=show_future_placeholders,furbolg_portrait_fdid=furbolg_portrait_fdid,hide_skyborne=hide_skyborne)
if output.exists():raise ValueError('Preserve existing isolated output')
output.mkdir(parents=True);target=output/SOURCE_PATH;target.parent.mkdir(parents=True);target.write_bytes(patched)
report={'policy':POLICY,'source_file_data_id':SOURCE_FDID,'source_path':SOURCE_PATH,'before_sha256':SOURCE_SHA256,'candidate_sha256':hashlib.sha256(patched).hexdigest(),'original_utf8_name_unmodified':True,'surname_empty_new_characters_only':True,'server_name_validity_and_availability_verified':False,'availability_success_synthesized':False,'original_create_call_and_result_handlers_unchanged':True,'installed':False,'native_execution_verified':False,'limits':['Native original CreateCharacter accepts empty-surname request schema; actual C API/UI transmission still needs local QA.','Original Camelot source/TOC selection is proved statically; actual patched consumer execution is pending.','No existing character, paid service, reincarnation, server name policy or account data is changed.']}
if hide_skyborne:
report.update(skyborne_visibility_policy=SKYBORNE_HIDE_POLICY,hidden_creation_race_ids=list(SKYBORNE_HIDDEN_RACE_IDS),original_race_rows_unchanged=True,existing_character_and_service_flows_changed=False)
if disable_extra_elves:
report.update(creation_menu_policy=RACE_MENU_POLICY,
disabled_new_character_race_ids=list(DISABLED_CREATION_RACES),
native_race_definitions_preserved=True,
source_goblin_high_elf_admission_changed=False,
existing_character_and_service_flows_changed=False)
report['limits'].append('High Elf/Goblin native availability, customization and actual creation remain separate acceptance gates.')
if observe_race_availability:
report.update(private_race_observation_policy=RACE_OBSERVATION_POLICY,
visible_fields=['raceID','enabled'],logged_fields=['raceID','enabled'],
native_overlay_verified=False,native_log_delivery_verified=False)
report['limits'].append('Private race observation is not installed; native overlay and C_Log delivery require acceptance.')
if show_future_placeholders:
report.update(future_race_placeholder_policy=FUTURE_RACE_PLACEHOLDER_POLICY,
placeholder_portraits={'Ogre':236695,'Furbolg':furbolg_portrait_fdid},
placeholders_selectable=False,native_race_rows_added=False,
placeholder_native_rendering_verified=False)
report['limits'].append('Ogre and Furbolg are inert portraits only; native rendering requires acceptance and playable races remain future work.')
(output/'report.json').write_text(json.dumps(report,indent=2)+'\n');return report
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--source',type=Path,required=True);p.add_argument('--output',type=Path,required=True);p.add_argument('--disable-extra-elves',action='store_true');p.add_argument('--observe-race-availability',action='store_true');p.add_argument('--show-future-placeholders',action='store_true');p.add_argument('--furbolg-portrait-fdid',type=int,default=236696);p.add_argument('--hide-skyborne',action='store_true');a=p.parse_args();prepare(a.source,a.output,disable_extra_elves=a.disable_extra_elves,observe_race_availability=a.observe_race_availability,show_future_placeholders=a.show_future_placeholders,furbolg_portrait_fdid=a.furbolg_portrait_fdid,hide_skyborne=a.hide_skyborne);print('Isolated creation UI prepared; native/server acceptance pending.')
NAME_TEMPLATE_BORDER = '''local function GW_FitNameBackdrop(frame)
if not GW_SourceSingleNameCreation() or not frame:IsShown() then return; end
local edit = frame.EditBox;
-- #121 (11-30): restore SharedEditBoxTemplate's own three pieces after the width change; the earlier
-- regions[4] stretch left the box without its left cap. Named keys only, no region-order guess.
local left, right, middle = edit and edit.Left, edit and edit.Right, edit and edit.Middle;
if not left or not right or not middle then return; end
left:ClearAllPoints(); left:SetPoint("LEFT", edit, "LEFT", 0, 0);
right:ClearAllPoints(); right:SetPoint("RIGHT", edit, "RIGHT", 0, 0);
middle:ClearAllPoints();
middle:SetPoint("TOPLEFT", left, "TOPRIGHT", 0, 0);
middle:SetPoint("BOTTOMRIGHT", right, "BOTTOMLEFT", 0, 0);
for _, texture in ipairs({left, right, middle}) do texture:SetAlpha(1); texture:Show(); end
end
'''
def rebase_name_template_border(raw):
"""#121: replace the live GW_FitNameBackdrop (region-index stretch) with the template's named-piece layout."""
if not isinstance(raw, bytes):
raise ValueError('bytes required')
newline = b'\r\n' if b'\r\n' in raw else b'\n'
start = raw.find(b'local function GW_FitNameBackdrop(frame)')
end = raw.find(b'local function GW_ScheduleNameBackdrop(frame)')
if start < 0 or end < start or raw.count(b'local function GW_FitNameBackdrop(frame)') != 1 or b'#121 (11-30)' in raw:
raise ValueError('Name backdrop anchors differ')
return raw[:start] + (NAME_TEMPLATE_BORDER + '\n').replace('\n', '\n').encode().replace(b'\n', newline) + raw[end:]