Thread Tools Display Modes
10-12-18, 07:39 AM   #1
tobias1919
A Deviate Faerie Dragon
Join Date: Mar 2015
Posts: 13
How to get function from standard wow ui

Hello.

I am trying to make an addon that can share and import macros between player in-game. I got most of the logic working, but i am now struggling with addon a shift+click function to the standard "MacroButtonX" buttons in the macro-frame. Any suggestions or ideas as to how i modify the function of a wow standard ui element such as the macro buttons?

Thanks on advance!
  Reply With Quote
10-12-18, 10:23 AM   #2
aallkkaa
A Warpwood Thunder Caller
 
aallkkaa's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 98
Basically, what you're asking for is a way to hook a function, namely a standard Blizzard function.
Hooking functions insecurely is usually a bad idea, specially if they are Blizzard ones. You will cause taint, which will spread to other parts of the UI (both Blizzard and other addons' elements), which will trigger events like ADDON_ACTION_BLOCKED or ADDON_ACTION_FORBIDDEN (and I'm talking about actions from sources other than your addon (Blizzard or other addons), even though the culprit will be your own hook.

Still, for the sake of understanding, I'll show you how to do an insecure hook first, and then link to the secure hooking functons the Blizzard API provides.

#1: Insecure hook on function "standardFunction" (full replacement):
Code:
myFunction = function()
-- do stuff
end

standardFunction = myFunction;

-- Any calls to standardFunction() (from Blizzard or another addon) will now call myFunction() instead. The original standardFunction no longer "exists" (there are no available references to it)
#2: Insecure hook on function "standardFunction" (prehook, i.e. with callback to the original function when done):
Code:
oldFunction = standardFunction;

myFunction = function()
-- do stuff
oldFunction();
end

standardFunction = myFunction;

-- Any calls to standardFunction() (from Blizzard or another addon) will now call myFunction() instead. myFunction does its thing and then calls the original standardFunction() (now accessible as oldFunction())[/
A full replacement or a prehook of a standard Blizzard function should never be done (well, there is an exception or two where you actually can't get around it; e.g. changing the color of a given text output to the standard ChatFrame).
As a rule of thumb, you should only fully replace or prehook a function of your own (in the same addon of yours or a global function from another addon of yours).

#3: Insecure hook on function "standardFunction" (posthook, i.e. with callback to the original function first):
Code:
oldFunction = standardFunction;

myFunction = function()
oldFunction();
-- do stuff
end

standardFunction = myFunction;

-- Any calls to standardFunction() (from Blizzard or another addon) will now call myFunction() instead. myFunction calls the original standardFunction() (now accessible as oldFunction()) and then does its thing.[/
All three hooks above are insecure. They will cause taint, the standard UI will notice and mark anything that later calls the hooked function (this is also valid for standard variables you may have changed) as insecure, thus restricting its usability, namely but not exclusively, during combat.


The standard API provides two functions (and a (big) little something else) to securely posthook functions (both Blizzard's and other addons'). For more details please see:
API hooksecurefunc
API Frame HookScript

You can also look at RestrictedEnvironment, SecureHandlers and the SecureStateDriver (as starting points to the whole thing).
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » How to get function from standard wow ui

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