Mercurial > wow > buffalo2
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 102:1e511e9aaca5 | 103:8df154a2bfd6 |
|---|---|
| 81 local addonCompatibility = { | 81 local addonCompatibility = { |
| 82 ['Bagnon'] = { | 82 ['Bagnon'] = { |
| 83 BagFrames = {'BagnonFrameinventory'}, | 83 BagFrames = {'BagnonFrameinventory'}, |
| 84 BankFrames = {'BagnonFramebank'}, | 84 BankFrames = {'BagnonFramebank'}, |
| 85 FrameMethods = { | 85 FrameMethods = { |
| 86 ['HideFrame'] = IsBagnonOpen, | 86 ['Hide'] = IsBagnonOpen, |
| 87 ['ShowFrame'] = IsBagnonOpen | 87 ['Show'] = IsBagnonOpen |
| 88 }, | 88 }, |
| 89 PostHooks = {'ToggleAllBags', 'ToggleBackpack' }, | 89 PostHooks = {}, |
| 90 MethodClass = 'Bagnon', | 90 MethodClass = 'Bagnon', |
| 91 MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'}, | 91 MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'}, |
| 92 | 92 |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | |
| 96 | |
| 97 | |
| 98 local queued_hooks = {} | |
| 99 local function CreateHook(...) | |
| 100 if select('#', ...) >= 2 then | |
| 101 tinsert(queued_hooks, {...}) | |
| 102 end | |
| 103 if not InCombatLockdown() then | |
| 104 local info = tremove(queued_hooks) | |
| 105 while info do | |
| 106 print('hooking', unpack(info)) | |
| 107 hooksecurefunc(unpack(info)) | |
| 108 info = tremove(queued_hooks) | |
| 109 end | |
| 110 | |
| 111 end | |
| 112 end | |
| 95 | 113 |
| 96 local function AddFrameHooks(frame, args) | 114 local function AddFrameHooks(frame, args) |
| 97 for funcName, func in pairs(args.FrameMethods) do | 115 for funcName, func in pairs(args.FrameMethods) do |
| 98 print('binding', frame:GetName(), funcName, 'to', tostring(func)) | 116 print('binding', frame:GetName(), funcName, 'to', tostring(func)) |
| 99 hooksecurefunc(frame, funcName, func) | 117 CreateHook(frame, funcName, function() |
| 118 VeneerArtifactPower:TryToShow() | |
| 119 end) | |
| 100 end | 120 end |
| 101 end | 121 end |
| 102 local PENDING_HOOKS = {} | 122 local PENDING_HOOKS = {} |
| 103 | 123 |
| 104 local function RegisterInventoryFrame(name, listType, args) | 124 local function RegisterInventoryFrame(name, listType, args) |
| 110 else | 130 else |
| 111 PENDING_HOOKS[name] = args | 131 PENDING_HOOKS[name] = args |
| 112 end | 132 end |
| 113 end | 133 end |
| 114 | 134 |
| 115 | |
| 116 function ap:Setup() | 135 function ap:Setup() |
| 117 print(self:GetName()..':Setup()') | 136 print(self:GetName()..':Setup()') |
| 118 local guid = UnitGUID('player') | 137 local guid = UnitGUID('player') |
| 119 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings | 138 VeneerData.ArtifactPower = VeneerData.ArtifactPower or defaultSettings |
| 120 self.db = VeneerData.ArtifactPower | 139 self.db = VeneerData.ArtifactPower |
| 142 end) | 161 end) |
| 143 | 162 |
| 144 local DoTryToShow = function() | 163 local DoTryToShow = function() |
| 145 self:TryToShow() | 164 self:TryToShow() |
| 146 end | 165 end |
| 147 hooksecurefunc("OpenBackpack", DoTryToShow) | 166 CreateHook("OpenBackpack", DoTryToShow) |
| 148 hooksecurefunc("CloseBackpack", DoTryToShow) | 167 CreateHook("CloseBackpack", DoTryToShow) |
| 149 | 168 |
| 150 -- Bagnon compatibility | 169 -- Bagnon compatibility |
| 151 -- todo: ArkInventory, Elv, etc | 170 -- todo: ArkInventory, Elv, etc |
| 152 for addon, args in pairs(addonCompatibility) do | 171 for addon, args in pairs(addonCompatibility) do |
| 153 if IsAddOnLoaded(addon) then | 172 if IsAddOnLoaded(addon) then |
| 160 end | 179 end |
| 161 | 180 |
| 162 -- should only specify non-secure functions in this table | 181 -- should only specify non-secure functions in this table |
| 163 for _, name in ipairs(args.PostHooks) do | 182 for _, name in ipairs(args.PostHooks) do |
| 164 local oFunc = _G[name] | 183 local oFunc = _G[name] |
| 165 _G[name] = function(...) | 184 print('hook entry', name, tostring(oFunc)) |
| 166 print('|cFFFF0088' .. name .. '|r', ...) | 185 CreateHook(name, function(...) |
| 186 print('|cFFFF0088' .. name .. '|r', ..., 'original', tostring(oFunc)) | |
| 167 oFunc(...) | 187 oFunc(...) |
| 168 self:TryToShow() | 188 self:TryToShow() |
| 169 end | 189 end) |
| 170 end | 190 end |
| 171 local frame = _G[args.MethodClass] | 191 local frame = _G[args.MethodClass] |
| 172 if frame then | 192 if frame then |
| 193 print() | |
| 173 for _, name in ipairs(args.MethodHooks) do | 194 for _, name in ipairs(args.MethodHooks) do |
| 174 hooksecurefunc(frame, name, DoTryToShow) | 195 CreateHook(frame, name, DoTryToShow) |
| 175 end | 196 end |
| 176 end | 197 end |
| 177 end | 198 end |
| 178 end | 199 end |
| 179 | 200 |
| 182 | 203 |
| 183 end | 204 end |
| 184 end | 205 end |
| 185 | 206 |
| 186 local UNDERLIGHT_ANGLER_ID = 133755 | 207 local UNDERLIGHT_ANGLER_ID = 133755 |
| 187 function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent) | 208 |
| 188 print('|cFF00FF00SetArtifact()|r') | |
| 189 if not self.profile then | |
| 190 return | |
| 191 end | |
| 192 local artifacts = self.profile.artifacts | |
| 193 | |
| 194 local multi = C_ArtifactUI.GetArtifactKnowledgeMultiplier() | |
| 195 self.profile.knowledgeMultiplier = multi or self.profile.knowledgeMultiplier | |
| 196 print('multiplier:', multi) | |
| 197 | |
| 198 if itemID then | |
| 199 | |
| 200 self.currentEquipped = itemID | |
| 201 | |
| 202 artifacts[itemID] = artifacts[itemID] or {} | |
| 203 table.wipe(artifacts[itemID]) | |
| 204 local artifact = artifacts[itemID] | |
| 205 | |
| 206 artifact.name = name | |
| 207 artifact.texture = texture | |
| 208 artifact.currentXP = currentXP | |
| 209 artifact.level = pointsSpent | |
| 210 local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent) | |
| 211 artifact.cost = cost | |
| 212 | |
| 213 local pointsAvailable = pointsSpent | |
| 214 local actualCost = cost | |
| 215 local actualXP = currentXP | |
| 216 while actualXP >= actualCost do | |
| 217 pointsAvailable = pointsAvailable + 1 | |
| 218 actualXP = actualXP - actualCost | |
| 219 print(pointsAvailable, '-', actualCost, '=', actualXP) | |
| 220 actualCost = C_ArtifactUI.GetCostForPointAtRank(pointsAvailable) | |
| 221 end | |
| 222 print('updating', itemID, name, currentXP, pointsSpent, pointsAvailable, actualXP) | |
| 223 artifact.actualXP = actualXP | |
| 224 artifact.actualLevel = pointsAvailable | |
| 225 artifact.actualCost = actualCost | |
| 226 | |
| 227 end | |
| 228 end | |
| 229 function ap:QueueBag(containerID) | 209 function ap:QueueBag(containerID) |
| 230 containerID = tonumber(containerID) | 210 containerID = tonumber(containerID) |
| 231 if not containerID then | 211 if not containerID then |
| 232 return | 212 return |
| 233 end | 213 end |
| 277 | 257 |
| 278 print('|cFFFFFF00TryToShow()') | 258 print('|cFFFFFF00TryToShow()') |
| 279 | 259 |
| 280 if not InCombatLockdown() then | 260 if not InCombatLockdown() then |
| 281 for _, name in ipairs(FRAME_LIST) do | 261 for _, name in ipairs(FRAME_LIST) do |
| 282 --print(name, (_G[name] and _G[name]:IsShown())) | 262 print('test:', name, (_G[name] and _G[name]:IsShown())) |
| 283 if _G[name] and _G[name]:IsShown() then | 263 if _G[name] and _G[name]:IsShown() then |
| 284 if self:IsShown() then | 264 if self:IsShown() then |
| 285 self:Update() | 265 self:Update() |
| 286 else | 266 else |
| 287 self:Show() | 267 self:Show() |
| 326 elseif event == 'ARTIFACT_XP_UPDATE' then | 306 elseif event == 'ARTIFACT_XP_UPDATE' then |
| 327 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetEquippedArtifactInfo() | 307 local itemID, _, name, texture, currentXP, pointsSpent = C_ArtifactUI:GetEquippedArtifactInfo() |
| 328 self:SetArtifact(itemID, name, texture, currentXP, pointsSpent) | 308 self:SetArtifact(itemID, name, texture, currentXP, pointsSpent) |
| 329 self:ScanAllBags(self.bankAccess) | 309 self:ScanAllBags(self.bankAccess) |
| 330 elseif event == 'PLAYER_REGEN_ENABLED' then | 310 elseif event == 'PLAYER_REGEN_ENABLED' then |
| 331 if self.enabled then | 311 |
| 332 if self.queuedScan then | 312 if self.queuedScan then |
| 333 self:ScanAllBags(self.backAccess) | 313 self:ScanAllBags(self.backAccess) |
| 334 else | 314 else |
| 335 self:TryToShow() | 315 self:TryToShow() |
| 336 end | 316 end |
| 337 end | 317 |
| 338 | 318 if #queued_hooks >= 1 then |
| 319 CreateHook() | |
| 320 end | |
| 339 elseif event == 'PLAYER_REGEN_DISABLED' then | 321 elseif event == 'PLAYER_REGEN_DISABLED' then |
| 340 self:Hide() | 322 self:Hide() |
| 341 end | 323 end |
| 342 end | 324 end |
| 343 | 325 |
| 559 end | 541 end |
| 560 end | 542 end |
| 561 return self.cache[itemID], self.fishingCache[itemID] | 543 return self.cache[itemID], self.fishingCache[itemID] |
| 562 end | 544 end |
| 563 | 545 |
| 546 function ap:SetArtifact(itemID, name, texture, currentXP, pointsSpent) | |
| 547 print('|cFF00FF00SetArtifact()|r') | |
| 548 if not self.profile then | |
| 549 return | |
| 550 end | |
| 551 local artifacts = self.profile.artifacts | |
| 552 | |
| 553 local multi = C_ArtifactUI.GetArtifactKnowledgeMultiplier() | |
| 554 self.profile.knowledgeMultiplier = multi or self.profile.knowledgeMultiplier | |
| 555 print('multiplier:', multi) | |
| 556 | |
| 557 if itemID then | |
| 558 | |
| 559 self.currentEquipped = itemID | |
| 560 | |
| 561 artifacts[itemID] = artifacts[itemID] or {} | |
| 562 table.wipe(artifacts[itemID]) | |
| 563 local artifact = artifacts[itemID] | |
| 564 | |
| 565 artifact.name = name | |
| 566 artifact.texture = texture | |
| 567 artifact.currentXP = currentXP | |
| 568 artifact.level = pointsSpent | |
| 569 local cost = C_ArtifactUI.GetCostForPointAtRank(pointsSpent) | |
| 570 artifact.cost = cost | |
| 571 | |
| 572 local pointsAvailable = pointsSpent | |
| 573 local actualCost = cost | |
| 574 local actualXP = currentXP | |
| 575 while actualXP >= actualCost do | |
| 576 pointsAvailable = pointsAvailable + 1 | |
| 577 actualXP = actualXP - actualCost | |
| 578 print(pointsAvailable, '-', actualCost, '=', actualXP) | |
| 579 actualCost = C_ArtifactUI.GetCostForPointAtRank(pointsAvailable) | |
| 580 end | |
| 581 print('updating', itemID, name, currentXP, pointsSpent, pointsAvailable, actualXP) | |
| 582 artifact.actualXP = actualXP | |
| 583 artifact.actualLevel = pointsAvailable | |
| 584 artifact.actualCost = actualCost | |
| 585 | |
| 586 end | |
| 587 end | |
| 588 | |
| 564 function ap:ScanBag(id) | 589 function ap:ScanBag(id) |
| 565 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id)) | 590 print('|cFF00FFFFScanBag()|r', id, IsBagOpen(id), GetContainerNumSlots(id)) |
| 566 local numSlots = GetContainerNumSlots(id) | 591 local numSlots = GetContainerNumSlots(id) |
| 567 local requiresUpdate | 592 local requiresUpdate |
| 568 if numSlots == 0 then | 593 if numSlots == 0 then |
| 664 self.fishingAP = self.fishingAP + bagData.fishingAP | 689 self.fishingAP = self.fishingAP + bagData.fishingAP |
| 665 end | 690 end |
| 666 | 691 |
| 667 end | 692 end |
| 668 self.lastUpdate = GetTime() | 693 self.lastUpdate = GetTime() |
| 694 self.queuedScan = nil | |
| 669 self:TryToShow() | 695 self:TryToShow() |
| 670 end | 696 end |
| 671 | 697 |
| 672 VeneerArtifactButtonMixin = {} | 698 VeneerArtifactButtonMixin = {} |
| 673 | 699 |
