File hook fixes. Still need to fix rehooks

This commit is contained in:
Aussiemon 2023-01-08 02:14:18 -07:00
parent c77af55020
commit e97c394006
3 changed files with 17 additions and 11 deletions

View file

@ -401,14 +401,13 @@ function DMFMod:hook_file(obj_str, method_str, handler)
_hooks_by_file[obj_str] = _hooks_by_file[obj_str] or {}
local hook_create_func = function(this_filepath, this_index)
local dynamic_obj =
"dmf:get_require_store(\"" .. this_filepath .. "\")[" .. tostring(this_index) .. "]"
local dynamic_obj = self:get_require_store(this_filepath)[this_index]
return generic_hook(self, dynamic_obj, method_str, handler, "hook")
end
table.insert(_hooks_by_file[obj_str], hook_create_func)
-- Add the new hook to every instance of the file
local all_file_instances = dmf:get_require_store(obj_str)
local all_file_instances = self:get_require_store(obj_str)
if all_file_instances then
for i, item in ipairs(all_file_instances) do
if item then
@ -468,11 +467,9 @@ dmf.apply_delayed_hooks = function(status, state)
end
end
dmf.apply_hooks_to_file = function(filepath, store_index)
local all_file_instances = dmf:get_require_store(filepath)
local file_instance = all_file_instances and all_file_instances[store_index]
dmf.apply_hooks_to_file = function(require_store, filepath, store_index)
local all_file_hooks = _hooks_by_file[filepath]
local file_instance = require_store and require_store[store_index]
if all_file_hooks and file_instance then
for _, hook_create_func in ipairs(all_file_hooks) do

View file

@ -39,8 +39,9 @@ local _notification_types = {
local function add_chat_notification(message, notification_type, sound_event, replay_to_chat_on_error)
if Managers.event then
Managers.event:trigger("event_add_notification_message",
_notification_types[notification_type] and notification_type or "default",
Managers.event:trigger(
"event_add_notification_message",
_notification_types[notification_type] and notification_type or "default",
message or "",
nil,
sound_event or UISoundEvents.default_click

View file

@ -62,12 +62,20 @@ end
-- ##### Hooks #########################################################################################################
-- #####################################################################################################################
-- Handles the swap to io for registered files
-- Handles the swap to io for registered files and the application of file hooks
dmf:hook(_G, "require", function (func, path, ...)
if _io_requires[path] then
return dmf:dofile(path)
else
return func(path, ...)
local result = func(path, ...)
-- Apply any file hooks to the newly-required file
local require_store = get_require_store(path)
if require_store then
dmf.apply_hooks_to_file(require_store, path, #require_store)
end
return result
end
end)