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

27 lines
1.8 KiB
Python

"""Inject the saved-account UI into AccountLogin without changing the priority gate."""
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def prepare(source):
newline = '\r\n' if b'\r\n' in source else '\n'
text = source.decode('utf-8').replace('\r\n', '\n')
helper = (ROOT / 'compat/glue/remember_password.lua').read_text()
prefix = 'local ForeverRememberPassword = (function()\n'
if text.startswith(prefix):
boundary = text.find('\nend)();\n', len(prefix))
if boundary < 0 or text.count('ForeverRememberPassword.Setup(self);') != 1 or text.count('ForeverRememberPassword.BeforeLogin(') != 1:
raise ValueError('Installed account-list closure boundaries differ')
text = prefix + helper + text[boundary:]
return text.replace('\n', newline).encode()
show = '\tAccountLogin_CheckAutoLogin();\nend\n'
login = '\t\tC_Login.Login(string.gsub(username, "||", "|"), AccountLogin.UI.PasswordEditBox);'
start = text.find('function AccountLogin_OnShow(self)\n')
end = text.find('\nfunction ', start + 1)
if start < 0 or end < 0 or text[start:end + 1].count(show) != 1 or text.count(login) != 1 or 'ForeverRememberPassword' in text:
raise ValueError('AccountLogin boundaries differ or remember-password already installed')
helper = (ROOT / 'compat/glue/remember_password.lua').read_text()
block = text[start:end + 1].replace(show, '\tAccountLogin_CheckAutoLogin();\n\tForeverRememberPassword.Setup(self);\nend\n', 1)
text = text[:start] + block + text[end + 1:]
text = 'local ForeverRememberPassword = (function()\n' + helper + '\nend)();\n' + text
text = text.replace(login, '\t\tif not ForeverRememberPassword.BeforeLogin(string.gsub(username, "||", "|"), AccountLogin.UI.PasswordEditBox) then return; end\n' + login, 1)
return text.replace('\n', newline).encode()