Files

162 lines
7.9 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Source has the real backpack count and four equipped bags, with neither
-- authenticator upgrade slots nor a reagent bag. Keep native frames/Edit Mode.
-- Keyring engine routing remains separate; never replace its native click path.
local reagentBag = Enum and Enum.BagIndex and Enum.BagIndex.ReagentBag
if type(reagentBag) ~= "number" then reagentBag = 5 end
local pending = false
local hooked = setmetatable({}, { __mode = "k" })
local keyringButton
local function inCombat()
return InCombatLockdown and InCombatLockdown()
end
local function bagID(frame)
if type(frame.GetBagID) == "function" then
local ok, id = pcall(frame.GetBagID, frame)
if ok and type(id) == "number" then return id end
end
if type(frame.bagID) == "number" then return frame.bagID end
if type(frame.containerID) == "number" then return frame.containerID end
end
-- Do NOT replace ContainerFrame_GetContainerNumSlots (or IsAccountSecured).
-- Replacing either global taints the native bag-update handlers at the call
-- site; the rest of Camelot's OnBagUpdate then runs as insecure code and trips
-- "insecure scripts exceeded execution limit". The four extra backpack slots
-- come from native containerframe.lua:129 (`not IsAccountSecured()` -> +4).
-- The supported fix is engine state: the gateway reports the account as
-- secured, so native FrameXML shows the real backpack count by itself.
local function hideUnsupported(frame, isSlot)
if inCombat() then pending = true; return end
if isSlot or bagID(frame) == reagentBag then frame:Hide() end
if frame.AddSlotsButton then frame.AddSlotsButton:Hide() end
end
local function observe(frame, isSlot)
if not frame then return end
local hooks = hooked[frame]
if not hooks then hooks = {}; hooked[frame] = hooks end
if not hooks.show and type(frame.HookScript) == "function" then
frame:HookScript("OnShow", function(self) hideUnsupported(self, isSlot) end)
hooks.show = true
end
-- No method hook on the bag frame (opening a merchant raised "attempt to call a nil value" at the
-- UpdateAddSlots call): our own child frame hides the button if the game shows it again.
-- Patch by eineath (Gitea #1, 2026-11-29).
if not hooks.addSlots and type(frame.UpdateAddSlots) == "function" then
CreateFrame("Frame", nil, frame):SetScript("OnUpdate", function()
local button = frame.AddSlotsButton
if button and button:IsShown() then hideUnsupported(frame, isSlot) end
end)
hooks.addSlots = true
end
hideUnsupported(frame, isSlot)
end
-- The bag bar itself (no reagent slot, no empty gap left of the keyring) is fixed in Blizzard's own
-- mainmenubarbagbuttons.lua (content 358abf40, #107): the slot never joins MainMenuBarBagManager.
local function enableKeyringOnClick(button, mouseButton)
if mouseButton ~= "LeftButton" and mouseButton ~= "RightButton" then return end
if inCombat() or CursorHasItem() or GetCVarBool("showKeyring") then return end
if not C_ActionBar.ShouldShowKeyring() or not ContainerFrame_AllowedToOpenBags
or not ContainerFrame_AllowedToOpenBags() then return end
-- The native tutorial enables this setting on acquiring a key. An explicit
-- click on the available empty keyring should also open its native bag.
SetCVar("showKeyring", 1)
if InputUtil.IsGamepadUIEnabled() then STARTING_BAG_INDEX = KEYRING_CONTAINER end
button:OnBagUpdate()
end
local function observeKeyringButton()
local button = _G.KeyRingButton
if button and button ~= keyringButton and type(button.OnBagUpdate) == "function" then
button:HookScript("PreClick", enableKeyringOnClick)
keyringButton = button
end
end
local function observeNewContainerFrames()
local count = tonumber(NUM_CONTAINER_FRAMES) or 13
count = math.min(64, math.max(1, count))
for i = 1, count do
local frame = _G["ContainerFrame" .. i]
if frame and not hooked[frame] then observe(frame, false) end
end
end
local function apply()
if inCombat() then pending = true; return end
pending = false
observeKeyringButton()
observe(_G.ContainerFrameCombinedBags, false)
local count = tonumber(NUM_CONTAINER_FRAMES) or 13
count = math.min(64, math.max(1, count))
for i = 1, count do observe(_G["ContainerFrame" .. i], false) end
end
-- Bounded passive metadata only. No item, account, character, mail or chat data.
-- Saved at the normal UI reload/logout; this does not initiate any game action.
local function probe()
local result = { version = 1, reagentBag = reagentBag, frames = {}, slots = {} }
if type(KEYRING_CONTAINER) == "number" then result.keyringContainer = KEYRING_CONTAINER end
local getSlots = C_Container and C_Container.GetContainerNumSlots or GetContainerNumSlots
if type(getSlots) == "function" then
for id = -2, 5 do
local ok, value = pcall(getSlots, id)
if ok and type(value) == "number" then result.slots[id] = value end
end
end
for i = 1, 64 do
local frame = _G["ContainerFrame" .. i]
if frame then
local row = { frameIndex = i, bagID = bagID(frame) }
if type(frame.GetID) == "function" then
local ok, value = pcall(frame.GetID, frame)
if ok and type(value) == "number" then row.frameID = value end
end
result.frames[#result.frames + 1] = row
end
end
WoWHybridBagDiagnostics = result
end
local events = CreateFrame("Frame")
for _, name in ipairs({"PLAYER_LOGIN", "PLAYER_ENTERING_WORLD", "BANKFRAME_OPENED", "BAG_UPDATE", "PLAYER_REGEN_ENABLED", "ADDON_LOADED"}) do
events:RegisterEvent(name)
end
events:SetScript("OnEvent", function(_, event, addon)
if event == "PLAYER_REGEN_ENABLED" then
if pending then apply() end
return
end
-- BAG_UPDATE also reaches the native keyring and paper doll hot paths.
-- Only hook newly created frames, then refresh size if visibility changed.
if event == "BAG_UPDATE" then
if inCombat() then pending = true; return end
observeKeyringButton()
observeNewContainerFrames()
return
end
if event == "ADDON_LOADED"
and addon ~= "Blizzard_MainMenuBarBagButtons"
and addon ~= "Blizzard_UIPanels_Game" then return end
apply()
if event == "PLAYER_LOGIN" or event == "PLAYER_ENTERING_WORLD" or event == "BANKFRAME_OPENED" then probe() end
end)
-- #72 (owner 2026-11-26, 2560x1440: "(8)0" on the backpack, "more text underneath is confusing"): the backpack
-- button drew the free-slot count (FreeSlots) plus a second count string over it. The backpack has no stack
-- count, so every other text on the button is silenced and the free-slot text stays on one line.
-- Owner 2026-11-26 (Praxis, "(9)0" on the button right of the combined-bag search box): the combined bag window
-- carries its own backpack button (GamepadBackpackButton in GamepadBagBar) with the same FreeSlots + count pair.
-- Every backpack button gets the same rule, for every character.
local function SingleCount(b)
if not b then return; end
local keep = b.FreeSlots;
for _, r in ipairs({ b:GetRegions() }) do
if r ~= keep and r.GetObjectType and r:GetObjectType() == "FontString" and r:GetAlpha() > 0 then r:SetAlpha(0); end
end
if keep and keep.SetWordWrap then keep:SetWordWrap(false); keep:SetNonSpaceWrap(false); end
end
local function BackpackSingleCount()
SingleCount(MainMenuBarBackpackButton);
SingleCount(_G.GamepadBackpackButton);
end
local bp = CreateFrame("Frame");
bp:RegisterEvent("PLAYER_ENTERING_WORLD");
bp:RegisterEvent("BAG_UPDATE_DELAYED");
bp:SetScript("OnEvent", BackpackSingleCount);
if ContainerFrameCombinedBags then ContainerFrameCombinedBags:HookScript("OnShow", BackpackSingleCount); end