Mercurial > wow > buffalo2
diff Modules/ArtifactPower.lua @ 103:8df154a2bfd6 v7.1.5-r104
- Fixed a tainting issue caused by trying to hook ToggleAllBags
author | Nenue |
---|---|
date | Thu, 26 Jan 2017 17:36:12 -0500 |
parents | 1e511e9aaca5 |
children | a41f6b74709a |
line wrap: on
line diff
--- a/Modules/ArtifactPower.lua Wed Jan 25 23:11:27 2017 -0500 +++ b/Modules/ArtifactPower.lua Thu Jan 26 17:36:12 2017 -0500 @@ -83,20 +83,40 @@ BagFrames = {'BagnonFrameinventory'}, BankFrames = {'BagnonFramebank'}, FrameMethods = { - ['HideFrame'] = IsBagnonOpen, - ['ShowFrame'] = IsBagnonOpen + ['Hide'] = IsBagnonOpen, + ['Show'] = IsBagnonOpen }, - PostHooks = {'ToggleAllBags', 'ToggleBackpack' }, + PostHooks = {}, MethodClass = 'Bagnon', MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'}, } } + + +local queued_hooks = {} +local function CreateHook(...) + if select('#', ...) >= 2 then + tinsert(queued_hooks, {...}) + end + if not InCombatLockdown() then + local info = tremove(queued_hooks) + while info do + print('hooking', unpack(info)) + hooksecurefunc(unpack(info)) + info = tremove(queued_hooks) + end + + end +end + local function AddFrameHooks(frame, args) for funcName, func in pairs(args.FrameMethods) do print('binding', frame:GetName(), funcName, 'to', tostring(func)) - hooksecurefunc(frame, funcName, func) + CreateHook(frame, funcName, function() + VeneerArtifactPower:TryToShow() + end) end end local PENDING_HOOKS = {} @@ -112,7 +132,6 @@ end end - function ap:Setup() print(self:GetName()..':Setup()') local guid = UnitGUID('player') @@ -144,8 +163,8 @@ local DoTryToShow = function() self:TryToShow() end - hooksecurefunc("OpenBackpack", DoTryToShow) - hooksecurefunc("CloseBackpack", DoTryToShow) + CreateHook("OpenBackpack", DoTryToShow) + CreateHook("CloseBackpack", DoTryToShow) -- Bagnon compatibility -- todo: ArkInventory, Elv, etc @@ -162,16 +181,18 @@ -- should only specify non-secure functions in this table for _, name in ipairs(args.PostHooks) do local oFunc = _G[name] - _G[name] = function(...) - print('|cFFFF0088' .. name .. '|r', ...) + print('hook entry', name, tostring(oFunc)) + CreateHook(name, function(...) + print('|cFFFF0088' .. name .. '|r', ..., 'original', tostring(oFunc)) oFunc(...) self:TryToShow() - end + end) end local frame = _G[args.MethodClass] if frame then + print() for _, name in ipairs(args.MethodHooks) do - hooksecurefunc(frame, name, DoTryToShow) + CreateHook(frame, name, DoTryToShow) end end end @@ -184,48 +205,7 @@ end local UNDERLIGHT_ANGLER_ID = 133755 -function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent) - print('|cFF00FF00SetArtifact()|r') - if not self.profile then - return - end - local artifacts = self.profile.artifacts - local multi = C_ArtifactUI.GetArtifactKnowledgeMultiplier() - self.profile.knowledgeMultiplier = multi or self.profile.knowledgeMultiplier - print('multiplier:', multi) - - if itemID then - - self.currentEquipped = itemID - - artifacts[itemID] = artifacts[itemID] or {} - table.wipe(artifacts[itemID]) - local artifact = artifacts[itemID] - - artifact.name = name - artifact.texture = texture - artifact.currentXP = currentXP - artifact.level = pointsSpent - local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent) - artifact.cost = cost - - local pointsAvailable = pointsSpent - local actualCost = cost - local actualXP = currentXP - while actualXP >= actualCost do - pointsAvailable = pointsAvailable + 1 - actualXP = actualXP - actualCost - print(pointsAvailable, '-', actualCost, '=', actualXP) - actualCost = C_ArtifactUI.GetCostForPointAtRank(pointsAvailable) - end - print('updating', itemID, name, currentXP, pointsSpent, pointsAvailable, actualXP) - artifact.actualXP = actualXP - artifact.actualLevel = pointsAvailable - artifact.actualCost = actualCost - - end -end function ap:QueueBag(containerID) containerID = tonumber(containerID) if not containerID then @@ -279,7 +259,7 @@ if not InCombatLockdown() then for _, name in ipairs(FRAME_LIST) do - --print(name, (_G[name] and _G[name]:IsShown())) + print('test:', name, (_G[name] and _G[name]:IsShown())) if _G[name] and _G[name]:IsShown() then if self:IsShown() then self:Update() @@ -328,14 +308,16 @@ self:SetArtifact(itemID, name, texture, currentXP, pointsSpent) self:ScanAllBags(self.bankAccess) elseif event == 'PLAYER_REGEN_ENABLED' then - if self.enabled then - if self.queuedScan then - self:ScanAllBags(self.backAccess) - else - self:TryToShow() - end + + if self.queuedScan then + self:ScanAllBags(self.backAccess) + else + self:TryToShow() end + if #queued_hooks >= 1 then + CreateHook() + end elseif event == 'PLAYER_REGEN_DISABLED' then self:Hide() end @@ -561,6 +543,49 @@ return self.cache[itemID], self.fishingCache[itemID] end +function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent) + print('|cFF00FF00SetArtifact()|r') + if not self.profile then + return + end + local artifacts = self.profile.artifacts + + local multi = C_ArtifactUI.GetArtifactKnowledgeMultiplier() + self.profile.knowledgeMultiplier = multi or self.profile.knowledgeMultiplier + print('multiplier:', multi) + + if itemID then + + self.currentEquipped = itemID + + artifacts[itemID] = artifacts[itemID] or {} + table.wipe(artifacts[itemID]) + local artifact = artifacts[itemID] + + artifact.name = name + artifact.texture = texture + artifact.currentXP = currentXP + artifact.level = pointsSpent + local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent) + artifact.cost = cost + + local pointsAvailable = pointsSpent + local actualCost = cost + local actualXP = currentXP + while actualXP >= actualCost do + pointsAvailable = pointsAvailable + 1 + actualXP = actualXP - actualCost + print(pointsAvailable, '-', actualCost, '=', actualXP) + actualCost = C_ArtifactUI.GetCostForPointAtRank(pointsAvailable) + end + print('updating', itemID, name, currentXP, pointsSpent, pointsAvailable, actualXP) + artifact.actualXP = actualXP + artifact.actualLevel = pointsAvailable + artifact.actualCost = actualCost + + end +end + function ap:ScanBag(id) print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id)) local numSlots = GetContainerNumSlots(id) @@ -666,6 +691,7 @@ end self.lastUpdate = GetTime() + self.queuedScan = nil self:TryToShow() end