Files

127 lines
6.0 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Opt-in companion for ops/native_model_probe.py. No work occurs on addon load.
-- Python owns publication/identity/auth/input-policy admission. This module only
-- presents explicitly queued numeric models in private diagnostic frames.
GWNativeModelProbe = GWNativeModelProbe or {}
local P = GWNativeModelProbe
P.version = 1
P.colors = {{0,1,0},{0,0,1},{1,0,1},{0,1,1},{1,1,0},{1,1,1}}
local function ordinary(value)
if type(issecretvalue) ~= "function" then return true end
local ok, secret = pcall(issecretvalue, value)
return ok and not secret
end
function P:Finish()
self.active = false
if self.frames then
for _, frame in ipairs(self.frames) do frame:Hide(); frame:ClearModel() end
end
if self.status then self.status:Hide() end
end
function P:Begin(run, size)
if type(run) ~= "string" or #run ~= 8 or not run:match("^[0-9a-f]+$") or size ~= 4 then
error("Bounded private model run/grid required")
end
if type(C_Timer) ~= "table" or type(C_Timer.After) ~= "function" then
error("Original timer unavailable; no model requests")
end
local archive = GetCVar("overrideArchive")
if not ordinary(archive) or archive ~= "0" then error("Original archive policy unavailable") end
self:Finish()
GatewayDiagnosticsSaved = GatewayDiagnosticsSaved or {}
local data = {run=run, models={}, groups={}, overrideArchive=archive, gridSize=4}
GatewayDiagnosticsSaved.nativeModelBatch = data
self.data, self.frames, self.pending = data, {}, {}
local width, height = UIParent:GetWidth(), UIParent:GetHeight()
local edge = math.min(450, (height - 150) / 2)
if edge < 160 then error("Original viewport too small") end
data.view = {width=width, height=height, edge=edge, gapX=24, gapY=44}
for i=1,4 do
local frame = CreateFrame("PlayerModel", nil, UIParent)
local x = ((i-1)%2 == 0 and -1 or 1) * (edge+24)/2
local y = (i <= 2 and 1 or -1) * (edge+44)/2
frame:SetSize(edge, edge); frame:SetPoint("CENTER", UIParent, "CENTER", x, y)
frame:SetFrameStrata("DIALOG")
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("BOTTOM", frame, "TOP", 0, 4)
frame.probeLabel = label; frame:Hide(); self.frames[i] = frame
end
local status = CreateFrame("Frame", nil, UIParent)
status:SetSize(48,48); status:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0,0)
status:SetFrameStrata("TOOLTIP"); status:EnableMouse(false)
local texture = status:CreateTexture(nil, "BACKGROUND")
texture:SetAllPoints(); texture:SetColorTexture(1,0,0,1)
local label = status:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
label:SetPoint("LEFT", status, "RIGHT", 8, 0); label:SetText("GW model grid prepared")
status.probeTexture, status.probeLabel = texture, label
self.status = status; status:Show()
end
function P:Poll(group)
if not self.active or self.group ~= group then return end
self.attempt = self.attempt + 1
local complete = true
for i, row in ipairs(self.pending) do
local frame = self.frames[i]
local ok, value = pcall(frame.GetModelFileID, frame)
if ok and ordinary(value) and type(value) == "number" then
row.loadedFileID = value
row.idMatches = value == row.requestedFileID
frame.probeLabel:SetText(row.requestedFileID .. " loaded " .. value)
else
row.loadedFileID = nil; row.idMatches = false; row.unavailableOrSecret = true
frame.probeLabel:SetText(row.requestedFileID .. " ID unavailable")
end
if not row.idMatches or not row.loadAccepted then complete = false end
end
if complete then
self.active = false
for _, row in ipairs(self.pending) do row.pending = false end
self.data.groups[#self.data.groups+1] = {group=group, ready=true, count=#self.pending}
local color = self.colors[(group-1)%#self.colors+1]
self.status.probeTexture:SetColorTexture(color[1],color[2],color[3],1)
self.status.probeLabel:SetText("GW group " .. group .. " ready " .. #self.pending)
elseif self.attempt < 20 then
C_Timer.After(0.1, function() P:Poll(group) end)
else
self.active = false; self.data.error = "loaded-id-timeout-or-unavailable"
self.data.groups[#self.data.groups+1] = {group=group, ready=false, count=#self.pending}
self.status.probeLabel:SetText("GW group " .. group .. " HELD")
end
end
function P:Show(ids, group)
if self.active or type(ids) ~= "table" or #ids < 1 or #ids > 4 or
type(group) ~= "number" or group < 1 or group > 8 or group%1 ~= 0 then
error("Bounded non-overlapping model cohort required")
end
local seen = {}
for _, id in ipairs(ids) do
if type(id) ~= "number" or id%1 ~= 0 or id <= 0 or id > 2147483647 or seen[id] then
error("Distinct numeric model identities required")
end
seen[id] = true
end
self.active, self.group, self.attempt, self.pending = true, group, 0, {}
self.status:Show(); self.status.probeTexture:SetColorTexture(1,0,0,1)
self.status.probeLabel:SetText("GW group " .. group .. " pending")
for i=1,4 do
local frame, id = self.frames[i], ids[i]
if id then
local row = {run=self.data.run, requestedFileID=id, fileID=id,
overrideArchive=self.data.overrideArchive, group=group, slot=i, pending=true}
self.pending[i] = row; self.data.models[#self.data.models+1] = row
frame:Show(); frame:ClearModel(); frame.probeLabel:SetText(id .. " pending")
row.loadAccepted = pcall(frame.SetModel, frame, id)
else
frame:Hide(); frame:ClearModel()
end
end
-- Completion is deferred, never claimed from the SetModel call's tick.
C_Timer.After(1.0, function() P:Poll(group) end)
end