Files
WoW-Hybrid-gateway/ops/character_select_ready_ui.py
2026-11-23 03:28:32 +02:00

104 lines
4.9 KiB
Python

#!/usr/bin/env python3
"""Character-select readiness: keep Enter World closed while the list refreshes.
Transforms the pinned original `characterselect.lua` of the native client
(1.60.1.70334). The original asks for a new character list whenever the screen
appears, but Enter World (key, button, double click, context action) is not
tied to that request, so a selection from the previous list can be sent before
the new list arrives. Three one-line hooks call the owned helper
`compat/glue/character_list_ready.lua`, which is prepended to the file:
CharacterSelect_AllowedToEnterWorld false while the list is awaited
CharacterSelect_EnterWorld returns while the list is awaited
CHARACTER_LIST_UPDATE branch a list received while the screen is
hidden leaves Enter World closed
Nothing is synthesized and no login or credential code is touched. Usage:
python3 ops/character_select_ready_ui.py <original characterselect.lua> <output>
"""
import argparse
import hashlib
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SOURCE_SHA256 = '26942804434fd0808c07019cb60f199c56664090e57711b02e9a1dfc6feb1537'
SOURCE_REFERENCE = 'interface/addons/blizzard_gluexml/mainline/characterselect.lua'
HELPER = ROOT / 'compat/glue/character_list_ready.lua'
HOOKS = (
('permission',
'function CharacterSelect_AllowedToEnterWorld()\n'
'\tlocal isAccountLocked = CharacterSelectUtil.IsAccountLocked();\n',
'function CharacterSelect_AllowedToEnterWorld()\n'
'\tif CharacterListReady.Held(CharacterSelect) then\n\t\treturn false;\n\tend\n\n'
'\tlocal isAccountLocked = CharacterSelectUtil.IsAccountLocked();\n'),
('enter',
'function CharacterSelect_EnterWorld()\n'
'\tif (CharacterSelectUtil.IsAccountLocked()) then\n',
'function CharacterSelect_EnterWorld()\n'
'\tif CharacterListReady.Held(CharacterSelect, true) then\n\t\treturn;\n\tend\n\n'
'\tif (CharacterSelectUtil.IsAccountLocked()) then\n'),
('list update',
'\t\tself.waitingforCharacterList = false;\n\t\tUpdateCharacterList();\n\t\tUpdateAddonButton();\n',
'\t\tself.waitingforCharacterList = CharacterListReady.Received(self, listSize);\n'
'\t\tUpdateCharacterList();\n\t\tUpdateAddonButton();\n'),
)
def apply(text):
"""Insert the three hooks into LF-normalized original text."""
for label, before, after in HOOKS:
if text.count(before) != 1:
raise ValueError('Original character-select anchor differs: ' + label)
text = text.replace(before, after, 1)
return text
def add_account_back_notification(source):
"""Notify the owned GlueParent adapter immediately before the original Account Back."""
if not isinstance(source, bytes) or hashlib.sha256(source).hexdigest() != SOURCE_SHA256:
raise ValueError('Pinned original character-select input differs')
newline = b'\r\n' if b'\r\n' in source else b'\n'
anchor = newline.join((b'\tCharacterSelectUI:ReleaseCharacterOverlayFrames();',
b'\tC_Login.DisconnectFromServer();', b'\tClearOutage();'))
before_disconnect = b'\tif type(GlueParent_SourceAccountBack) == "function" then GlueParent_SourceAccountBack(); end'
if source.count(anchor) != 1:
raise ValueError('Original Account Back action differs')
return source.replace(anchor, anchor.replace(newline, newline + before_disconnect + newline, 1))
def transform(source):
"""Pinned original bytes -> transformed bytes, original line endings kept."""
if not isinstance(source, bytes) or hashlib.sha256(source).hexdigest() != SOURCE_SHA256:
raise ValueError('Pinned original character-select input differs')
newline = '\r\n' if b'\r\n' in source else '\n'
text = apply(source.decode('utf-8').replace('\r\n', '\n'))
helper = HELPER.read_text(encoding='utf-8')
if not helper.endswith('\n'):
helper += '\n'
return (helper + '\n' + text).replace('\n', newline).encode('utf-8')
def main():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('original', type=Path)
parser.add_argument('output', type=Path)
parser.add_argument('--account-back-only', action='store_true',
help='Notify GlueParent when the original roster Back action exits the account')
options = parser.parse_args()
if options.output.exists():
parser.error('output exists; existing candidates are preserved')
original = options.original.read_bytes()
result = add_account_back_notification(original) if options.account_back_only else transform(original)
options.output.parent.mkdir(parents=True, exist_ok=True)
options.output.write_bytes(result)
hooks = '1 account Back hook' if options.account_back_only else f'{len(HOOKS)} hooks'
print(f'{SOURCE_REFERENCE}: {hooks}, sha256 {hashlib.sha256(result).hexdigest()}')
return 0
if __name__ == '__main__':
sys.exit(main())