From 8a13ec1bf93527dc47f5d0a4c8d0c84d848a3e92 Mon Sep 17 00:00:00 2001 From: FireSiku Date: Mon, 11 Jun 2018 03:15:44 -0400 Subject: [PATCH] Hooks's active status is based on mod's enabled status now. Also, allow hook_enable and hook_disable to be delayed as well. --- vmf/scripts/mods/vmf/modules/core/hooks.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/vmf/scripts/mods/vmf/modules/core/hooks.lua b/vmf/scripts/mods/vmf/modules/core/hooks.lua index 47d72ca..027709b 100644 --- a/vmf/scripts/mods/vmf/modules/core/hooks.lua +++ b/vmf/scripts/mods/vmf/modules/core/hooks.lua @@ -204,7 +204,7 @@ local function create_hook(self, orig, obj, method, handler, func_name, hook_typ -- Check to make sure it wasn't hooked before if not _registry[self][orig] then - _registry[self][orig] = { active = true } + _registry[self][orig] = { active = self:is_enabled() } local hook_registry = _registry.hooks[hook_type] -- Add to the hook to registry. Origin hooks are unique, so we check for that too. @@ -318,8 +318,17 @@ local function generic_hook_toggle(self, obj, method, enabled_state) local obj, success = get_object_reference(obj) --luacheck: ignore if obj and not success then - self:error("(%s): object doesn't exist.", func_name) - return + if _delaying_enabled and type(obj) == "string" then + -- Call this func at a later time, using upvalues. + self:info("(%s): [%s.%s] needs to be delayed.", func_name, obj, method) + table.insert(_delayed, function() + generic_hook_toggle(self, obj, method, enabled_state) + end) + return + else + self:error("(%s): trying to toggle hook on object that doesn't exist: %s", func_name, obj) + return + end end local orig = get_orig_function(self, obj, method)