From 89e88b41af98ca4f95d0068551194b2ee8b5bcc5 Mon Sep 17 00:00:00 2001 From: FireSiku Date: Sun, 20 Jan 2019 22:53:10 -0500 Subject: [PATCH 1/3] [Hooks] Do not show unique ID address in info log --- vmf/scripts/mods/vmf/modules/core/hooks.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmf/scripts/mods/vmf/modules/core/hooks.lua b/vmf/scripts/mods/vmf/modules/core/hooks.lua index 82fb224..e6b2ca8 100644 --- a/vmf/scripts/mods/vmf/modules/core/hooks.lua +++ b/vmf/scripts/mods/vmf/modules/core/hooks.lua @@ -193,7 +193,7 @@ local function create_hook(mod, orig, obj, method, handler, func_name, hook_type else unique_id = obj[method] end - mod:info("(%s): Hooking '%s' from [%s] (Origin: %s) (UniqueID: %s)", func_name, method, obj, orig, unique_id) + mod:info("(%s): Hooking '%s' from [%s] (Origin: %s)", func_name, method, obj, orig) -- Check to make sure this mod hasn't hooked it before local hook_data = _registry[mod][unique_id] From 04f49e995bd3e4392a961eea86befb9c8e0af7d4 Mon Sep 17 00:00:00 2001 From: FireSiku Date: Sun, 20 Jan 2019 22:56:36 -0500 Subject: [PATCH 2/3] [Hooks] Show readable strings in hook creation info logs. --- vmf/scripts/mods/vmf/modules/core/hooks.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vmf/scripts/mods/vmf/modules/core/hooks.lua b/vmf/scripts/mods/vmf/modules/core/hooks.lua index e6b2ca8..0925045 100644 --- a/vmf/scripts/mods/vmf/modules/core/hooks.lua +++ b/vmf/scripts/mods/vmf/modules/core/hooks.lua @@ -86,6 +86,16 @@ local function can_rehook(mod, hook_data, obj, hook_type) end end +-- Search global table for an object that matches to get a readable string. +local function print_obj(obj) + for k, v in pairs(_G) do + if v == obj then + return k + end + end + return obj +end + -- #################################################################################################################### -- ##### Hook Creation ################################################################################################ -- #################################################################################################################### @@ -193,7 +203,7 @@ local function create_hook(mod, orig, obj, method, handler, func_name, hook_type else unique_id = obj[method] end - mod:info("(%s): Hooking '%s' from [%s] (Origin: %s)", func_name, method, obj, orig) + mod:info("(%s): Hooking '%s' from [%s] (Origin: %s)", func_name, method, print_obj(obj), orig) -- Check to make sure this mod hasn't hooked it before local hook_data = _registry[mod][unique_id] @@ -281,7 +291,7 @@ local function generic_hook(mod, obj, method, handler, func_name) -- Quick check to make sure the target exists if not obj[method] then - mod:error("(%s): trying to hook function or method that doesn't exist: [%s.%s]", func_name, obj, method) + mod:error("(%s): trying to hook function or method that doesn't exist: [%s.%s]", func_name, print_obj(obj), method) return end From b172d19f24839e0ae9c6c6845d12f42d2ce7214b Mon Sep 17 00:00:00 2001 From: FireSiku Date: Mon, 21 Jan 2019 04:49:59 -0500 Subject: [PATCH 3/3] [Hooks] Make Travis happy about long error messages --- vmf/scripts/mods/vmf/modules/core/hooks.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vmf/scripts/mods/vmf/modules/core/hooks.lua b/vmf/scripts/mods/vmf/modules/core/hooks.lua index 0925045..3df68ba 100644 --- a/vmf/scripts/mods/vmf/modules/core/hooks.lua +++ b/vmf/scripts/mods/vmf/modules/core/hooks.lua @@ -228,8 +228,8 @@ local function create_hook(mod, orig, obj, method, handler, func_name, hook_type hook_data.handler = handler elseif mod:get_internal_data("allow_rehooking") then -- If we can't rehook but rehooking is enabled, send a warning that something went wrong - mod:warning("(%s): Attempting to rehook active hook [%s] with different obj or hook_type.", func_name, - method) + mod:warning("(%s): Attempting to rehook active hook [%s] with different obj or hook_type.", + func_name, method) else mod:warning("(%s): Attempting to rehook active hook [%s].", func_name, method) end @@ -291,7 +291,8 @@ local function generic_hook(mod, obj, method, handler, func_name) -- Quick check to make sure the target exists if not obj[method] then - mod:error("(%s): trying to hook function or method that doesn't exist: [%s.%s]", func_name, print_obj(obj), method) + mod:error("(%s): trying to hook function or method that doesn't exist: [%s.%s]", + func_name, print_obj(obj), method) return end