Files
WoW-Hybrid-gateway/ops/native_glue_addon_probe.py
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

158 lines
10 KiB
Python

#!/usr/bin/env python3
"""Stage/install/restore an owned read-only ordinary Glue addon in the private client.
Original TOCs demonstrate AllowLoad:Glue, not that third-party Glue addons load.
Only an actual login-screen marker can establish that. No core UI replacement,
engine calls, state/label changes, credentials or validation overrides.
"""
import argparse,datetime,hashlib,json,os,shutil,subprocess
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
ADDON='WoWHybridGlueProbe'
TARGET=ROOT/'runtime/native-client/_classic_beta_/Interface/AddOns'/ADDON
JOURNAL=ROOT/'runtime/native-glue-addon-probe-install.json'
DEFAULT_STAGE=ROOT/'runtime/native-glue-addon-probe-stage'
KIND='owned-private-glue-addon-probe'
TOC='''## Interface: 16001
## Title: WoW-Hybrid Read-Only Glue Load Probe
## Notes: Public load/context markers only; no interface or authentication changes.
## Version: 1
## Dep: Blizzard_GlueParent
## Dep: Blizzard_GlueXML
## LoadFirst: 1
## AllowLoad: Glue
GlueProbe.lua
'''
LUA='''-- Read-only probe. Do not wrap handlers, replace namespaces or access credentials.
local emitted, previous = 0, nil;
local function scalar(value)
if type(issecretvalue) == "function" and issecretvalue(value) then return "restricted"; end
local kind = type(value);
if kind == "boolean" or kind == "number" then return tostring(value); end
return "unavailable";
end
local function ReportGlueLoad(reason)
if emitted >= 32 or type(C_Log) ~= "table" or type(C_Log.LogMessage) ~= "function" then return; end
local hasParent = type(GlueParentMixin) == "table" and GlueParent ~= nil;
local hasAccount = AccountLogin ~= nil and AccountLogin.UI ~= nil;
local hasLogin = type(C_Login) == "table" and type(C_Login.GetState) == "function";
local parts = {"GW_GLUE_ADDON_PROBE revision=1", "event=" .. reason,
"context=" .. ((hasParent and hasAccount and hasLogin) and "glue-model-present" or "game-or-other"),
"parent=" .. tostring(hasParent), "accountFrame=" .. tostring(hasAccount), "loginAPI=" .. tostring(hasLogin)};
if hasLogin then
local ok, state = pcall(C_Login.GetState);
if ok and type(state) == "table" then
for _, key in ipairs({"connectedToWoW", "hasRealmList", "superDistrictChoicePending", "waitingForRuleSets"}) do
parts[#parts + 1] = key .. "=" .. scalar(state[key]);
end
end
end
local realm = C_RealmList;
if type(realm) == "table" and type(realm.GetAvailableCategories) == "function" and type(realm.GetRealmsInCategory) == "function" then
local ok, categories = pcall(realm.GetAvailableCategories);
if ok and type(categories) == "table" and #categories <= 64 then
local count, complete = 0, true;
for _, category in ipairs(categories) do
local got, rows = pcall(realm.GetRealmsInCategory, category);
if not got or type(rows) ~= "table" or #rows > 256 then complete = false; break; end
count = count + #rows;
end
parts[#parts + 1] = "categories=" .. #categories;
parts[#parts + 1] = "realms=" .. (complete and count or "unavailable");
end
end
local message = table.concat(parts, " ");
if message ~= previous then C_Log.LogMessage(message); previous = message; emitted = emitted + 1; end
end
ReportGlueLoad("load");
local observer = CreateFrame("Frame");
for _, event in ipairs({"FRAMES_LOADED", "LOGIN_STATE_CHANGED", "REALM_LIST_UPDATED"}) do
pcall(observer.RegisterEvent, observer, event);
end
observer:SetScript("OnEvent", function(_, event) ReportGlueLoad(event); end);
'''
def files():return {ADDON+'.toc':TOC.encode(),'GlueProbe.lua':LUA.encode()}
def hashes(values):return {name:hashlib.sha256(data).hexdigest() for name,data in values.items()}
def tree(path):
if path.is_symlink() or not path.is_dir():raise RuntimeError('Expected regular owned probe directory')
rows=list(path.iterdir())
if {p.name for p in rows}!=set(files()) or any(p.is_symlink() or not p.is_file() for p in rows):raise RuntimeError('Unexpected probe contents preserved')
return {p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in rows}
def write_json(path,value):
temporary=path.with_name(path.name+'.new')
fd=os.open(temporary,os.O_WRONLY|os.O_CREAT|os.O_EXCL|os.O_NOFOLLOW,0o600)
with os.fdopen(fd,'w') as output:json.dump(value,output,indent=2);output.write('\n');output.flush();os.fsync(output.fileno())
temporary.replace(path)
def owned_manifest():
if JOURNAL.is_symlink() or not JOURNAL.is_file():raise RuntimeError('Existing probe has no owned manifest; preserve it')
result=json.loads(JOURNAL.read_text())
if result.get('kind')!=KIND or result.get('build')!=70334 or result.get('target')!=str(TARGET.relative_to(ROOT)) or result.get('state') not in ('installed','restored'):raise RuntimeError('Unrecognized probe manifest preserved')
return result
def closed_client():
from client_installation import running_clients,inspect_installation
if running_clients():raise RuntimeError('Close development WowB normally before probe install/restore')
inspect_installation(ROOT/'runtime/native-client')
for parent in (TARGET,*TARGET.parents):
if parent==ROOT:break
if parent.is_symlink():raise RuntimeError('Linked private probe path preserved')
def stage(directory):
directory=Path(directory)
if not directory.is_absolute():directory=ROOT/directory
if directory.is_symlink() or not directory.resolve().is_relative_to(ROOT/'runtime') or directory.resolve().is_relative_to(ROOT/'runtime/native-client'):raise RuntimeError('Require inactive private runtime stage directory')
expected=hashes(files());manifest=directory/'manifest.json';addon=directory/ADDON
if directory.exists():
if manifest.is_symlink() or not manifest.is_file() or json.loads(manifest.read_text()).get('files')!=expected or tree(addon)!=expected:raise RuntimeError('Existing stage differs; preserved')
return json.loads(manifest.read_text())
subprocess.run(['luac','-p','-'],input=LUA.encode(),check=True)
addon.mkdir(parents=True,mode=0o700)
for name,data in files().items():(addon/name).write_bytes(data);(addon/name).chmod(0o600)
result=dict(kind=KIND,build=70334,target=str(TARGET.relative_to(ROOT)),files=expected,scope='Read-only original Glue-context discovery; no UI/hooks/account/network changes',load_verified=False,source_tocs=['Blizzard_GlueParent.toc FID8286095','Blizzard_GlueXML.toc FID8286096'],limits=['Original AllowLoad:Glue/LoadFirst/Dep syntax is verified; third-party Glue discovery/eligibility is unverified.','A game-or-other marker is not a successful Glue load.','No marker is not proof of why discovery failed.'],rollback='Close WowB normally; run this tool restore. Only hash-owned probe files are moved to recovery; previous owned probe, if any, is restored.')
write_json(manifest,result);return result
def install(directory):
closed_client();directory=Path(directory)
if not directory.is_absolute():directory=ROOT/directory
if directory.is_symlink() or not directory.resolve().is_relative_to(ROOT/'runtime') or directory.resolve().is_relative_to(ROOT/'runtime/native-client'):raise RuntimeError('Require inactive owned private runtime stage')
manifest=directory/'manifest.json'
if manifest.is_symlink() or not manifest.is_file():raise RuntimeError('Stage the probe before installation')
staged=json.loads(manifest.read_text());expected=hashes(files())
if staged.get('kind')!=KIND or staged.get('build')!=70334 or staged.get('target')!=str(TARGET.relative_to(ROOT)) or staged.get('files')!=expected or tree(directory/ADDON)!=expected:raise RuntimeError('Staged probe differs from reviewed source')
if JOURNAL.is_symlink():raise RuntimeError('Linked installation manifest preserved')
previous=None
if TARGET.exists() or TARGET.is_symlink():
previous=owned_manifest()
if tree(TARGET)!=previous.get('files'):raise RuntimeError('Changed or third-party probe preserved')
elif JOURNAL.exists():
previous=owned_manifest()
if previous.get('files'):raise RuntimeError('Owned probe missing; inspect before installing')
previous=None
stamp=datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%S.%fZ');recovery=ROOT/'recovery'/('native-glue-addon-probe-'+stamp);recovery.mkdir(parents=True,mode=0o700)
shutil.copytree(directory/ADDON,recovery/'candidate-addon')
if previous:shutil.copy2(JOURNAL,recovery/'previous-manifest.json')
result=dict(staged,state='installing',recovery=str(recovery.relative_to(ROOT)),previous_files=previous['files'] if previous else None)
write_json(JOURNAL,result)
TARGET.parent.mkdir(parents=True,exist_ok=True)
if previous:TARGET.rename(recovery/'previous-addon')
(recovery/'candidate-addon').rename(TARGET)
result['state']='installed';write_json(JOURNAL,result);return result
def restore():
closed_client();current=owned_manifest()
if current['state']=='restored':
if current.get('files') and tree(TARGET)!=current['files']:raise RuntimeError('Changed restored probe preserved')
if not current.get('files') and (TARGET.exists() or TARGET.is_symlink()):raise RuntimeError('Unowned replacement preserved')
return current
if tree(TARGET)!=current.get('files'):raise RuntimeError('Changed probe preserved; no blind rollback')
recovery=ROOT/current['recovery']
if recovery.is_symlink() or not recovery.resolve().is_relative_to(ROOT/'recovery') or (recovery/'removed-addon').exists():raise RuntimeError('Recovery path differs; preserve probe')
previous=current.get('previous_files')
if previous and tree(recovery/'previous-addon')!=previous:raise RuntimeError('Previous owned probe backup differs')
TARGET.rename(recovery/'removed-addon')
if previous:shutil.copytree(recovery/'previous-addon',TARGET)
current.update(state='restored',files=previous or {},previous_files=None)
write_json(JOURNAL,current);return current
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('action',choices=('stage','install','restore'));p.add_argument('--stage',type=Path,default=DEFAULT_STAGE);a=p.parse_args()
result=stage(a.stage) if a.action=='stage' else install(a.stage) if a.action=='install' else restore()
print(json.dumps(result,indent=2))