From d27db55abfa070464b93778b971321b0ebccf39f Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Thu, 21 May 2026 17:03:55 -0500 Subject: [PATCH] modernize monkey-patched hooks to hooksecurefunc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sellvalue.lua: SetItemRef hook follows the same pattern questitem.lua got earlier — replaces the local-Hook + _G.SetItemRef monkey-patch with hooksecurefunc, drops the string.find link-parser, and reads itemID directly from ItemRefTooltip:GetItem after the original populates the tooltip. The OnShow path also moves from libtooltip:GetItemLink/GetItemID to GameTooltip:HasItem/GetItem (libtooltip:GetItemCount stays — it's populated by libtooltip's own SetBagItem hook and carries the stack count, which GetItem doesn't return). unusable.lua: the two post-hooks (pfUI.bag.UpdateSlot and BankFrameItemButton_UpdateLock) are textbook hooksecurefunc cases — both ran the original then did extra work, no conditional skip or return-value tampering. The table form of hooksecurefunc handles pfUI.bag.UpdateSlot cleanly. --- modules/sellvalue.lua | 25 +++++++++++++------------ modules/unusable.lua | 12 ++++-------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/modules/sellvalue.lua b/modules/sellvalue.lua index f854d089..06bb1567 100644 --- a/modules/sellvalue.lua +++ b/modules/sellvalue.lua @@ -28,21 +28,22 @@ pfUI:RegisterModule("sellvalue", "vanilla:tbc", function () end end - pfUI.sellvalue = CreateFrame( "Frame" , "pfGameTooltip", GameTooltip ) + pfUI.sellvalue = CreateFrame("Frame", "pfGameTooltip", GameTooltip) pfUI.sellvalue:SetScript("OnShow", function() - if libtooltip:GetItemLink() then - local id = libtooltip:GetItemID() - local count = tonumber(libtooltip:GetItemCount()) or 1 - AddVendorPrices(GameTooltip, id, math.max(count, 1)) + if GameTooltip:HasItem() then + local _, _, id = GameTooltip:GetItem() + if id then + local count = tonumber(libtooltip:GetItemCount()) or 1 + AddVendorPrices(GameTooltip, id, math.max(count, 1)) + end end end) - local HookSetItemRef = SetItemRef - _G.SetItemRef = function(link, text, button) - local item, _, id = string.find(link, "item:(%d+):.*") - HookSetItemRef(link, text, button) - if not IsAltKeyDown() and not IsShiftKeyDown() and not IsControlKeyDown() and item then - AddVendorPrices(ItemRefTooltip, tonumber(id), 1) + hooksecurefunc("SetItemRef", function() + if IsAltKeyDown() or IsShiftKeyDown() or IsControlKeyDown() then return end + if ItemRefTooltip:HasItem() then + local _, _, id = ItemRefTooltip:GetItem() + if id then AddVendorPrices(ItemRefTooltip, id, 1) end end - end + end) end) diff --git a/modules/unusable.lua b/modules/unusable.lua index 73a9d992..b0eb8c80 100644 --- a/modules/unusable.lua +++ b/modules/unusable.lua @@ -41,16 +41,12 @@ pfUI:RegisterModule("unusable", "vanilla:tbc", function () end -- update on regular pfUI button updates - local HookUpdateSlot = pfUI.bag.UpdateSlot - pfUI.bag.UpdateSlot = function(self, bag, slot) - HookUpdateSlot(self, bag, slot) + hooksecurefunc(pfUI.bag, "UpdateSlot", function(self, bag, slot) pfUI.unusable:UpdateSlot(bag, slot) - end + end) -- update on bank frame itemlock updates - local HookBankFrameItemButton_UpdateLock = BankFrameItemButton_UpdateLock - _G.BankFrameItemButton_UpdateLock = function() - HookBankFrameItemButton_UpdateLock() + hooksecurefunc("BankFrameItemButton_UpdateLock", function() pfUI.unusable:UpdateSlot(-1, this:GetID()) - end + end) end)