Files
praxisandClaude Fable 5.2 cf9ad2ff3c Client interface: addons, login-screen adapters and launcher
66 files, from working commit b1a079a.

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

272 lines
15 KiB
Lua

-- Original70334 item tooltips, using public server-derived component metadata.
-- Source bands and optional base-item primary presentation. This does not
-- change ItemSparse or compiled damage APIs/combat calculations.
-- Pinned original TooltipDataHandler AddTooltipPostCall receives tooltip,data;
-- TooltipUtil.GetDisplayedItem uses the Item tooltipData.id as its item identity.
local states = setmetatable({}, {__mode = "k"})
local function public(value)
if type(issecretvalue) == "function" then
local ok, hidden = pcall(issecretvalue, value)
if not ok or hidden then return false end
end
return true
end
local function integer(value, low, high)
return public(value) and type(value) == "number" and value == value and
value >= low and value <= high and value % 1 == 0
end
local function amount(value)
return public(value) and type(value) == "number" and value == value and value >= 0 and value <= 2147483647
end
local function context(tooltip, data)
if not public(tooltip) or type(tooltip) ~= "table" or not public(data) or type(data) ~= "table" then return end
if not integer(data.type, 0, 0) or not integer(data.id, 1, 2147483647) then return end
local itemID = data.id
local profile = GatewaySourceWeaponDamageData
if not public(profile) or type(profile) ~= "table" or (profile.schemaVersion ~= 1 and profile.schemaVersion ~= 2 and profile.schemaVersion ~= 3 and profile.schemaVersion ~= 4 and profile.schemaVersion ~= 5) or profile.locale ~= "enUS" or
type(GetLocale) ~= "function" or GetLocale() ~= "enUS" then return end
if not public(profile.items) or type(profile.items) ~= "table" then return end
if not public(C_Item) or type(C_Item) ~= "table" or type(C_Item.GetItemInfoInstant) ~= "function" or
type(C_Item.GetItemInfo) ~= "function" then return end
-- Verify original item identity and category. Do not interpret hyperlinks or
-- accept an ID supplied by arbitrary addon text as an engine item tooltip.
local ok, originalID, originalClass = pcall(function()
local foundID, _, _, _, _, classID = C_Item.GetItemInfoInstant(itemID)
return foundID, classID
end)
if not ok or not integer(originalID, 1, 2147483647) or originalID ~= itemID or not integer(originalClass, 2, 2) then return end
-- Item basic/instant metadata can exist while the full ItemSparse record
-- is still missing. Do not decorate "Retrieving item information" with a
-- partial source line and make that unresolved item look successfully loaded.
local complete, itemName, loadedClass = pcall(function()
local name, _, _, _, _, _, _, _, _, _, _, classID = C_Item.GetItemInfo(itemID)
return name, classID
end)
if not complete or not public(itemName) or type(itemName) ~= "string" or #itemName == 0 or #itemName > 512 or
not integer(loadedClass, 2, 2) then return end
return itemID, profile
end
local function appendSourceBands(tooltip, data, collectOnly)
local itemID, profile = context(tooltip, data)
if not itemID then return end
local bands = profile.items[itemID]
if not public(bands) or type(bands) ~= "table" or #bands < 1 or #bands > 4 then return end
-- Validate the complete requested record before adding any line. Source
-- slots are zero-based: index0 is already the native primary damage line.
local lines, previous = {}, 0
for i = 1, #bands do
local band = bands[i]
if not public(band) or type(band) ~= "table" or not integer(band.index, 1, 4) or band.index <= previous or
not integer(band.school, 0, 6) or not amount(band.minimum) or not amount(band.maximum) or
band.maximum <= 0 or band.maximum < band.minimum then return end
previous = band.index
if not public(profile.schools) or type(profile.schools) ~= "table" then return end
local label = profile.schools[band.school]
if not public(label) or type(label) ~= "string" or not label:match("^[A-Za-z]+$") or #label > 16 then return end
lines[#lines + 1] = string.format("+%g - %g %s Damage", band.minimum, band.maximum, label)
end
if collectOnly then return itemID, lines end
if type(tooltip.AddLine) ~= "function" or type(tooltip.ClearLines) ~= "function" or type(hooksecurefunc) ~= "function" then return end
local state = states[tooltip]
if not state then
state = {added = {}}
-- Original InternalProcessInfo clears non-appended tooltips before
-- rebuilding. A secure post-hook tracks that lifecycle without replacing
-- its method, reading protected font strings, or hooking gameplay APIs.
local hooked = pcall(hooksecurefunc, tooltip, "ClearLines", function() state.added = {} end)
if not hooked then return end
states[tooltip] = state
end
if state.added[itemID] then return end
state.added[itemID] = true
for _, line in ipairs(lines) do tooltip:AddLine(line, 1, 1, 1, false) end
end
-- Build70334 InternalProcessInfo clears lines, then calls the tooltip pre-call;
-- ProcessLine calls the line pre-call and consumes the line only on true.
-- Base-equivalent native instance and shopping tooltips must independently
-- match their raw base damage, speed and DPS; changed instance lines stay native.
local primaryStates = setmetatable({}, {__mode = "k"})
local diagnostics = {baseTooltips = 0, damageLines = 0, dpsLines = 0, errors = 0, instanceBaseMatches = 0, instanceDifferences = 0}
GatewaySourceWeaponDamageDiagnostics = diagnostics
local damageSchools = {Holy=true,Fire=true,Nature=true,Frost=true,Shadow=true,Arcane=true}
local function displayAmount(text)
return type(text) == "string" and (text:match("^%d+$") or text:match("^%d+%.%d+$")) ~= nil
end
local function damageLine(text)
local minimum, maximum, label = text:match("^([^ ]+) %- ([^ ]+) (.+)$")
if not displayAmount(minimum) or not displayAmount(maximum) then return false end
if label == "Damage" then return true end
local school = label:match("^([A-Za-z]+) Damage$")
return school and damageSchools[school]
end
local function dpsLine(text)
local value = text:match("^%(([^ ]+) damage per second%)$")
return displayAmount(value)
end
local function nativePrimary(data)
if not public(data) or type(data) ~= "table" or not public(data.lines) or type(data.lines) ~= "table" or #data.lines > 256 then return end
local band, dps
for index, line in ipairs(data.lines) do
if not public(line) or type(line) ~= "table" or not public(line.type) or not public(line.leftText) or not public(line.rightText) then return end
if line.type == 0 and type(line.leftText) == "string" then
if damageLine(line.leftText) and type(line.rightText) == "string" and line.rightText:match("^Speed %d+%.%d%d$") then
if band then return end
band = {left = line.leftText, right = line.rightText, index = index, color = line.leftColor}
elseif dpsLine(line.leftText) and (line.rightText == nil or line.rightText == "") then
if dps then return end
dps = line.leftText
end
end
end
if band and dps then return {left = band.left, right = band.right, dps = dps, index = band.index, color = band.color} end
end
-- Original70334 calls tooltipPreCall before iterating this same public lines
-- table. Keep every native/owner line intact and add source bands at its damage
-- anchor, rather than appending them after proc/set/issue-report footer lines.
local structuredBands = setmetatable({}, {__mode = "k"})
local function insertSourceBands(tooltip, data)
if not public(data) or type(data) ~= "table" or not public(data.lines) or type(data.lines) ~= "table" then return end
if #data.lines > 1024 then return end
for _, line in ipairs(data.lines) do
if not public(line) or type(line) ~= "table" then return end
end
local owned = structuredBands[data]
if owned then
for index = #data.lines, 1, -1 do
if owned[data.lines[index]] then table.remove(data.lines, index) end
end
structuredBands[data] = nil
end
local itemID, bands = appendSourceBands(tooltip, data, true)
if not itemID then return end
local anchor = nativePrimary(data)
if not anchor or not public(anchor.color) then return end
local inserted = {}
for index, text in ipairs(bands) do
local line = {type = 0, leftText = text, leftColor = anchor.color, wrapText = false}
table.insert(data.lines, anchor.index + index, line)
inserted[line] = true
end
structuredBands[data] = inserted
end
local function preparePrimary(tooltip, data)
if not public(tooltip) or type(tooltip) ~= "table" then return end
primaryStates[tooltip] = nil
local itemID, profile = context(tooltip, data)
if not itemID or (profile.schemaVersion ~= 2 and profile.schemaVersion ~= 3 and profile.schemaVersion ~= 4 and profile.schemaVersion ~= 5) or not public(profile.primary) or type(profile.primary) ~= "table" then return end
local row = profile.primary[itemID]
if not public(row) or type(row) ~= "table" or not amount(row.minimum) or not amount(row.maximum) or
row.maximum <= 0 or row.maximum < row.minimum or not integer(row.delayMS, 1, 2147483647) or
not amount(row.dps) or type(tooltip.GetProcessingTooltipInfo) ~= "function" or
type(tooltip.AddDoubleLine) ~= "function" or type(tooltip.AddLine) ~= "function" then return end
local label = "Damage"
if profile.schemaVersion == 4 or profile.schemaVersion == 5 then
if not integer(row.school, 0, 6) then return end
if row.school > 0 then
local school = public(profile.schools) and type(profile.schools) == "table" and profile.schools[row.school]
if not public(school) or type(school) ~= "string" or not damageSchools[school] then return end
label = school .. " Damage"
end
end
local info = tooltip:GetProcessingTooltipInfo()
if not public(info) or type(info) ~= "table" or not public(info.getterName) or
not public(info.getterArgs) or not public(info.getterFunction) then return end
-- Original70334 TooltipComparisonManager fetches GetItemByGUID/GetHyperlink
-- itself, then passes ProcessInfo({tooltipData=data,append=true}). There is
-- no getter or argument table on this native shopping-tooltip path.
local rawComparison = info.getterName == nil and info.getterFunction == nil and
info.getterArgs == nil and public(info.tooltipData) and info.tooltipData == data
local arg
if info.getterArgs ~= nil then
if type(info.getterArgs) ~= "table" then return end
arg = info.getterArgs[1]
if not public(arg) then return end
end
local isBase = (info.getterName == "GetItemByID" and arg == itemID) or
(info.getterName == "GetHyperlink" and arg == "item:" .. itemID)
local expected
if not isBase then
local instanceGetter = type(info.getterArgs) == "table" and (info.getterName == "GetInventoryItem" or info.getterName == "GetInventoryItemByID" or
info.getterName == "GetBagItem" or info.getterName == "GetBagItemChild" or
info.getterName == "GetHyperlink" or info.getterName == "GetItemByGUID")
if profile.baseEquivalentInstances ~= true or not (rawComparison or instanceGetter) or
not public(C_TooltipInfo) or type(C_TooltipInfo) ~= "table" or type(C_TooltipInfo.GetItemByID) ~= "function" then return end
local base = C_TooltipInfo.GetItemByID(itemID)
if not public(base) or type(base) ~= "table" or not integer(base.type, 0, 0) or not integer(base.id, itemID, itemID) then return end
expected = nativePrimary(base)
local current = nativePrimary(data)
if not expected or not current or current.left ~= expected.left or current.right ~= expected.right or current.dps ~= expected.dps then
diagnostics.instanceDifferences = diagnostics.instanceDifferences + 1
return
end
diagnostics.instanceBaseMatches = diagnostics.instanceBaseMatches + 1
else
diagnostics.baseTooltips = diagnostics.baseTooltips + 1
end
primaryStates[tooltip] = {row = row, label = label, damage = false, dps = false, expected = expected}
diagnostics.lastItemID = itemID
end
local function replacePrimaryLine(tooltip, line)
if not public(tooltip) or type(tooltip) ~= "table" or not public(line) or type(line) ~= "table" then return end
local state = primaryStates[tooltip]
if not state or not integer(line.type, 0, 0) or not public(line.leftText) or type(line.leftText) ~= "string" then return end
local row, left, right = state.row, line.leftText, line.rightText
if state.expected and not (left == state.expected.dps or (left == state.expected.left and public(right) and right == state.expected.right)) then return end
if not state.damage and damageLine(left) and public(right) and type(right) == "string" and
right:match("^Speed %d+%.%d%d$") then
tooltip:AddDoubleLine(string.format("%g - %g %s", row.minimum, row.maximum, state.label),
string.format("Speed %.2f", row.delayMS / 1000), 1, 1, 1, 1, 1, 1)
state.damage = true
diagnostics.damageLines = diagnostics.damageLines + 1
return true
end
if state.damage and not state.dps and dpsLine(left) and
public(right) and (right == nil or right == "") then
tooltip:AddLine(string.format("(%.1f damage per second)", row.dps), 1, 1, 1, false)
state.dps = true
diagnostics.dpsLines = diagnostics.dpsLines + 1
return true
end
end
-- Missing/changed native API contracts fail closed. No tooltip replacement,
-- frame creation, C_Item override, item mutation, cast or server request.
local ok = pcall(function()
if type(TooltipDataProcessor) == "table" and type(TooltipDataProcessor.AddTooltipPostCall) == "function" and
type(Enum) == "table" and type(Enum.TooltipDataType) == "table" and Enum.TooltipDataType.Item == 0 then
local structuredLines = type(TooltipDataProcessor.AddTooltipPreCall) == "function" and
type(TooltipDataProcessor.AddLinePreCall) == "function" and
type(Enum.TooltipDataLineType) == "table" and Enum.TooltipDataLineType.None == 0
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, data)
-- Preserve the existing older-API fallback, never append a second copy
-- after the footer when the original70334 structured path is available.
if not structuredLines then pcall(appendSourceBands, tooltip, data) end
end)
if structuredLines then
TooltipDataProcessor.AddTooltipPreCall(Enum.TooltipDataType.Item, function(tooltip, data)
local good = pcall(function()
insertSourceBands(tooltip, data)
preparePrimary(tooltip, data)
end)
if not good then diagnostics.errors = diagnostics.errors + 1 end
end)
TooltipDataProcessor.AddLinePreCall(Enum.TooltipDataLineType.None, function(tooltip, line)
local good, consumed = pcall(replacePrimaryLine, tooltip, line)
if not good then diagnostics.errors = diagnostics.errors + 1; return end
return consumed
end)
end
end
end)