Xiiph@0: --- **AceHook-3.0** offers safe Hooking/Unhooking of functions, methods and frame scripts. Xiiph@0: -- Using AceHook-3.0 is recommended when you need to unhook your hooks again, so the hook chain isn't broken Xiiph@0: -- when you manually restore the original function. Xiiph@0: -- Xiiph@0: -- **AceHook-3.0** can be embeded into your addon, either explicitly by calling AceHook:Embed(MyAddon) or by Xiiph@0: -- specifying it as an embeded library in your AceAddon. All functions will be available on your addon object Xiiph@0: -- and can be accessed directly, without having to explicitly call AceHook itself.\\ Xiiph@0: -- It is recommended to embed AceHook, otherwise you'll have to specify a custom `self` on all calls you Xiiph@0: -- make into AceHook. Xiiph@0: -- @class file Xiiph@0: -- @name AceHook-3.0 Xiiph@0: -- @release $Id: AceHook-3.0.lua 877 2009-11-02 15:56:50Z nevcairiel $ Xiiph@0: local ACEHOOK_MAJOR, ACEHOOK_MINOR = "AceHook-3.0", 5 Xiiph@0: local AceHook, oldminor = LibStub:NewLibrary(ACEHOOK_MAJOR, ACEHOOK_MINOR) Xiiph@0: Xiiph@0: if not AceHook then return end -- No upgrade needed Xiiph@0: Xiiph@0: AceHook.embeded = AceHook.embeded or {} Xiiph@0: AceHook.registry = AceHook.registry or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) Xiiph@0: AceHook.handlers = AceHook.handlers or {} Xiiph@0: AceHook.actives = AceHook.actives or {} Xiiph@0: AceHook.scripts = AceHook.scripts or {} Xiiph@0: AceHook.onceSecure = AceHook.onceSecure or {} Xiiph@0: AceHook.hooks = AceHook.hooks or {} Xiiph@0: Xiiph@0: -- local upvalues Xiiph@0: local registry = AceHook.registry Xiiph@0: local handlers = AceHook.handlers Xiiph@0: local actives = AceHook.actives Xiiph@0: local scripts = AceHook.scripts Xiiph@0: local onceSecure = AceHook.onceSecure Xiiph@0: Xiiph@0: -- Lua APIs Xiiph@0: local pairs, next, type = pairs, next, type Xiiph@0: local format = string.format Xiiph@0: local assert, error = assert, error Xiiph@0: Xiiph@0: -- WoW APIs Xiiph@0: local issecurevariable, hooksecurefunc = issecurevariable, hooksecurefunc Xiiph@0: local _G = _G Xiiph@0: Xiiph@0: -- functions for later definition Xiiph@0: local donothing, createHook, hook Xiiph@0: Xiiph@0: local protectedScripts = { Xiiph@0: OnClick = true, Xiiph@0: } Xiiph@0: Xiiph@0: -- upgrading of embeded is done at the bottom of the file Xiiph@0: Xiiph@0: local mixins = { Xiiph@0: "Hook", "SecureHook", Xiiph@0: "HookScript", "SecureHookScript", Xiiph@0: "Unhook", "UnhookAll", Xiiph@0: "IsHooked", Xiiph@0: "RawHook", "RawHookScript" Xiiph@0: } Xiiph@0: Xiiph@0: -- AceHook:Embed( target ) Xiiph@0: -- target (object) - target object to embed AceHook in Xiiph@0: -- Xiiph@0: -- Embeds AceEevent into the target object making the functions from the mixins list available on target:.. Xiiph@0: function AceHook:Embed( target ) Xiiph@0: for k, v in pairs( mixins ) do Xiiph@0: target[v] = self[v] Xiiph@0: end Xiiph@0: self.embeded[target] = true Xiiph@0: -- inject the hooks table safely Xiiph@0: target.hooks = target.hooks or {} Xiiph@0: return target Xiiph@0: end Xiiph@0: Xiiph@0: -- AceHook:OnEmbedDisable( target ) Xiiph@0: -- target (object) - target object that is being disabled Xiiph@0: -- Xiiph@0: -- Unhooks all hooks when the target disables. Xiiph@0: -- this method should be called by the target manually or by an addon framework Xiiph@0: function AceHook:OnEmbedDisable( target ) Xiiph@0: target:UnhookAll() Xiiph@0: end Xiiph@0: Xiiph@0: function createHook(self, handler, orig, secure, failsafe) Xiiph@0: local uid Xiiph@0: local method = type(handler) == "string" Xiiph@0: if failsafe and not secure then Xiiph@0: -- failsafe hook creation Xiiph@0: uid = function(...) Xiiph@0: if actives[uid] then Xiiph@0: if method then Xiiph@0: self[handler](self, ...) Xiiph@0: else Xiiph@0: handler(...) Xiiph@0: end Xiiph@0: end Xiiph@0: return orig(...) Xiiph@0: end Xiiph@0: -- /failsafe hook Xiiph@0: else Xiiph@0: -- all other hooks Xiiph@0: uid = function(...) Xiiph@0: if actives[uid] then Xiiph@0: if method then Xiiph@0: return self[handler](self, ...) Xiiph@0: else Xiiph@0: return handler(...) Xiiph@0: end Xiiph@0: elseif not secure then -- backup on non secure Xiiph@0: return orig(...) Xiiph@0: end Xiiph@0: end Xiiph@0: -- /hook Xiiph@0: end Xiiph@0: return uid Xiiph@0: end Xiiph@0: Xiiph@0: function donothing() end Xiiph@0: Xiiph@0: function hook(self, obj, method, handler, script, secure, raw, forceSecure, usage) Xiiph@0: if not handler then handler = method end Xiiph@0: Xiiph@0: -- These asserts make sure AceHooks's devs play by the rules. Xiiph@0: assert(not script or type(script) == "boolean") Xiiph@0: assert(not secure or type(secure) == "boolean") Xiiph@0: assert(not raw or type(raw) == "boolean") Xiiph@0: assert(not forceSecure or type(forceSecure) == "boolean") Xiiph@0: assert(usage) Xiiph@0: Xiiph@0: -- Error checking Battery! Xiiph@0: if obj and type(obj) ~= "table" then Xiiph@0: error(format("%s: 'object' - nil or table expected got %s", usage, type(obj)), 3) Xiiph@0: end Xiiph@0: if type(method) ~= "string" then Xiiph@0: error(format("%s: 'method' - string expected got %s", usage, type(method)), 3) Xiiph@0: end Xiiph@0: if type(handler) ~= "string" and type(handler) ~= "function" then Xiiph@0: error(format("%s: 'handler' - nil, string, or function expected got %s", usage, type(handler)), 3) Xiiph@0: end Xiiph@0: if type(handler) == "string" and type(self[handler]) ~= "function" then Xiiph@0: error(format("%s: 'handler' - Handler specified does not exist at self[handler]", usage), 3) Xiiph@0: end Xiiph@0: if script then Xiiph@0: if not secure and obj:IsProtected() and protectedScripts[method] then Xiiph@0: error(format("Cannot hook secure script %q; Use SecureHookScript(obj, method, [handler]) instead.", method), 3) Xiiph@0: end Xiiph@0: if not obj or not obj.GetScript or not obj:HasScript(method) then Xiiph@0: error(format("%s: You can only hook a script on a frame object", usage), 3) Xiiph@0: end Xiiph@0: else Xiiph@0: local issecure Xiiph@0: if obj then Xiiph@0: issecure = onceSecure[obj] and onceSecure[obj][method] or issecurevariable(obj, method) Xiiph@0: else Xiiph@0: issecure = onceSecure[method] or issecurevariable(method) Xiiph@0: end Xiiph@0: if issecure then Xiiph@0: if forceSecure then Xiiph@0: if obj then Xiiph@0: onceSecure[obj] = onceSecure[obj] or {} Xiiph@0: onceSecure[obj][method] = true Xiiph@0: else Xiiph@0: onceSecure[method] = true Xiiph@0: end Xiiph@0: elseif not secure then Xiiph@0: error(format("%s: Attempt to hook secure function %s. Use `SecureHook' or add `true' to the argument list to override.", usage, method), 3) Xiiph@0: end Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: local uid Xiiph@0: if obj then Xiiph@0: uid = registry[self][obj] and registry[self][obj][method] Xiiph@0: else Xiiph@0: uid = registry[self][method] Xiiph@0: end Xiiph@0: Xiiph@0: if uid then Xiiph@0: if actives[uid] then Xiiph@0: -- Only two sane choices exist here. We either a) error 100% of the time or b) always unhook and then hook Xiiph@0: -- choice b would likely lead to odd debuging conditions or other mysteries so we're going with a. Xiiph@0: error(format("Attempting to rehook already active hook %s.", method)) Xiiph@0: end Xiiph@0: Xiiph@0: if handlers[uid] == handler then -- turn on a decative hook, note enclosures break this ability, small memory leak Xiiph@0: actives[uid] = true Xiiph@0: return Xiiph@0: elseif obj then -- is there any reason not to call unhook instead of doing the following several lines? Xiiph@0: if self.hooks and self.hooks[obj] then Xiiph@0: self.hooks[obj][method] = nil Xiiph@0: end Xiiph@0: registry[self][obj][method] = nil Xiiph@0: else Xiiph@0: if self.hooks then Xiiph@0: self.hooks[method] = nil Xiiph@0: end Xiiph@0: registry[self][method] = nil Xiiph@0: end Xiiph@0: handlers[uid], actives[uid], scripts[uid] = nil, nil, nil Xiiph@0: uid = nil Xiiph@0: end Xiiph@0: Xiiph@0: local orig Xiiph@0: if script then Xiiph@0: orig = obj:GetScript(method) or donothing Xiiph@0: elseif obj then Xiiph@0: orig = obj[method] Xiiph@0: else Xiiph@0: orig = _G[method] Xiiph@0: end Xiiph@0: Xiiph@0: if not orig then Xiiph@0: error(format("%s: Attempting to hook a non existing target", usage), 3) Xiiph@0: end Xiiph@0: Xiiph@0: uid = createHook(self, handler, orig, secure, not (raw or secure)) Xiiph@0: Xiiph@0: if obj then Xiiph@0: self.hooks[obj] = self.hooks[obj] or {} Xiiph@0: registry[self][obj] = registry[self][obj] or {} Xiiph@0: registry[self][obj][method] = uid Xiiph@0: Xiiph@0: if not secure then Xiiph@0: self.hooks[obj][method] = orig Xiiph@0: end Xiiph@0: Xiiph@0: if script then Xiiph@0: -- If the script is empty before, HookScript will not work, so use SetScript instead Xiiph@0: -- This will make the hook insecure, but shouldnt matter, since it was empty before. Xiiph@0: -- It does not taint the full frame. Xiiph@0: if not secure or orig == donothing then Xiiph@0: obj:SetScript(method, uid) Xiiph@0: elseif secure then Xiiph@0: obj:HookScript(method, uid) Xiiph@0: end Xiiph@0: else Xiiph@0: if not secure then Xiiph@0: obj[method] = uid Xiiph@0: else Xiiph@0: hooksecurefunc(obj, method, uid) Xiiph@0: end Xiiph@0: end Xiiph@0: else Xiiph@0: registry[self][method] = uid Xiiph@0: Xiiph@0: if not secure then Xiiph@0: _G[method] = uid Xiiph@0: self.hooks[method] = orig Xiiph@0: else Xiiph@0: hooksecurefunc(method, uid) Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: actives[uid], handlers[uid], scripts[uid] = true, handler, script and true or nil Xiiph@0: end Xiiph@0: Xiiph@0: --- Hook a function or a method on an object. Xiiph@0: -- The hook created will be a "safe hook", that means that your handler will be called Xiiph@0: -- before the hooked function ("Pre-Hook"), and you don't have to call the original function yourself, Xiiph@0: -- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\ Xiiph@0: -- This type of hook is typically used if you need to know if some function got called, and don't want to modify it. Xiiph@0: -- @paramsig [object], method, [handler], [hookSecure] Xiiph@0: -- @param object The object to hook a method from Xiiph@0: -- @param method If object was specified, the name of the method, or the name of the function to hook. Xiiph@0: -- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function) Xiiph@0: -- @param hookSecure If true, AceHook will allow hooking of secure functions. Xiiph@0: -- @usage Xiiph@0: -- -- create an addon with AceHook embeded Xiiph@0: -- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0") Xiiph@0: -- Xiiph@0: -- function MyAddon:OnEnable() Xiiph@0: -- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status Xiiph@0: -- self:Hook("ActionButton_UpdateHotkeys", true) Xiiph@0: -- end Xiiph@0: -- Xiiph@0: -- function MyAddon:ActionButton_UpdateHotkeys(button, type) Xiiph@0: -- print(button:GetName() .. " is updating its HotKey") Xiiph@0: -- end Xiiph@0: function AceHook:Hook(object, method, handler, hookSecure) Xiiph@0: if type(object) == "string" then Xiiph@0: method, handler, hookSecure, object = object, method, handler, nil Xiiph@0: end Xiiph@0: Xiiph@0: if handler == true then Xiiph@0: handler, hookSecure = nil, true Xiiph@0: end Xiiph@0: Xiiph@0: hook(self, object, method, handler, false, false, false, hookSecure or false, "Usage: Hook([object], method, [handler], [hookSecure])") Xiiph@0: end Xiiph@0: Xiiph@0: --- RawHook a function or a method on an object. Xiiph@0: -- The hook created will be a "raw hook", that means that your handler will completly replace Xiiph@0: -- the original function, and your handler has to call the original function (or not, depending on your intentions).\\ Xiiph@0: -- The original function will be stored in `self.hooks[object][method]` or `self.hooks[functionName]` respectively.\\ Xiiph@0: -- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments Xiiph@0: -- or want to control execution of the original function. Xiiph@0: -- @paramsig [object], method, [handler], [hookSecure] Xiiph@0: -- @param object The object to hook a method from Xiiph@0: -- @param method If object was specified, the name of the method, or the name of the function to hook. Xiiph@0: -- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function) Xiiph@0: -- @param hookSecure If true, AceHook will allow hooking of secure functions. Xiiph@0: -- @usage Xiiph@0: -- -- create an addon with AceHook embeded Xiiph@0: -- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0") Xiiph@0: -- Xiiph@0: -- function MyAddon:OnEnable() Xiiph@0: -- -- Hook ActionButton_UpdateHotkeys, overwriting the secure status Xiiph@0: -- self:RawHook("ActionButton_UpdateHotkeys", true) Xiiph@0: -- end Xiiph@0: -- Xiiph@0: -- function MyAddon:ActionButton_UpdateHotkeys(button, type) Xiiph@0: -- if button:GetName() == "MyButton" then Xiiph@0: -- -- do stuff here Xiiph@0: -- else Xiiph@0: -- self.hooks.ActionButton_UpdateHotkeys(button, type) Xiiph@0: -- end Xiiph@0: -- end Xiiph@0: function AceHook:RawHook(object, method, handler, hookSecure) Xiiph@0: if type(object) == "string" then Xiiph@0: method, handler, hookSecure, object = object, method, handler, nil Xiiph@0: end Xiiph@0: Xiiph@0: if handler == true then Xiiph@0: handler, hookSecure = nil, true Xiiph@0: end Xiiph@0: Xiiph@0: hook(self, object, method, handler, false, false, true, hookSecure or false, "Usage: RawHook([object], method, [handler], [hookSecure])") Xiiph@0: end Xiiph@0: Xiiph@0: --- SecureHook a function or a method on an object. Xiiph@0: -- This function is a wrapper around the `hooksecurefunc` function in the WoW API. Using AceHook Xiiph@0: -- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't Xiiph@0: -- required anymore, or the addon is being disabled.\\ Xiiph@0: -- Secure Hooks should be used if the secure-status of the function is vital to its function, Xiiph@0: -- and taint would block execution. Secure Hooks are always called after the original function was called Xiiph@0: -- ("Post Hook"), and you cannot modify the arguments, return values or control the execution. Xiiph@0: -- @paramsig [object], method, [handler] Xiiph@0: -- @param object The object to hook a method from Xiiph@0: -- @param method If object was specified, the name of the method, or the name of the function to hook. Xiiph@0: -- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked function) Xiiph@0: function AceHook:SecureHook(object, method, handler) Xiiph@0: if type(object) == "string" then Xiiph@0: method, handler, object = object, method, nil Xiiph@0: end Xiiph@0: Xiiph@0: hook(self, object, method, handler, false, true, false, false, "Usage: SecureHook([object], method, [handler])") Xiiph@0: end Xiiph@0: Xiiph@0: --- Hook a script handler on a frame. Xiiph@0: -- The hook created will be a "safe hook", that means that your handler will be called Xiiph@0: -- before the hooked script ("Pre-Hook"), and you don't have to call the original function yourself, Xiiph@0: -- however you cannot stop the execution of the function, or modify any of the arguments/return values.\\ Xiiph@0: -- This is the frame script equivalent of the :Hook safe-hook. It would typically be used to be notified Xiiph@0: -- when a certain event happens to a frame. Xiiph@0: -- @paramsig frame, script, [handler] Xiiph@0: -- @param frame The Frame to hook the script on Xiiph@0: -- @param script The script to hook Xiiph@0: -- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script) Xiiph@0: -- @usage Xiiph@0: -- -- create an addon with AceHook embeded Xiiph@0: -- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0") Xiiph@0: -- Xiiph@0: -- function MyAddon:OnEnable() Xiiph@0: -- -- Hook the OnShow of FriendsFrame Xiiph@0: -- self:HookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow") Xiiph@0: -- end Xiiph@0: -- Xiiph@0: -- function MyAddon:FriendsFrameOnShow(frame) Xiiph@0: -- print("The FriendsFrame was shown!") Xiiph@0: -- end Xiiph@0: function AceHook:HookScript(frame, script, handler) Xiiph@0: hook(self, frame, script, handler, true, false, false, false, "Usage: HookScript(object, method, [handler])") Xiiph@0: end Xiiph@0: Xiiph@0: --- RawHook a script handler on a frame. Xiiph@0: -- The hook created will be a "raw hook", that means that your handler will completly replace Xiiph@0: -- the original script, and your handler has to call the original script (or not, depending on your intentions).\\ Xiiph@0: -- The original script will be stored in `self.hooks[frame][script]`.\\ Xiiph@0: -- This type of hook can be used for all purposes, and is usually the most common case when you need to modify arguments Xiiph@0: -- or want to control execution of the original script. Xiiph@0: -- @paramsig frame, script, [handler] Xiiph@0: -- @param frame The Frame to hook the script on Xiiph@0: -- @param script The script to hook Xiiph@0: -- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script) Xiiph@0: -- @usage Xiiph@0: -- -- create an addon with AceHook embeded Xiiph@0: -- MyAddon = LibStub("AceAddon-3.0"):NewAddon("HookDemo", "AceHook-3.0") Xiiph@0: -- Xiiph@0: -- function MyAddon:OnEnable() Xiiph@0: -- -- Hook the OnShow of FriendsFrame Xiiph@0: -- self:RawHookScript(FriendsFrame, "OnShow", "FriendsFrameOnShow") Xiiph@0: -- end Xiiph@0: -- Xiiph@0: -- function MyAddon:FriendsFrameOnShow(frame) Xiiph@0: -- -- Call the original function Xiiph@0: -- self.hooks[frame].OnShow(frame) Xiiph@0: -- -- Do our processing Xiiph@0: -- -- .. stuff Xiiph@0: -- end Xiiph@0: function AceHook:RawHookScript(frame, script, handler) Xiiph@0: hook(self, frame, script, handler, true, false, true, false, "Usage: RawHookScript(object, method, [handler])") Xiiph@0: end Xiiph@0: Xiiph@0: --- SecureHook a script handler on a frame. Xiiph@0: -- This function is a wrapper around the `frame:HookScript` function in the WoW API. Using AceHook Xiiph@0: -- extends the functionality of secure hooks, and adds the ability to unhook once the hook isn't Xiiph@0: -- required anymore, or the addon is being disabled.\\ Xiiph@0: -- Secure Hooks should be used if the secure-status of the function is vital to its function, Xiiph@0: -- and taint would block execution. Secure Hooks are always called after the original function was called Xiiph@0: -- ("Post Hook"), and you cannot modify the arguments, return values or control the execution. Xiiph@0: -- @paramsig frame, script, [handler] Xiiph@0: -- @param frame The Frame to hook the script on Xiiph@0: -- @param script The script to hook Xiiph@0: -- @param handler The handler for the hook, a funcref or a method name. (Defaults to the name of the hooked script) Xiiph@0: function AceHook:SecureHookScript(frame, script, handler) Xiiph@0: hook(self, frame, script, handler, true, true, false, false, "Usage: SecureHookScript(object, method, [handler])") Xiiph@0: end Xiiph@0: Xiiph@0: --- Unhook from the specified function, method or script. Xiiph@0: -- @paramsig [obj], method Xiiph@0: -- @param obj The object or frame to unhook from Xiiph@0: -- @param method The name of the method, function or script to unhook from. Xiiph@0: function AceHook:Unhook(obj, method) Xiiph@0: local usage = "Usage: Unhook([obj], method)" Xiiph@0: if type(obj) == "string" then Xiiph@0: method, obj = obj, nil Xiiph@0: end Xiiph@0: Xiiph@0: if obj and type(obj) ~= "table" then Xiiph@0: error(format("%s: 'obj' - expecting nil or table got %s", usage, type(obj)), 2) Xiiph@0: end Xiiph@0: if type(method) ~= "string" then Xiiph@0: error(format("%s: 'method' - expeting string got %s", usage, type(method)), 2) Xiiph@0: end Xiiph@0: Xiiph@0: local uid Xiiph@0: if obj then Xiiph@0: uid = registry[self][obj] and registry[self][obj][method] Xiiph@0: else Xiiph@0: uid = registry[self][method] Xiiph@0: end Xiiph@0: Xiiph@0: if not uid or not actives[uid] then Xiiph@0: -- Declining to error on an unneeded unhook since the end effect is the same and this would just be annoying. Xiiph@0: return false Xiiph@0: end Xiiph@0: Xiiph@0: actives[uid], handlers[uid] = nil, nil Xiiph@0: Xiiph@0: if obj then Xiiph@0: registry[self][obj][method] = nil Xiiph@0: registry[self][obj] = next(registry[self][obj]) and registry[self][obj] or nil Xiiph@0: Xiiph@0: -- if the hook reference doesnt exist, then its a secure hook, just bail out and dont do any unhooking Xiiph@0: if not self.hooks[obj] or not self.hooks[obj][method] then return true end Xiiph@0: Xiiph@0: if scripts[uid] and obj:GetScript(method) == uid then -- unhooks scripts Xiiph@0: obj:SetScript(method, self.hooks[obj][method] ~= donothing and self.hooks[obj][method] or nil) Xiiph@0: scripts[uid] = nil Xiiph@0: elseif obj and self.hooks[obj] and self.hooks[obj][method] and obj[method] == uid then -- unhooks methods Xiiph@0: obj[method] = self.hooks[obj][method] Xiiph@0: end Xiiph@0: Xiiph@0: self.hooks[obj][method] = nil Xiiph@0: self.hooks[obj] = next(self.hooks[obj]) and self.hooks[obj] or nil Xiiph@0: else Xiiph@0: registry[self][method] = nil Xiiph@0: Xiiph@0: -- if self.hooks[method] doesn't exist, then this is a SecureHook, just bail out Xiiph@0: if not self.hooks[method] then return true end Xiiph@0: Xiiph@0: if self.hooks[method] and _G[method] == uid then -- unhooks functions Xiiph@0: _G[method] = self.hooks[method] Xiiph@0: end Xiiph@0: Xiiph@0: self.hooks[method] = nil Xiiph@0: end Xiiph@0: return true Xiiph@0: end Xiiph@0: Xiiph@0: --- Unhook all existing hooks for this addon. Xiiph@0: function AceHook:UnhookAll() Xiiph@0: for key, value in pairs(registry[self]) do Xiiph@0: if type(key) == "table" then Xiiph@0: for method in pairs(value) do Xiiph@0: self:Unhook(key, method) Xiiph@0: end Xiiph@0: else Xiiph@0: self:Unhook(key) Xiiph@0: end Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: --- Check if the specific function, method or script is already hooked. Xiiph@0: -- @paramsig [obj], method Xiiph@0: -- @param obj The object or frame to unhook from Xiiph@0: -- @param method The name of the method, function or script to unhook from. Xiiph@0: function AceHook:IsHooked(obj, method) Xiiph@0: -- we don't check if registry[self] exists, this is done by evil magicks in the metatable Xiiph@0: if type(obj) == "string" then Xiiph@0: if registry[self][obj] and actives[registry[self][obj]] then Xiiph@0: return true, handlers[registry[self][obj]] Xiiph@0: end Xiiph@0: else Xiiph@0: if registry[self][obj] and registry[self][obj][method] and actives[registry[self][obj][method]] then Xiiph@0: return true, handlers[registry[self][obj][method]] Xiiph@0: end Xiiph@0: end Xiiph@0: Xiiph@0: return false, nil Xiiph@0: end Xiiph@0: Xiiph@0: --- Upgrade our old embeded Xiiph@0: for target, v in pairs( AceHook.embeded ) do Xiiph@0: AceHook:Embed( target ) Xiiph@0: end