WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Changing actionbars attribute in secure env (https://www.wowinterface.com/forums/showthread.php?t=57065)

gmarco 03-17-19 03:55 AM

Changing actionbars attribute in secure env
 
Hi all,

I had and still have a problem that I post some day ago about trying to scale a ActionBar:
https://www.wowinterface.com/forums/...ad.php?t=57047


The problem is still there even if Fizzlemizz and Terenna suggest some changes at the code.

I have tried to use someting like:
Lua Code:
  1. MultiBarRight:HookScript('OnSizeChanged', function()
  2.     if not UnitAffectingCombat("player") then
  3.         if MultiBarRight:GetScale() > 0.81 then
  4.             MultiBarRight:SetScale(0.8)
  5.         end
  6.     end
  7. end)

and I have seen that this bar changes a lot of time during gameplay from scale 0.8 to 1 (probably when the function is called in combat or on some state that make UnitAffectingCombat("player") true.

For example I had always an error when exit from "BeachHead" quest of Tortollan Seekers but using the :
Lua Code:
  1. if not UnitAffectingCombat("player") then
  2. ...
  3. end

there isn't error anymore, even if I have the ActionBar scale = 1 instead of 0.8 it was started the quest with.

Now I am here to ask if it is possible to have some clues on how generate a secure enviroment to make changes to UI element during combat or other state that can generate a taint.

Thanks so much.

Terenna 03-17-19 09:35 AM

You'll have to make a secure frame:

Lua Code:
  1. local secureFrame = CreateFrame('frame', nil, UIParent, 'SecureActionButtonTemplate')

then you'll need to hook your script as above. I think you'll need to set a reference frame for the MultiBarRight inside of the secure frame. So something like:

Lua Code:
  1. secureFrame:SetFrameRef('MultiBarRight', MultiBarRight)

Then you'll need to securely insert the reference frame into a secure table.

Lua Code:
  1. secureFrame:Execute([[
  2.      multiBarRightSecureTable = table.new()
  3.      mutliBarRightSecureTable[1] = secureFrame:GetFrameRef('MultiBarRight')
  4. ]])

Then you'll execute secure code in your MultiBarRight Hookscript:

Lua Code:
  1. MultiBarRight:HookScript('OnSizeChanged', function()
  2.      secureFrame:Execute([[
  3.           if multiBarRightSecureTable[1]:GetScale() > 0.81 then
  4.                multiBarRightSecureTable[1]:SetScale(0.8)
  5.           end
  6.      ]])
  7. end)

I think that will work. IDK, I just learned about secure coding yesterday and I'm probably not great at it. You might be able to skip the multiBarRightSecureTable thing altogether and just use self:GetFrameRef('MultiBarRight'):GetScale() and self:GetFrameRef('MultiBarRight'):SetScale(). I'm not sure, like I said I'm fairly new to this, too.

gmarco 03-17-19 01:25 PM

Hi Terenna,

thanks for your help again ...

I have tried your code but I got an error ... do you have some clues :) ?

The code:

Lua Code:
  1. local secureFrame = CreateFrame('frame', nil, UIParent, 'SecureActionButtonTemplate')
  2. secureFrame:SetFrameRef('MultiBarRight', MultiBarRight)
  3. secureFrame:Execute([[
  4.      multiBarRightSecureTable = table.new()
  5.      multiBarRightSecureTable[1] = secureFrame:GetFrameRef('MultiBarRight')
  6. ]])
  7.  
  8. MultiBarRight:HookScript('OnSizeChanged', function()
  9.      secureFrame:Execute([[
  10.           if multiBarRightSecureTable[1]:GetScale() > 0.81 then
  11.                multiBarRightSecureTable[1]:SetScale(0.8)
  12.           end
  13.      ]])
  14. end)

The error:

Lua Code:
  1. 1x gmActionBars\core.lua:5: attempt to call method 'SetFrameRef' (a nil value)
  2. gmActionBars\core.lua:5: in main chunk
  3.  
  4. Locals:
  5. ADDON = "gmActionBars"
  6. secureFrame = <unnamed> {
  7.  0 = <userdata>
  8. }
  9. (*temporary) = nil
  10. (*temporary) = <unnamed> {
  11.  0 = <userdata>
  12. }
  13. (*temporary) = "MultiBarRight"
  14. (*temporary) = MultiBarRight {
  15.  0 = <userdata>
  16.  slideOut = <unnamed> {
  17.  }
  18. }
  19. (*temporary) = "attempt to call method 'SetFrameRef' (a nil value)"

Thanks everyone for attention.

Terenna 03-17-19 02:45 PM

try replacing your CreateFrame with this: CreateFrame('frame', nil, UIParent, 'SecureHandlerAttributeTemplate')

perhaps it needs a handler rather than an actionbutton

gmarco 03-25-19 12:26 AM

Hi Terenna,

thanks so much for your reply but I couldn't test it before.

It doesn't work either.


The code:
Lua Code:
  1. local secureFrame = CreateFrame('frame', nil, UIParent, 'SecureHandlerAttributeTemplate')
  2. secureFrame:SetFrameRef('MultiBarRight', MultiBarRight)
  3. secureFrame:Execute([[
  4.          multiBarRightSecureTable = table.new()
  5.          multiBarRightSecureTable[1] = secureFrame:GetFrameRef('MultiBarRight')
  6. ]])
  7.      
  8. MultiBarRight:HookScript('OnSizeChanged', function()
  9.          secureFrame:Execute([[
  10.             multiBarRightSecureTable[1]:SetScale(0.8)
  11.          ]])
  12. end)


The error:
Lua Code:
  1. 1x FrameXML\RestrictedExecution.lua:431: Call failed: [string "         multiBarRightSecureTable[1]:SetScale(0.8..."]:1: attempt to index field '?' (a nil value)
  2. [C]: ?
  3. FrameXML\RestrictedExecution.lua:431: in function <FrameXML\RestrictedExecution.lua:420>
  4. (tail call): ?
  5. (tail call): ?
  6. FrameXML\SecureHandlers.lua:499: in function <FrameXML\SecureHandlers.lua:473>
  7. [C]: in function `SetAttribute'
  8. FrameXML\SecureHandlers.lua:743: in function <FrameXML\SecureHandlers.lua:725>
  9. (tail call): ?
  10. gmChat\core.lua:33: in function <gmChat\core.lua:32>
  11. [C]: in function `LoadAddOn'
  12. FrameXML\UIParent.lua:446: in function `UIParentLoadAddOn'
  13. FrameXML\UIParent.lua:561: in function `AchievementFrame_LoadUI'
  14. gmActionBars\core.lua:156: in function <gmActionBars\core.lua:107>
  15. gmActionBars\core.lua:170: in function <gmActionBars\core.lua:165>
  16.  
  17. Locals:
  18. (*temporary) = "Call failed: [string "          multiBarRightSecureTable[1]:SetScale(0.8..."]:1: attempt to index field '?' (a nil value)"

Any ideas ?

Thank so much

kurapica.igas 03-25-19 01:44 AM

You can't use the secureFrame in the snippet, since the snippets are processed in a secure environment, you an use self instead the secureFrame since it's the one called the Execute.

And to run the snippet codes during a script event, you also can't Hook or set the script, you can only do it like

Lua Code:
  1. secureFrame = secureFrame or CreateFrame('frame', nil, UIParent, 'SecureHandlerAttributeTemplate')
  2.  
  3. SecureHandlerWrapScript(MultiBarRight, "OnShow", secureFrame, [[  -- do the job  ]])

Unfortunately, the OnSizeChanged isn't a script type supported by the wrap script, so you can't do the job through the secure snippets.

The MultiBarRight's scale will be reset in MultiActionBar_Update, it's called under several conditions. I can't say it's a good choice to disable it, so you may keep scale it out of combat, or just change the uiparent's scale, or just replace it with an action bar mod.

Taudier 03-25-19 02:11 AM

create a frame with a SecureFrameTemplate, change the scale of this frame, and MultiBarRight:SetParent(this frame), maybe ?

siweia 03-25-19 01:19 PM

Lua Code:
  1. hooksecurefunc(MultiBarRight, "SetScale", function(self, scale)
  2.     if scale < 1 then self:SetScale(1) end
  3. end)

I have been using this since 8.0, never meet a taint issue.

gmarco 03-25-19 07:27 PM

Hi,

thanks so much for your answer.

I have tried your code and it doesn't give any errors when the player enters world ...and the bars are at 0.8 ...
Lua Code:
  1. 5:  hooksecurefunc(MultiBarRight, "SetScale", function(self, scale)
  2. 6:     if scale ~= 0.8 then self:SetScale(0.8) end
  3. 7:  end)
  4.  
  5. 9:  hooksecurefunc(MultiBarLeft, "SetScale", function(self, scale)
  6. 10: if scale ~= 0.8 then self:SetScale(0.8) end
  7. 11:end)

But when I finish the quest BeachHead (which is vehicle exit) I got:

Lua Code:
  1. 1x [ADDON_ACTION_BLOCKED] AddOn 'gmActionBars' tried to call the protected function 'UNKNOWN()'.
  2. !BugGrabber\BugGrabber.lua:519: in function <!BugGrabber\BugGrabber.lua:519>
  3. [C]: ?
  4. [C]: in function `SetScale'
  5. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  6. [C]: in function `SetScale'
  7. FrameXML\MultiActionBars.lua:85: in function `MultiActionBar_Update'
  8. FrameXML\ActionBarController.lua:169: in function `ValidateActionBarTransition'
  9. FrameXML\ActionBarController.lua:137: in function `ActionBarController_UpdateAll'
  10. FrameXML\ActionBarController.lua:62: in function <FrameXML\ActionBarController.lua:51>
  11.  
  12. Locals:
  13. InCombatSkipped

And the MultiBarRight is to 1.0 scale again (I don't use the MultiBarLeft)

The FrameXML\MultiActionBars.lua:85

Lua Code:
  1. local scale = 1;
  2. if ( contentHeight > availableSpace ) then
  3.     scale = availableSpace / contentHeight;
  4. end
  5.         MultiBarRight:SetScale(scale);    --> line 85
  6. if ( showLeft ) then
  7.         MultiBarLeft:SetScale(scale);
  8. end

I really don't understand why is not possible in an easy way to set scale to a value different from 1 :)

P.s.
The other thing I don't understand is why if I call this code instead:

Lua Code:
  1. hooksecurefunc(MultiBarRight, "SetScale", function(self, scale)
  2.      self:SetScale(0.8)
  3. end)

which basically do the same thing of the code above it fired a lot of errors like:

Lua Code:
  1. 7x C stack overflow
  2. [C]: in function `SetScale'
  3. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  4. [C]: in function `SetScale'
  5. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  6. [C]: in function `SetScale'
  7. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  8. [C]: in function `SetScale'
  9. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  10. [C]: in function `SetScale'
  11. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  12. [C]: in function `SetScale'
  13. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  14. ...
  15. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  16. [C]: in function `SetScale'
  17. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  18. [C]: in function `SetScale'
  19. gmActionBars\core.lua:6: in function <gmActionBars\core.lua:5>
  20. [C]: in function `SetScale'
  21. FrameXML\MultiActionBars.lua:85: in function `MultiActionBar_Update'
  22. FrameXML\InterfaceOptionsPanels.lua:1184: in function `InterfaceOptions_UpdateMultiActionBars'
  23. [string "*:OnLoad"]:4: in function `setFunc'
  24. FrameXML\InterfaceOptionsPanels.lua:1154: in function <FrameXML\InterfaceOptionsPanels.lua:1147>
  25.  
  26. Locals:
  27. (*temporary) = MultiBarRight {
  28.  0 = <userdata>
  29.  SetScale = <function> defined =[C]:-1
  30.  slideOut = <unnamed> {
  31.  }
  32. }
  33. (*temporary) = 0.800000
  34. (*temporary) = <function> defined =[C]:-1
  35. (*temporary) = MultiBarRight {
  36.  0 = <userdata>
  37.  SetScale = <function> defined =[C]:-1
  38.  slideOut = <unnamed> {
  39.  }
  40. }
  41. (*temporary) = 0.800000
  42.  = <function> defined =[C]:-1
  43.  = <function> defined @gmActionBars\core.lua:5

Terenna 03-26-19 03:40 AM

I'm not sure what's going on, but the reason you're last code causes a stack overflow is because you essentially enter an infinite loop.

You hook into the setscale function, and then SetScale within it. So it just constantly hooks into itself and runs and runs and runs. Thus, you need to have an if self:GetScale() > 0.8 then self:SetScale(0.8) end so it doesn't infinitely run; it only runs until the scale is 0.8.

Taudier 03-29-19 05:28 AM

Quote:

Originally Posted by gmarco (Post 331792)
I really don't understand why is not possible in an easy way to set scale to a value different from 1 :)

because SetScale is protected

i see 3 solutions :

1 : you inherit the scale from a secure parent

2 : you can maybe wrap an handler of the blizz code (see SecureHeadersGuide-4.0-r1.pdf)

3 : look into SecureStateDriver.lua if an event is triggered in your case


All times are GMT -6. The time now is 03:44 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI