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

116 lines
7.6 KiB
Lua

-- Present source armor totals after the original engine computes the same total.
-- Item/stat APIs, curves, enchants, source equip spells and combat are untouched.
local states = setmetatable({}, {__mode="k"})
local diagnostics = {armor=0, block=0, skipped=0, errors=0}
GWArmorPresentationDiagnostics = diagnostics
local function public(v)
if type(issecretvalue)=="function" then
local ok,hidden=pcall(issecretvalue,v)
if not ok or hidden then return false end
end
return true
end
local function integer(v,low,high)
return public(v) and type(v)=="number" and v==v and v%1==0 and v>=low and v<=high
end
local function number(text)
if not public(text) or type(text)~="string" or not text:match("^%d[%d,]*$") then return end
local plain=text:gsub(",","");local value=tonumber(plain)
if not integer(value,0,2147483647) then return end
-- Reject malformed separators instead of parsing arbitrary tooltip text.
if text:find(",") and not text:match("^%d%d?%d?,%d%d%d$") then return end
return value
end
local function formatted(value)
if value<1000 then return tostring(value) end
return string.format("%d,%03d",math.floor(value/1000),value%1000)
end
local function scan(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 result={adjustments={},blocks={}}
for _,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" and (line.rightText==nil or line.rightText=="") then
local text=line.leftText
local armor=number(text:match("^(%d[%d,]*) Armor$"))
local sign,delta=text:match("^([+-])(%d[%d,]*) Armor$")
local block=number(text:match("^(%d[%d,]*) Block$"))
local flat=number(text:match("^Equip: Increases the Block Value of your shield by (%d[%d,]*)%.$"))
if armor then
if result.armor then return end
result.armor={text=text,value=armor}
elseif delta then
delta=number(delta)
if not delta then return end
result.adjustments[#result.adjustments+1]={text=text,value=sign=="-" and -delta or delta}
elseif block then
if result.block then return end
result.block={text=text,value=block}
elseif flat then
result.blocks[#result.blocks+1]={text=text,value=flat}
end
end
end
return result
end
local function prepare(tooltip,data)
if not public(tooltip) or type(tooltip)~="table" then return end
states[tooltip]=nil
if GetLocale()~="enUS" or not public(data) or type(data)~="table" or not integer(data.type,0,0) or not integer(data.id,1,2147483647) then return end
local profile=GWArmorPresentationData
if not public(profile) or type(profile)~="table" or profile.version~=1 or not public(profile.items) or type(profile.items)~="table" then return end
local row=profile.items[data.id]
if not public(row) or type(row)~="table" or not integer(row.armor,1,999999) or not integer(row.block,0,999999) or not integer(row.subclass,1,6) then return end
local id,_,_,_,_,class,subclass=C_Item.GetItemInfoInstant(data.id)
local name=C_Item.GetItemInfo(data.id)
if not integer(id,data.id,data.id) or not integer(class,4,4) or not integer(subclass,row.subclass,row.subclass) or not public(name) or type(name)~="string" or name=="" then return end
if type(tooltip.GetProcessingTooltipInfo)~="function" or type(tooltip.AddLine)~="function" then return end
local info=tooltip:GetProcessingTooltipInfo()
if not public(info) or type(info)~="table" or not public(info.getterName) or not public(info.getterArgs) or type(info.getterArgs)~="table" then return end
local arg=info.getterArgs[1]
if not public(arg) then return end
local base=(info.getterName=="GetItemByID" and arg==data.id) or (info.getterName=="GetHyperlink" and arg=="item:"..data.id)
if not base and info.getterName~="GetInventoryItem" and info.getterName~="GetBagItem" and info.getterName~="GetHyperlink" then return end
local current=scan(data)
local reference=base and current or scan(C_TooltipInfo.GetItemByID(data.id))
local stats=C_Item.GetItemStats("item:"..data.id)
if not current or not reference or not public(stats) or type(stats)~="table" then return end
local state={}
-- Reconcile only one unambiguous base adjustment. Instance armor changes or
-- additional armor enchants that introduce ambiguous lines preserve native UI.
if current.armor and reference.armor and current.armor.text==reference.armor.text and #current.adjustments==1 and #reference.adjustments==1 then
local delta=current.adjustments[1]
if delta.text==reference.adjustments[1].text and integer(stats.RESISTANCE0_NAME,row.armor,row.armor) and current.armor.value+delta.value==row.armor then
state.armor=current.armor.text;state.adjustment=delta.text;state.armorValue=row.armor
end
end
if row.subclass==6 and row.block>0 and current.block and reference.block and current.block.text==reference.block.text and integer(stats.ITEM_MOD_BLOCK_VALUE_SHORT,row.block,row.block) then
local matches=0
for _,line in ipairs(current.blocks) do if line.value==row.block then matches=matches+1;state.flatBlock=line.text end end
local baseMatches=0
for _,line in ipairs(reference.blocks) do if line.value==row.block then baseMatches=baseMatches+1 end end
if matches==1 and baseMatches==1 then state.block=current.block.text;state.blockValue=row.block else state.flatBlock=nil end
end
if state.armor or state.block then states[tooltip]=state else diagnostics.skipped=diagnostics.skipped+1 end
end
local function line(tooltip,data)
if not public(tooltip) or type(tooltip)~="table" or not public(data) or type(data)~="table" or not integer(data.type,0,0) or not public(data.leftText) or not public(data.rightText) or (data.rightText~=nil and data.rightText~="") then return end
local state=states[tooltip]
if not state or type(data.leftText)~="string" then return end
if state.armor and data.leftText==state.armor then
tooltip:AddLine(formatted(state.armorValue).." Armor",1,1,1,false)
state.armor=nil;state.armorRendered=true;diagnostics.armor=diagnostics.armor+1;return true
elseif state.armorRendered and data.leftText==state.adjustment then
state.adjustment=nil;return true
elseif state.block and data.leftText==state.block then
tooltip:AddLine(formatted(state.blockValue).." Block",1,1,1,false)
state.block=nil;state.blockRendered=true;diagnostics.block=diagnostics.block+1;return true
elseif state.blockRendered and data.leftText==state.flatBlock then
state.flatBlock=nil;return true
end
end
if type(TooltipDataProcessor)=="table" and type(TooltipDataProcessor.AddTooltipPreCall)=="function" and type(TooltipDataProcessor.AddLinePreCall)=="function" and type(Enum)=="table" and type(Enum.TooltipDataType)=="table" and Enum.TooltipDataType.Item==0 and type(Enum.TooltipDataLineType)=="table" and Enum.TooltipDataLineType.None==0 then
TooltipDataProcessor.AddTooltipPreCall(0,function(t,d)local ok=pcall(prepare,t,d);if not ok then diagnostics.errors=diagnostics.errors+1 end end)
TooltipDataProcessor.AddLinePreCall(0,function(t,d)local ok,result=pcall(line,t,d);if not ok then diagnostics.errors=diagnostics.errors+1;return end;return result end)
end