Thread Tools Display Modes
01-13-24, 10:25 PM   #1
soulreeperxiii
A Murloc Raider
Join Date: Jan 2024
Posts: 4
Protected function help

I cant figure out how to get this working. Blizzard says its a Protected Function. Is there any way to get this to run?

Code:
FrameButton:SetScript("OnClick", function()
	local index = GetCraftSelectionIndex()
	DoCraft(index)
end)
  Reply With Quote
01-14-24, 08:51 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,950
It depends on what you were hoping to achieve.
What part of the system you are working with.
Whether you were in combat at the time the error happened
And whether you set up your custom frame button to work in the secured environment ( if it's needed ).

For example:
This example for the OnClick command ( https://warcraft.wiki.gg/wiki/UIHANDLER_OnClick ) doesn't mention the need for a secured environment, so it should not error out like that.

So, depending on what the other 2 functions relate to and access could point to the reason why you are having this problem. Maybe seeing what those other functions do will help identify the cause.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-15-24, 05:48 AM   #3
soulreeperxiii
A Murloc Raider
Join Date: Jan 2024
Posts: 4
I am working with Blizzard_CraftUI.lua and Blizzard_CraftUI.xml
Neither of those two functions are documented, I am inferring what they do by looking at Blizzards code.
Its the DoCraft() function that fires the Protected event.

I think its a secure environment that I need? But I cant figure out how to do it. Here's what I've come up with so far:

Code:
local button = CreateFrame("Button", "FrameButton", UIParent, "SecureHandlerBaseTemplate")
button:SetScript("OnClick", function()
	local index = GetCraftSelectionIndex()
	DoCraft(index)
end)
  Reply With Quote
01-15-24, 06:37 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,950
Ah gotcha.

Not played with that (DoCraft) functionality myself but ..

https://warcraft.wiki.gg/wiki/Secure...rClickTemplate

Creating a button from a SecureHandlerClickTemplate would be a starting point as that would let you use a button to do something that is part of the secure frame system. This gives you a brief example but bear in mind that you have to pass information into the secure system for it to be accessible. The example creates 2 frame variables to use the frames.

Now, whether, protected functions work this route I don't know.

Looking at nUI there is a secure click button in use there with a somewhat simple set up. So I will grab out it's code as an example. I'm not sure how successful this will be for your task, as the button nUI uses just activates the visibility of another frame, so just comment out your code or make a copy of the file in case you need to go back to it.


Lua Code:
  1. local mysecurebutton       = CreateFrame( "Button", "MySecureButtonName", UIParent, "UIPanelButtonTemplate,SecureHandlerClickTemplate" )
  2. mysecurebutton:SetPoint("CENTER")
  3. mysecurebutton:SetSize(100, 40)
  4. mysecurebutton:SetText("DoCraft")
  5.  
  6. mysecurebutton:SetAttribute(
  7.     "_onclick",
  8.     [[
  9.         local index = self:GetAttribute( "craftselectionindex" )
  10.         DoCraft(index)
  11.     ]]
  12. )
  13.  
  14.  
  15. -- Somewhere in the rest of your code make sure this line is called before clicking the button
  16. mysecurebutton:SetAttribute( "craftselectionindex", GetCraftSelectionIndex() )

For reference this is a page of info regarding the secure handlers
https://warcraft.wiki.gg/wiki/SecureHandlers
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 01-15-24 at 06:44 AM.
  Reply With Quote
01-15-24, 11:11 AM   #5
soulreeperxiii
A Murloc Raider
Join Date: Jan 2024
Posts: 4
Thanks for the help Xrystal, i appreciate it. I plugged your example into my code and managed to get it to run. This was exactly what I needed. However, I think I have a new problem now.

This works perfectly and outputs the expected index value in the Print function.
Lua Code:
  1. mysecurebutton:SetAttribute(
  2.     "_onclick",
  3.     [[
  4.         local index = self:GetAttribute( "craftselectionindex" )
  5.         print(index)
  6.     ]]
  7. )

This does absoluty nothing at all, no error when ran but also seems to not even perform the function.
Lua Code:
  1. mysecurebutton:SetAttribute(
  2.     "_onclick",
  3.     [[
  4.         local index = self:GetAttribute( "craftselectionindex" )
  5.         DoCraft(index)
  6.     ]]
  7. )

My guess is there is something more the defaut UI is doing for DoCraft() to function that I am not doing.
The Proteced message is not popping up but neither does it do anything.
Is there some type of logging mechanic I can use to see whats going on under the hood?
  Reply With Quote
01-15-24, 01:57 PM   #6
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
There are two basic types of protections: hardware and full.

If it's a hardware protection, the function can only be called with a mouse click or a key press.

If it's a full protection, no custom code can use it at all.

If you're trying to get your code to autocraft it and it's giving you a protected error, try making a secure button and either click it or assign it to a key to continue the craft.
  Reply With Quote
01-15-24, 02:45 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,950
As I suspected, the protected side of the DoCraft function might not be allowed by addons at all.

Debugging:
I don't think there will be much you can do if it isn't erroring out noisily. I suspect because it is being called in a secure environment it is just silently failing because it isn't a Blizzard addon calling it. However, if you don't have Bugsack or Buggrabber installed, you might want to, and see if they see something.


Protected functions with no accessible code:
There is no DoCraft function in the accessible Blizzard code that I can see which could explain why there is no info on it in the wow api code. It's probably one of their behind the scenes code that is just called by valid callers.

It is only used directly in the xml file on the Crafting Button that you click in their UI.
https://github.com/Gethe/wow-ui-sour...rd_CraftUI.xml

Looking for that button control in the lua file to see if they do anything else with it and apart from enabling and disabling I also noticed this line of code. However, like DoCraft(), this GetCraftButtonToken() function doesn't exist anywhere else.

Lua Code:
  1. -- Set the action button text
  2.     CraftCreateButton:SetText(getglobal(GetCraftButtonToken()));
https://github.com/Gethe/wow-ui-sour...raftUI.lua#L99


Did you try making sure the Blizzard addon is loaded to see if it is needed to have access to these functions? :
If you haven't already, you could try making sure that the Blizzard_CraftUI addon is loaded before using it's functionality.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-17-24, 05:22 PM   #8
soulreeperxiii
A Murloc Raider
Join Date: Jan 2024
Posts: 4
Thank you for all your help. At the very least, I now have a much better understanding of secure templates and handlers.
I am going to give up on getting this function to work. I know it used to work in original vanilla wow (BeastTraining) with no special secure templates, but no longer. It might be that it can only be called from a bliz addon, and its just hardwired that way, never changing. Who knows.

Anyway, thanks again and I did learn from this
  Reply With Quote
01-17-24, 08:41 PM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,950
Originally Posted by soulreeperxiii View Post
Thank you for all your help. At the very least, I now have a much better understanding of secure templates and handlers.
I am going to give up on getting this function to work. I know it used to work in original vanilla wow (BeastTraining) with no special secure templates, but no longer. It might be that it can only be called from a bliz addon, and its just hardwired that way, never changing. Who knows.

Anyway, thanks again and I did learn from this
Oh yeah, that was a long time ago. They made some heft secure/protected changes after then.

Working on nUI has helped me understand them somewhat - but I still get regular errors that I haven't figured out yet, any attempt at fixing where I think the problem is, just compounds the problem more. Like BeastTraining nUI has been around for a long time and likely has quite a lot of code working the way it shouldn't. I keep saying it, but maybe next expansion ( 20 years anniversary edition rewrite rofl ) but I said this 10 years ago and every expansion since and it just never happens rofl.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 01-17-24 at 08:44 PM.
  Reply With Quote

WoWInterface » Classic - AddOns, Compliations, Macros » Classic - AddOn Help/Support » Protected function help

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