Skip to content
everloot

Lore archive · Warcraft Wiki, 2023 dump

API hooksecurefunc

Last wiki revision 2022-08-03

Securely posthooks the specified function. The hook will be called with the same arguments after the original call is performed. hooksecurefunc([table,] functionName, hookfunc)

  • table:Optional Table - Table to hook the key in; if omitted, defaults to the global table.
  • functionName: - name of the function being hooked.
  • hookfunc: - your hook function.

The following calls hook and 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

<OnHide function="MacroFrame_OnHide"/> hooksecurefunc(MacroPopupFrame, "Hide", MyFunction) MacroPopupFrame:HookScript("OnHide", MyFunction)

  • This is the only safe way to hook functions that execute protected functionality.
  • 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":
  • If you want to securely hook a frame's script handler, use :

Source

https://warcraft.wiki.gg/wiki/API_hooksecurefunc · retrieved 2023-11-13 · CC BY-SA 4.0

Converted from wikitext with templates, tables and images removed, so some sentences may be missing values.

This archive predates WoW: Forever. For collected gameplay facts see the Forever database. Search the archive.