Spelling checks and logging updates
This commit is contained in:
parent
dd31894cd2
commit
2f5bfd989a
1 changed files with 26 additions and 22 deletions
|
@ -73,7 +73,7 @@ local function get_orig_function(self, obj, method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return an object from the global table. Second return value is if it was sucessful.
|
-- Return an object from the global table. Second return value is if it was successful.
|
||||||
local function get_object_reference(obj)
|
local function get_object_reference(obj)
|
||||||
if type(obj) == "table" then
|
if type(obj) == "table" then
|
||||||
return obj, true
|
return obj, true
|
||||||
|
@ -112,7 +112,7 @@ end
|
||||||
-- ####################################################################################################################
|
-- ####################################################################################################################
|
||||||
|
|
||||||
-- For any given original function, return the newest entry of the hook_chain.
|
-- For any given original function, return the newest entry of the hook_chain.
|
||||||
-- Since all hooks of the chain contains the call to the previous one, we don't need to do any manual loops.
|
-- Since all hooks of the chain contain the call to the previous one, we don't need to do any manual loops.
|
||||||
-- This continues until the end of the chain, where the original function is called.
|
-- This continues until the end of the chain, where the original function is called.
|
||||||
local function get_hook_chain(orig)
|
local function get_hook_chain(orig)
|
||||||
local hook_registry = _registry.hooks
|
local hook_registry = _registry.hooks
|
||||||
|
@ -136,7 +136,7 @@ local function create_specialized_hook(self, orig, handler, hook_type)
|
||||||
local hook_data = _registry[self][orig]
|
local hook_data = _registry[self][orig]
|
||||||
|
|
||||||
-- Determine the previous function in the hook stack
|
-- Determine the previous function in the hook stack
|
||||||
-- Note: If a previous hook is removed from the table, these functions wouldnt be updated
|
-- Note: If a previous hook is removed from the table, these functions wouldn't be updated
|
||||||
-- This would break the chain, solution is to not remove the hooks, simply make them inactive
|
-- This would break the chain, solution is to not remove the hooks, simply make them inactive
|
||||||
-- Make sure inactive hooks that rely on the chain still call the next function seamlessly.
|
-- Make sure inactive hooks that rely on the chain still call the next function seamlessly.
|
||||||
local previous_hook = get_hook_chain(orig)
|
local previous_hook = get_hook_chain(orig)
|
||||||
|
@ -149,7 +149,7 @@ local function create_specialized_hook(self, orig, handler, hook_type)
|
||||||
return previous_hook(...)
|
return previous_hook(...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Rawhooks need to directly call the original function is inactive.
|
-- Make sure hook_origin directly calls the original function if inactive.
|
||||||
elseif hook_type == HOOK_TYPE_ORIGIN then
|
elseif hook_type == HOOK_TYPE_ORIGIN then
|
||||||
func = function(...)
|
func = function(...)
|
||||||
if hook_data.active then
|
if hook_data.active then
|
||||||
|
@ -164,8 +164,6 @@ local function create_specialized_hook(self, orig, handler, hook_type)
|
||||||
vmf.xpcall_no_return_values(self, "(safe_hook)", handler, ...)
|
vmf.xpcall_no_return_values(self, "(safe_hook)", handler, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
self:error("(create_specialized_hook): Invalid hook_type given. You should never this see.")
|
|
||||||
end
|
end
|
||||||
return func
|
return func
|
||||||
end
|
end
|
||||||
|
@ -209,7 +207,7 @@ local function create_hook(self, orig, obj, method, handler, func_name, hook_typ
|
||||||
_registry[self][orig] = { active = true }
|
_registry[self][orig] = { active = true }
|
||||||
|
|
||||||
local hook_registry = _registry.hooks[hook_type]
|
local hook_registry = _registry.hooks[hook_type]
|
||||||
-- Add to the hook to registry. Raw hooks are unique, so we check for that too.
|
-- Add to the hook to registry. Origin hooks are unique, so we check for that too.
|
||||||
if hook_type == HOOK_TYPE_ORIGIN then
|
if hook_type == HOOK_TYPE_ORIGIN then
|
||||||
if hook_registry[orig] then
|
if hook_registry[orig] then
|
||||||
self:error("(%s): Attempting to hook origin of already hooked function %s", func_name, method)
|
self:error("(%s): Attempting to hook origin of already hooked function %s", func_name, method)
|
||||||
|
@ -220,7 +218,13 @@ local function create_hook(self, orig, obj, method, handler, func_name, hook_typ
|
||||||
table.insert(hook_registry[orig], create_specialized_hook(self, orig, handler, hook_type) )
|
table.insert(hook_registry[orig], create_specialized_hook(self, orig, handler, hook_type) )
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:error("(%s): Attempting to rehook already active hook %s.", func_name, method)
|
-- This should be a warning log, but currently there are no differences between warning and error.
|
||||||
|
-- Wouldn't want to scare users that mods are broken because this used to be acceptable.
|
||||||
|
if vmf:get("developer_mode") then
|
||||||
|
self:warning("(%s): Attempting to rehook already active hook %s.", func_name, method)
|
||||||
|
else
|
||||||
|
self:info("(%s): Attempting to rehook already active hook %s.", func_name, method)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -260,9 +264,9 @@ local function generic_hook(self, obj, method, handler, func_name)
|
||||||
-- Get hook_type based on name
|
-- Get hook_type based on name
|
||||||
local hook_type = HOOK_TYPES[func_name]
|
local hook_type = HOOK_TYPES[func_name]
|
||||||
|
|
||||||
-- Grab the object's reference, if this fails, obj will remains a string and the hook will be delayed.
|
-- Grab the object's reference, if this fails, obj will remain a string and the hook will be delayed.
|
||||||
local obj, sucess = get_object_reference(obj) --luacheck: ignore
|
local obj, success = get_object_reference(obj) --luacheck: ignore
|
||||||
if obj and not sucess then
|
if obj and not success then
|
||||||
if _delaying_enabled and type(obj) == "string" then
|
if _delaying_enabled and type(obj) == "string" then
|
||||||
-- Call this func at a later time, using upvalues.
|
-- Call this func at a later time, using upvalues.
|
||||||
vmf:info("(%s): [%s.%s] needs to be delayed.", func_name, obj, method)
|
vmf:info("(%s): [%s.%s] needs to be delayed.", func_name, obj, method)
|
||||||
|
@ -307,8 +311,8 @@ local function generic_hook_toggle(self, obj, method, enabled_state)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local obj, sucess = get_object_reference(obj) --luacheck: ignore
|
local obj, success = get_object_reference(obj) --luacheck: ignore
|
||||||
if obj and not sucess then
|
if obj and not success then
|
||||||
self:error("(%s): object doesn't exist.", func_name)
|
self:error("(%s): object doesn't exist.", func_name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -318,8 +322,8 @@ local function generic_hook_toggle(self, obj, method, enabled_state)
|
||||||
if _registry[self][orig] then
|
if _registry[self][orig] then
|
||||||
_registry[self][orig].active = enabled_state
|
_registry[self][orig].active = enabled_state
|
||||||
else
|
else
|
||||||
|
-- This has the potential for mod-breaking behavior, but not guaranteed
|
||||||
self:warning("(%s): trying to toggle hook that doesn't exist: %s", func_name, method)
|
self:warning("(%s): trying to toggle hook that doesn't exist: %s", func_name, method)
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -336,7 +340,7 @@ function VMFMod:hook_safe(obj, method, handler)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- :hook() will allow you to hook a function, allowing your handler to replace the function in the stack,
|
-- :hook() will allow you to hook a function, allowing your handler to replace the function in the stack,
|
||||||
-- and control it's execution. All hooks on the same function will be part of a chain, with the
|
-- and control its execution. All hooks on the same function will be part of a chain, with the
|
||||||
-- original function at the end. Your handler has to call the next function in the chain manually.
|
-- original function at the end. Your handler has to call the next function in the chain manually.
|
||||||
-- The chain of event is determined by mod load order.
|
-- The chain of event is determined by mod load order.
|
||||||
function VMFMod:hook(obj, method, handler)
|
function VMFMod:hook(obj, method, handler)
|
||||||
|
@ -358,16 +362,16 @@ function VMFMod:hook_enable(obj, method) generic_hook_toggle(self, obj, method,
|
||||||
function VMFMod:hook_disable(obj, method) generic_hook_toggle(self, obj, method, false) end
|
function VMFMod:hook_disable(obj, method) generic_hook_toggle(self, obj, method, false) end
|
||||||
|
|
||||||
function VMFMod:enable_all_hooks()
|
function VMFMod:enable_all_hooks()
|
||||||
-- Using pairs because the self table may contain nils, and order isnt important.
|
self:info("(hooks): Enabling all hooks for mod: %s", self:get_name())
|
||||||
for _, hook in pairs(_registry[self]) do
|
for _, hook_data in pairs(_registry[self]) do
|
||||||
hook.active = true
|
hook_data.active = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function VMFMod:disable_all_hooks()
|
function VMFMod:disable_all_hooks()
|
||||||
-- Using pairs because the self table may contain nils, and order isnt important.
|
self:info("(hooks): Disabling all hooks for mod: %s", self:get_name())
|
||||||
for _, hook in pairs(_registry[self]) do
|
for _, hook_data in pairs(_registry[self]) do
|
||||||
hook.active = false
|
hook_data.active = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -375,7 +379,7 @@ end
|
||||||
-- ##### VMF internal functions and variables #########################################################################
|
-- ##### VMF internal functions and variables #########################################################################
|
||||||
-- ####################################################################################################################
|
-- ####################################################################################################################
|
||||||
|
|
||||||
-- -- removes all hooks when VMF is about to be reloaded
|
-- Remove all hooks when VMF is about to be reloaded
|
||||||
vmf.hooks_unload = function()
|
vmf.hooks_unload = function()
|
||||||
for key, value in pairs(_registry.origs) do
|
for key, value in pairs(_registry.origs) do
|
||||||
-- origs[method] = orig
|
-- origs[method] = orig
|
||||||
|
|
Loading…
Add table
Reference in a new issue