diff --git a/scripts/mods/dml/hook.lua b/scripts/mods/dml/hook.lua index deed632..f64a158 100644 --- a/scripts/mods/dml/hook.lua +++ b/scripts/mods/dml/hook.lua @@ -49,7 +49,7 @@ local function get_item(obj, func_name) local item = table.clone(item_template) item.obj = obj item.name = func_name - item.func = get_func(func_name) + item.func = get_func(obj, func_name) -- Save table.insert(MODS_HOOKS, item) @@ -121,8 +121,8 @@ end -- -- Set hook -- -local function set(mod_name, func_name, hook_func) - local item = get_item(func_name) +local function set(mod_name, obj, func_name, hook_func) + local item = get_item(obj, func_name) local item_hook = get_item_hook(item, mod_name) print_log_info(mod_name, "Hooking " .. func_name) diff --git a/scripts/mods/dml/init.lua b/scripts/mods/dml/init.lua index 9a716f5..f455539 100644 --- a/scripts/mods/dml/init.lua +++ b/scripts/mods/dml/init.lua @@ -1,10 +1,14 @@ +local StateGame = require("scripts/game_states/state_game") +local StateSplash = require("scripts/game_states/game/state_splash") +local GameStateMachine = require("scripts/foundation/utilities/game_state_machine") + -- The loader object that is used during game boot -- to initialize the modding environment. local loader = {} Mods = {} -function loader:init(libs, mod_data, boot_gui) +function loader:init(mod_data, libs, boot_gui) -- The metatable prevents overwriting these self._libs = setmetatable({}, { __index = libs }) Mods.lua = self._libs @@ -15,18 +19,19 @@ function loader:init(libs, mod_data, boot_gui) dofile("scripts/mods/dml/hook") local ModLoader = dofile("scripts/mods/dml/mod_loader") - local mod_loader = ModLoader:new(boot_gui, mod_data) + local mod_loader = ModLoader:new(mod_data, libs, boot_gui) self._mod_loader = mod_loader + Managers.mod = mod_loader -- The mod loader needs to remain active during game play, to -- enable reloads - Mods.hook.set("DML", GameState, "update", function(func, dt, ...) + Mods.hook.set("DML", StateGame, "update", function(func, dt, ...) mod_loader:update(dt) return func(dt, ...) end) -- Skip splash view - Mods.hook.set("Base", StateSplash, "on_enter", function(func, self, ...) + Mods.hook.set("DML", StateSplash, "on_enter", function(func, self, ...) local result = func(self, ...) self._should_skip = true @@ -36,7 +41,7 @@ function loader:init(libs, mod_data, boot_gui) end) -- Trigger state change events - Mods.hook.set("Base", GameStateMachine, "_change_state", function(func, self, ...) + Mods.hook.set("DML", GameStateMachine, "_change_state", function(func, self, ...) local old_state = self._state local old_state_name = old_state and self:current_state_name() @@ -57,7 +62,7 @@ function loader:init(libs, mod_data, boot_gui) end) -- Trigger ending state change event - Mods.hook.set("Base", GameStateMachine, "destroy", function(func, self, ...) + Mods.hook.set("DML", GameStateMachine, "destroy", function(func, self, ...) local old_state = self._state local old_state_name = old_state and self:current_state_name() @@ -75,7 +80,7 @@ function loader:update(dt) local done = mod_loader:all_mods_loaded() if done then - mod_loader:_remove_gui() + mod_loader:remove_gui() end return done diff --git a/scripts/mods/dml/mod_loader.lua b/scripts/mods/dml/mod_loader.lua index b7440f5..1331473 100644 --- a/scripts/mods/dml/mod_loader.lua +++ b/scripts/mods/dml/mod_loader.lua @@ -3,6 +3,10 @@ -- the purpose of loading mods within Warhammer 40,000: Darktide. local ModLoader = class("ModLoader") +local ScriptGui = require("scripts/foundation/utilities/script_gui") + +local FONT_MATERIAL = "content/ui/fonts/arial" + local LOG_LEVELS = { spew = 4, info = 3, @@ -19,8 +23,9 @@ local BUTTON_INDEX_R = Keyboard.button_index("r") local BUTTON_INDEX_LEFT_SHIFT = Keyboard.button_index("left shift") local BUTTON_INDEX_LEFT_CTRL = Keyboard.button_index("left ctrl") -ModLoader.init = function(self, boot_gui, mod_data) +ModLoader.init = function(self, mod_data, libs, boot_gui) self._mod_data = mod_data + self._libs = libs self._gui = boot_gui self._settings = Application.user_setting("mod_settings") or DEFAULT_SETTINGS @@ -31,10 +36,6 @@ ModLoader.init = function(self, boot_gui, mod_data) self._reload_data = {} self._ui_time = 0 - if Crashify then - Crashify.print_property("modded", true) - end - self._state = "scanning" end @@ -55,7 +56,9 @@ ModLoader._draw_state_to_gui = function(self, gui, dt) status_str = string.format("Loading mod %q", mod.name) end - Gui.text(gui, status_str .. string.rep(".", (2 * t) % 4), "materials/fonts/arial", 16, nil, Vector3(5, 10, 1)) + local msg = status_str .. string.rep(".", (2 * t) % 4) + Log.info("ModLoader", msg) + ScriptGui.text(gui, msg, FONT_MATERIAL, 48, Vector3(20, 30, 1), Color.white()) end ModLoader.remove_gui = function(self) @@ -120,9 +123,9 @@ ModLoader.update = function(self, dt) if not ok then self:print("error", "%s", object) end - local name = mod.name mod.object = object or {} + self:_run_callback(mod, "init", self._reload_data[mod.id]) self:print("info", "%s loaded.", name) self._state = self:_load_mod(self._mod_load_index + 1) @@ -197,6 +200,7 @@ ModLoader._build_mod_table = function(self) name = mod_data.name, loaded_packages = {}, packages = mod_data.packages, + data = mod_data, } end diff --git a/scripts/mods/dml/require.lua b/scripts/mods/dml/require.lua index d311b56..bc808a9 100644 --- a/scripts/mods/dml/require.lua +++ b/scripts/mods/dml/require.lua @@ -6,12 +6,11 @@ Mods.original_require = original_require local can_insert = function(filepath, new_result) local store = require_store[filepath] - local num_store = #store - if not store or num_store == 0 then + if not store or #store then return true end - if store[num_store] ~= new_result then + if store[#store] ~= new_result then return true end end