Creates a secure "post hook" for the specified function. Your hook will be called with the same arguments after the original call is performed.
hooksecurefunc([table,] "functionName", hookfunc)
Optional Table - Table to hook the functionName key in; if omitted, defaults to the global table (_G).
String - name of the function being hooked.
Function - your hook function.
The following calls hook CastSpellByName and GameTooltip:SetUnitBuff without compromising their secure status. When those functions are called, the hook prints their argument list into the default chat frame.
hooksecurefunc("CastSpellByName", print); -- Hooks the global CastSpellByName
hooksecurefunc(GameTooltip, "SetUnitBuff", print); -- Hooks GameTooltip.SetUnitBuff
This is the only safe way to hook functions that execute protected functionality.
hookfunc is invoked after the original function, and receives the same parameters; return values from hookfunc are discarded.
After this function is used on a function, setfenv() throws an error when attempted on that function
You cannot "unhook" a function that is hooked with this function except by a UI reload. Calling hooksecurefunc() multiple times only adds more hooks to be called.
Also note that using hooksecurefunc() may not always produce the expected result. Keep in mind that it actually replaces the original function with a new one (the function reference changes). For example, if you try to hook the global function "MacroFrame_OnHide" (after the macro frame has been displayed), your function will not be called when the macro frame is closed. It's simply because in Blizzard_MacroUI.xml the OnHide function call is registered like this:
The function ID called when the frame is hidden is the former one, before you hooked "MacroFrame_OnHide". The workaround is to hook a function called by "MacroFrame_OnHide":
This page was last edited on 26 November 2018, at 20:49.
Content is available under CC BY-SA 3.0 unless otherwise noted. Game content and materials are trademarks and copyrights of their respective publisher and its licensors. All rights reserved.
This site is a part of Fandom, Inc. and is not affiliated with the game publisher.