Files

468 lines
21 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Original Inspect sends the request. A server-approved response contains only
-- the selected peer's visible item entries, which may include transmog.
local prefix = "GWInspectGear"
local pending, hooked, active, labels = nil, false, false, {}
local _, addon = ...
local enchantNames = type(addon) == "table" and addon.inspectEnchantNames or {}
local slots, enchants, names, fragments = {}, {}, {}, {}
-- Octo INSTransmogs data per slot: {appearance = item shown, real = item worn}. A transmogged slot reports a
-- generated server template as its visible entry; the tooltip uses the real item and only the icon changes.
local transmogs = {}
local approvalLifetime = 5
local namesUntil = 0
local action, pendingUntil, waitingForPanelUntil = 0, 0, nil
local visibilityObserver, tooltip, fallback
local fallbackReady = false
local function readable(value)
return not issecretvalue or not issecretvalue(value)
end
local function clear()
action, pendingUntil, waitingForPanelUntil = action + 1, 0, nil
fallbackReady = false
if fallback then fallback:Hide() end
if tooltip then tooltip:Hide() end
pending, active, slots, enchants, transmogs = nil, nil, {}, {}, {}
names, fragments, namesUntil = {}, {}, 0
for _, box in pairs(labels) do box:Hide() end
end
local function inspectedGuid()
if not InspectFrame or not InspectFrame.GetInspectUnit then return end
local unit = InspectFrame:GetInspectUnit()
if not readable(unit) or type(unit) ~= "string" then return end
local selected, inspectable = UnitIsUnit(unit, "target"), CanInspect(unit, true)
if not readable(selected) or not selected or not readable(inspectable) or not inspectable then return end
local guid = UnitGUID(unit)
if readable(guid) and type(guid) == "string" then return guid end
end
WoWHybridInspectEquipment = {}
function WoWHybridInspectEquipment.RequestApproval(guid)
local current = UnitGUID("target")
local player = UnitIsPlayer("target")
local visible = UnitIsVisible("target")
local inspectable = CanInspect("target", true)
if not readable(guid) or type(guid) ~= "string" or not readable(current) or guid ~= current
or not readable(player) or not player or not readable(visible) or not visible
or not readable(inspectable) or not inspectable then return end
local realm, low = guid:match("^Player%-(%d+)%-(%x+)$")
local owner = UnitName("player")
if realm and #low <= 8 and readable(owner) and type(owner) == "string" then
C_ChatInfo.SendAddonMessage(prefix, realm .. " " .. tostring(tonumber(low, 16)), "WHISPER", owner)
return true
end
end
local function selfSender(sender)
if not readable(sender) or type(sender) ~= "string" then return false end
local name, realm = UnitFullName("player")
if not readable(name) or type(name) ~= "string" then return false end
if sender == name then return true end
if not readable(realm) then return false end
if not realm or realm == "" then realm = GetNormalizedRealmName() end
return readable(realm) and type(realm) == "string" and realm ~= "" and sender == name .. "-" .. realm
end
local function unpackSlots(text, guid)
if #text > 255 then return end
local realm, low = guid:match("^Player%-(%d+)%-(%x+)$")
local words = {}
for word in text:gmatch("%S+") do words[#words + 1] = word end
if #words ~= 21 or not realm or tonumber(words[1]) ~= tonumber(realm)
or tonumber(words[2]) ~= tonumber(low, 16) then return end
local values = {}
for slot = 1, 19 do
local word = words[slot + 2]
if word ~= "-" then
if not word:match("^%d+$") or #word > 10 then return end
local value = tonumber(word)
if value > 4294967295 then return end
values[slot] = value
end
end
return values
end
local function receiveName(text, guid)
if GetTime() >= namesUntil or #text > 255 then return end
local realm, low, slot, entry, offset, size, piece =
text:match("^M (%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (.+)$")
if not realm or #piece > 192 or piece:find("[%c]") then return end
local currentRealm, currentLow = guid:match("^Player%-(%d+)%-(%x+)$")
slot, entry, offset, size = tonumber(slot), tonumber(entry), tonumber(offset), tonumber(size)
if not currentRealm or tonumber(realm) ~= tonumber(currentRealm) or tonumber(low) ~= tonumber(currentLow, 16)
or slot < 1 or slot > 19 or entry < 1 or slots[slot] ~= entry or names[slot]
or size < 1 or size > 255 or offset + #piece > size then return end
local partial = fragments[slot]
if offset == 0 then
partial = {size=size, text=""}
elseif not partial or partial.size ~= size or #partial.text ~= offset then
return
end
partial.text = partial.text .. piece
if #partial.text < size then
fragments[slot] = partial
return
end
-- Source names are data. A literal pipe must not introduce tooltip markup.
names[slot] = partial.text:gsub("|", "||")
fragments[slot] = nil
local box = fallback and fallback:IsShown() and fallback.rows[slot] or labels[slot]
if box and box:IsVisible() and tooltip and tooltip:IsShown() and tooltip:IsOwned(box) then
box:GetScript("OnEnter")(box)
end
return slot
end
local function showEnchant(layer, slot, title)
local value = enchants[layer] and enchants[layer][slot]
if value and value > 0 then
local description = enchantNames[value] or tostring(value)
tooltip:AddLine(title .. " " .. description, 0.8, 0.8, 0.8)
end
end
local function sourceIcon(item)
local icon = item and item > 0 and GWSourceItemIcons and type(GWSourceItemIcons.TextureForItem) == "function"
and GWSourceItemIcons.TextureForItem(item)
if readable(icon) then return icon end
end
local function realEntry(slot)
local data = transmogs[slot]
return data and data.real or slots[slot]
end
local function iconFor(slot)
local data = transmogs[slot]
local entry = data and data.appearance or slots[slot]
-- Source catalogue icons only: a Turtle ID can name a different native item.
return sourceIcon(entry)
end
local function clientKnows(entry)
if not entry or entry <= 0 or not C_Item or not C_Item.GetItemInfoInstant then return false end
local id = C_Item.GetItemInfoInstant(entry)
return readable(id) and id ~= nil
end
-- Octo InspectTransmogTooltip_OnShow: the appearance goes under the item name, in Octo's colour and wording.
local function markTransmog(self, slot)
local data = transmogs[slot]
if not data or not data.appearance or data.appearance == data.real then return end
local appearance = C_Item and C_Item.GetItemNameByID and C_Item.GetItemNameByID(data.appearance)
if not readable(appearance) or not appearance then
if Item and Item.CreateFromItemID then
Item:CreateFromItemID(data.appearance):ContinueOnItemLoad(function()
if tooltip:IsOwned(self) and self:IsMouseOver() then self:GetScript("OnEnter")(self) end
end)
end
return
end
local line = _G[tooltip:GetName() .. "TextLeft2"]
if not line then return end
local heading = TRANSMOG_CHANGED_TO or "Transmogrified to:"
local rest = line:GetText()
line:SetText("|cfff471f5" .. heading .. "\n" .. appearance .. "|r" .. (rest and rest ~= "" and ("\n" .. rest) or ""))
tooltip:Show()
end
local function showItem(self, slot)
tooltip:SetOwner(self, "ANCHOR_RIGHT")
local item = slots[slot]
local real = realEntry(slot)
if real and real > 0 and clientKnows(real) then
local permanent = enchants.P and tonumber(enchants.P[slot]) or 0
tooltip:SetHyperlink(string.format("item:%d:%d", real, permanent))
showEnchant("T", slot, "Temporary enchant")
markTransmog(self, slot)
tooltip:Show()
return
end
if item and item > 0 then
tooltip:SetText(names[slot] or string.format("Item %d", item))
tooltip:AddLine("Visible appearance", 0.8, 0.8, 0.8)
showEnchant("P", slot, "Permanent enchant")
showEnchant("T", slot, "Temporary enchant")
else
tooltip:SetText(item == 0 and "No visible item" or "Item not reported")
end
tooltip:Show()
end
local slotNames = {
{"HEADSLOT","Head"},{"NECKSLOT","Neck"},{"SHOULDERSLOT","Shoulders"},{"SHIRTSLOT","Shirt"},
{"CHESTSLOT","Chest"},{"WAISTSLOT","Waist"},{"LEGSSLOT","Legs"},{"FEETSLOT","Feet"},
{"WRISTSLOT","Wrists"},{"HANDSSLOT","Hands"},{"FINGER0SLOT","Finger 1"},{"FINGER1SLOT","Finger 2"},
{"TRINKET0SLOT","Trinket 1"},{"TRINKET1SLOT","Trinket 2"},{"BACKSLOT","Back"},
{"MAINHANDSLOT","Main hand"},{"SECONDARYHANDSLOT","Off hand"},{"RANGEDSLOT","Ranged"},{"TABARDSLOT","Tabard"}
}
local function fallbackCurrent()
local visible, player = UnitIsVisible("target"), UnitIsPlayer("target")
return active and active == inspectedGuid() and GetTime() < namesUntil
and readable(visible) and visible and readable(player) and player
end
local function showingTargetTalents()
local frame = PlayerSpellsFrame
if not frame or not frame.TalentsFrame or not frame.TalentsFrame:IsVisible() then return false end
local unit = frame:GetInspectUnit()
if not readable(unit) or type(unit) ~= "string" then return false end
local same = UnitIsUnit(unit, "target")
return readable(same) and same
end
local targetContext = {unit = "target"}
local function canShowTargetTalents()
local menuAction = UnitPopupInspectTalentsButtonMixin
if not menuAction or InCombatLockdown() or not fallbackCurrent() then return false end
local visible = menuAction:CanShow(targetContext)
if not readable(visible) or not visible then return false end
local enabled = menuAction:IsEnabled(targetContext)
return readable(enabled) and enabled
end
local function paintFallback()
if not fallbackReady or not active or (InspectFrame and InspectFrame:IsShown()) then return end
if not fallbackCurrent() or showingTargetTalents() then clear(); return end
if InCombatLockdown() then return end
if not tooltip then tooltip = CreateFrame("GameTooltip", "WoWHybridInspectGearTooltip", UIParent, "GameTooltipTemplate") end
if not fallback then
fallback = CreateFrame("Frame", nil, UIParent)
fallback:SetPoint("CENTER", UIParent, "CENTER", 0, 30)
fallback:SetFrameStrata("DIALOG")
fallback:EnableMouse(true)
local bg = fallback:CreateTexture(nil,"BACKGROUND")
bg:SetAllPoints(); bg:SetColorTexture(.065,.055,.045,.98)
fallback.title = fallback:CreateFontString(nil,"ARTWORK","GameFontNormalLarge")
fallback.title:SetPoint("TOPLEFT",16,-15)
fallback.empty = fallback:CreateFontString(nil,"ARTWORK","GameFontHighlight")
fallback.empty:SetPoint("TOPLEFT",16,-47)
local close = CreateFrame("Button",nil,fallback,"UIPanelButtonTemplate")
close:SetSize(70,22); close:SetPoint("TOPRIGHT",-10,-10); close:SetText(CLOSE or "Close")
close:SetScript("OnClick",clear)
fallback.talents = CreateFrame("Button",nil,fallback,"UIPanelButtonTemplate")
fallback.talents:SetSize(125,22)
fallback.talents:SetPoint("BOTTOMRIGHT",-10,8)
fallback.talents:SetText(INSPECT_TALENTS or "Show Talents")
fallback.talents:SetScript("OnClick",function()
if not canShowTargetTalents() then return end
UnitPopupInspectTalentsButtonMixin:OnClick(targetContext)
if showingTargetTalents() then clear() end
end)
fallback.rows = {}
local elapsed = 0
fallback:SetScript("OnUpdate",function(_,dt)
elapsed = elapsed + dt
if elapsed >= 0.25 then
elapsed = 0
if not fallbackCurrent() or showingTargetTalents() then
clear()
else
fallback.talents:SetShown(canShowTargetTalents())
end
end
end)
end
local name = UnitName("target")
fallback.title:SetText(readable(name) and type(name)=="string" and name ~= ""
and name .. " — " .. (EQUIPMENT or "Equipment") or (EQUIPMENT or "Equipment"))
local count = 0
for slot,label in ipairs(slotNames) do
local entry, row = slots[slot], fallback.rows[slot]
if entry ~= nil then
if not row then
row = CreateFrame("Frame",nil,fallback)
row:SetSize(406,21); row:EnableMouse(true)
row.slot = row:CreateFontString(nil,"ARTWORK","GameFontNormal")
row.slot:SetPoint("LEFT"); row.slot:SetWidth(114); row.slot:SetJustifyH("LEFT")
row.icon = row:CreateTexture(nil,"ARTWORK")
row.icon:SetSize(18,18); row.icon:SetPoint("LEFT",117,0)
row.item = row:CreateFontString(nil,"ARTWORK","GameFontHighlight")
row.item:SetPoint("LEFT",143,0); row.item:SetWidth(258)
row.item:SetJustifyH("LEFT"); row.item:SetWordWrap(false)
row:SetScript("OnEnter",function(self) showItem(self,slot) end)
row:SetScript("OnLeave",function() tooltip:Hide() end)
fallback.rows[slot] = row
end
row:ClearAllPoints(); row:SetPoint("TOPLEFT",16,-47-count*22)
row.slot:SetText(_G[label[1]] or label[2])
row.icon:SetTexture(iconFor(slot) or nil)
row.item:SetText(names[slot] or (entry == 0 and "No visible item" or string.format("Item %d",entry)))
row:Show()
count = count + 1
elseif row then row:Hide() end
end
fallback.empty:SetText(count == 0 and "No visible equipment data received." or "")
fallback.talents:SetShown(canShowTargetTalents())
fallback:SetSize(438,85+22*math.max(count,1))
fallback:Show()
end
local function paint()
if not active or not InspectFrame then return end
if not InspectFrame:IsVisible() then paintFallback(); return end
if fallback and fallback:IsShown() then
fallback:Hide()
if tooltip then tooltip:Hide() end
end
if active ~= inspectedGuid() or (waitingForPanelUntil and GetTime() >= waitingForPanelUntil) then clear(); return end
if InCombatLockdown() then return end
waitingForPanelUntil = nil
if not tooltip then tooltip = CreateFrame("GameTooltip", "WoWHybridInspectGearTooltip", UIParent, "GameTooltipTemplate") end
for _, name in ipairs(INSPECTPAPERDOLLFRAME_SLOTS or {}) do
local button = _G[name]
if button and button.GetID then
local slot = button:GetID()
local box = labels[slot]
if not box then
box = CreateFrame("Frame", nil, button)
box:SetAllPoints(button)
box:SetFrameLevel(button:GetFrameLevel() + 3)
box:EnableMouse(true)
local shade = box:CreateTexture(nil, "BACKGROUND")
shade:SetAllPoints()
shade:SetColorTexture(0.09, 0.09, 0.09, 1)
box.art = box:CreateTexture(nil, "ARTWORK")
box.art:SetAllPoints()
box.label = box:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
box.label:SetPoint("CENTER")
box:SetScript("OnEnter", function(self) showItem(self, slot) end)
box:SetScript("OnLeave", function() tooltip:Hide() end)
labels[slot] = box
end
local item = slots[slot]
local icon = iconFor(slot)
box.art:SetTexture(icon or nil)
box.label:SetText(icon and "" or (item == 0 and "–" or "?"))
box:Show()
end
end
if type(WoWHybridInspectEquipment.OnPainted) == "function" then pcall(WoWHybridInspectEquipment.OnPainted) end
end
local function observeInspect()
if not InspectFrame or type(InspectFrame_Show) ~= "function" then return end
if not visibilityObserver and not InCombatLockdown() then
-- An addon-owned child receives visibility changes when the original
-- pane opens or closes, irrespective of which stock event sourced it.
visibilityObserver = CreateFrame("Frame", nil, InspectFrame)
visibilityObserver:SetScript("OnShow", paint)
visibilityObserver:SetScript("OnHide", clear)
end
if hooked then return end
hooked = true
hooksecurefunc("InspectFrame_Show", function()
clear()
pending = visibilityObserver and inspectedGuid()
local requested, token = pending, action
pendingUntil = GetTime() + approvalLifetime
-- The stock action sends NotifyInspect first. If its body was unsupported,
-- the existing self-addressed addon path can issue the same Source request.
if requested then
C_Timer.After(1, function()
local now = GetTime()
if pending == requested and token == action and now < pendingUntil
and inspectedGuid() == requested and WoWHybridInspectEquipment.RequestApproval(requested) then
pendingUntil = now + approvalLifetime
end
end)
end
end)
end
local events = CreateFrame("Frame")
events:RegisterEvent("ADDON_LOADED")
events:RegisterEvent("CHAT_MSG_ADDON")
events:RegisterEvent("PLAYER_TARGET_CHANGED")
events:RegisterEvent("PLAYER_LEAVING_WORLD")
events:RegisterEvent("PLAYER_REGEN_ENABLED")
events:RegisterEvent("PLAYER_REGEN_DISABLED")
events:SetScript("OnEvent", function(_, event, key, text, channel, sender, recipient)
if event == "ADDON_LOADED" then
if key == "Blizzard_InspectUI" then observeInspect() end
if key == "WoWHybridContent" and active then paint() end
elseif event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_LEAVING_WORLD" then
clear()
elseif event == "PLAYER_REGEN_DISABLED" then
if fallback and fallback:IsShown() then clear() end
elseif event == "PLAYER_REGEN_ENABLED" then
observeInspect()
paint()
elseif readable(key) and key == prefix and readable(channel) and channel == "GUILD"
and readable(text) and type(text) == "string" and selfSender(sender)
and readable(recipient) and (recipient == nil or recipient == "" or selfSender(recipient))
and (pending or active) then
local selected = inspectedGuid()
if text:sub(1, 2) == "M " then
if active and active == selected and receiveName(text, selected) and fallback and fallback:IsShown() then
paintFallback()
end
return
end
local tRealm, tLow, tSlot, tAppearance, tReal = text:match("^X (%d+) (%d+) (%d+) (%d+) (%d+)$")
if tRealm then
local currentRealm, currentLow = selected and selected:match("^Player%-(%d+)%-(%x+)$")
if not active or active ~= selected or not currentRealm or tonumber(tRealm) ~= tonumber(currentRealm)
or tonumber(tLow) ~= tonumber(currentLow, 16) then return end
tSlot, tAppearance, tReal = tonumber(tSlot), tonumber(tAppearance), tonumber(tReal)
if tSlot == 0 then
transmogs = {}
elseif tSlot <= 19 and tAppearance <= 2147483647 and tReal <= 2147483647 then
transmogs[tSlot] = {appearance = tAppearance > 0 and tAppearance or nil, real = tReal > 0 and tReal or nil}
end
if fallback and fallback:IsShown() then paintFallback() else paint() end
return
end
local layer, payload = text:match("^([PT]) (.+)$")
if layer then
if active and active == selected then
local values = unpackSlots(payload, selected)
if values then enchants[layer] = values end
end
return
end
if not pending or pending ~= selected or GetTime() >= pendingUntil then return end
local values = unpackSlots(text, pending)
if not values then return end
pending, active, slots = nil, pending, values
namesUntil = GetTime() + 30
-- A genuine Source approval can arrive before the stock frame is
-- visible. Only the normal Inspect UI owns that opening transition.
waitingForPanelUntil = namesUntil
local token = action
if not InspectFrame:IsShown() then
C_Timer.After(0.75, function()
if token ~= action or not active or InspectFrame:IsShown() then return end
fallbackReady = true
paintFallback()
end)
C_Timer.After(30, function()
if token == action and active and not InspectFrame:IsShown() then clear() end
end)
end
paint()
end
end)
C_ChatInfo.RegisterAddonMessagePrefix(prefix)
observeInspect()
-- Reported items of the currently inspected player as item links, for the stat comparison (OctoStatComparePane.lua).
-- A transmogged slot uses the real item from the peer's Octo INSTransmogs reply.
function WoWHybridInspectEquipment.GetReportedLinks()
if not active or active ~= inspectedGuid() then return end
local links, any = {}, false
for slot = 1, 19 do
local entry = realEntry(slot)
if entry and entry > 0 then
local permanent = enchants.P and tonumber(enchants.P[slot]) or 0
links[slot], any = string.format("item:%d:%d", entry, permanent), true
end
end
return any and links or nil
end