Thread Tools Display Modes
02-07-18, 05:12 AM   #1
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
SecureHandler template object fails visibility check

So, I'm currently trying to make a button that cancels aura on right mouse button and here's what I've got atm

Lua Code:
  1. local button = CreateFrame("Button", nil, UIParent, "SecureHandlerClickTemplate");
  2. button:RegisterEvent("PLAYER_ENTERING_WORLD");
  3. button:RegisterUnitEvent("UNIT_AURA", "player");
  4. button:RegisterForClicks("RightButtonUp");
  5. button:SetSize(50, 50);
  6. button:SetPoint("TOP", 0, -150);
  7. button:SetScript("OnEvent", function(self, event, ...)
  8.     if event == "PLAYER_ENTERING_WORLD" or event == "UNIT_AURA" then
  9.         if event == "PLAYER_ENTERING_WORLD" then
  10.             self:UnregisterEvent("PLAYER_ENTERING_WORLD");
  11.         end
  12.  
  13.         local spellName = GetSpellInfo(self.spellID);
  14.  
  15.         local _, _, _, count, _, duration, expires = UnitBuff("player", spellName);
  16.  
  17.         local cd = self.cd;
  18.         if duration and duration > 0 then
  19.             cd:SetCooldown(expires - duration, duration);
  20.             cd:Show();
  21.  
  22.             self.icon:SetDesaturated(false);
  23.  
  24.             self.duration = duration;
  25.         else
  26.             cd:Hide();
  27.  
  28.             self.icon:SetDesaturated(true);
  29.  
  30.             self.duration = nil;
  31.         end
  32.  
  33.         self.count:SetText((count and count > 1) and count or "");
  34.     end
  35. end);
  36. button:SetAttribute("_onclick", [=[
  37.     if button == "RightButton" and not down then
  38.         local name = self:GetAttribute("spellName");
  39.  
  40.         local cd = self:GetFrameRef("cd");
  41.        
  42.         if cd:IsShown() then
  43.             CancelUnitBuff("player", name);
  44.         end
  45.     end
  46. ]=]);
  47.  
  48. button.spellID = 241846;
  49. button:SetAttribute("spellName", GetSpellInfo(button.spellID));
  50.  
  51. local cd = CreateFrame("Cooldown", nil, button, "CooldownFrameTemplate");
  52. cd:SetAllPoints(button);
  53. cd:SetReverse(true);
  54. cd:SetDrawEdge(true);
  55. cd:SetHideCountdownNumbers(false);
  56.  
  57. button:SetFrameRef("cd", cd);

It currently fails at L#42 where I check cd's visibility.

Would that be because cd itself is not a SecureHandler template object?

Last edited by Eungavi : 02-07-18 at 07:32 AM.
  Reply With Quote
02-07-18, 07:45 AM   #2
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
You may check the RestrictedEnvironment.lua#L18-L94, the CancelUnitBuff can't be used in the secure snippets. Also none secure frames like the cooldown can't be used in the secure snippets.

You should use SecureActionButtonTemplate instead of the SecureHandlerClickTemplate

Lua Code:
  1. local button = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate")
  2. button:SetAttribute("*type2", "cancelaura")
  3. button:SetAttribute("spell", "the spell name")

See SecureTemplates.lua#L443-L459 for details.
  Reply With Quote
02-07-18, 08:04 AM   #3
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
To clarify, you can get frame references to unprotected frames in a secure scope, but you can't see them in a secure scope when you're in combat. :GetFrameRef will not return your frame if it's not protected.

https://github.com/Gethe/wow-ui-sour...es.lua#L76-L97
__________________
  Reply With Quote
02-07-18, 03:24 PM   #4
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
Many thanks to Kurapica and MunkDev.

Using SecureActionButtonTemplate did the trick

It seems like you would need a unit attribute set as well to use cancelaura, btw

Last edited by Eungavi : 02-07-18 at 04:15 PM.
  Reply With Quote
02-07-18, 10:29 PM   #5
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
Just being curious with

Lua Code:
  1. button:SetAttribute("*type2", "cancelaura")

Can you hook the script when it actually calls cancelaura function(?) either by hooksecurefunc() or :HookScript()?
  Reply With Quote
02-08-18, 05:44 AM   #6
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Originally Posted by Engavi View Post
Just being curious with

Lua Code:
  1. button:SetAttribute("*type2", "cancelaura")

Can you hook the script when it actually calls cancelaura function(?) either by hooksecurefunc() or :HookScript()?
You can hooksecurefunc the CancelUnitBuff or use button:HookScript("OnClick", ...)
  Reply With Quote
02-08-18, 06:32 PM   #7
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
Originally Posted by kurapica.igas View Post
You can hooksecurefunc the CancelUnitBuff or use button:HookScript("OnClick", ...)
So, I just need to hook CancelUnitBuff method?

That's easier than I thought
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SecureHandler template object fails visibility check

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off