From 48218a54d114257a931ff66044d9390cf533ffaa Mon Sep 17 00:00:00 2001 From: Aussiemon Date: Thu, 9 Feb 2023 14:00:09 -0700 Subject: [PATCH] Change hook_file to hook_require, fix init bug --- dmf/scripts/mods/dmf/modules/core/hooks.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dmf/scripts/mods/dmf/modules/core/hooks.lua b/dmf/scripts/mods/dmf/modules/core/hooks.lua index b4c1a1c..c59f0bb 100644 --- a/dmf/scripts/mods/dmf/modules/core/hooks.lua +++ b/dmf/scripts/mods/dmf/modules/core/hooks.lua @@ -422,15 +422,16 @@ function DMFMod:hook_origin(obj, method, handler) return generic_hook(self, obj, method, handler, "hook_origin") end --- :hook_file() allows you to hook every past and future version of a game file, +-- :hook_require() allows you to hook every past and future version of a game file, -- executing a callback function on every instance. -- The chain of event is determined by mod load order. -function DMFMod:hook_file(obj_str, callback_func) +function DMFMod:hook_require(obj_str, callback_func) -- Set up the tables for the file local mod_name = self:get_name() - _file_hooks_by_file[obj_str] = _file_hooks_by_file[obj_str] or {} - _file_hooks_applied_to_file[obj_str] = _file_hooks_applied_to_file[obj_str] or {[mod_name] = {}} + _file_hooks_by_file[obj_str] = _file_hooks_by_file[obj_str] or {} + _file_hooks_applied_to_file[obj_str] = _file_hooks_applied_to_file[obj_str] or {} + _file_hooks_applied_to_file[obj_str][mod_name] = _file_hooks_applied_to_file[obj_str][mod_name] or {} -- Store file hooks by mod name to prevent duplicates per mod _file_hooks_by_file[obj_str][mod_name] = callback_func