fix(dtmm): Fix patching GameStateMachine

The monkey-pacthed function was still called multiple times.
This commit is contained in:
Lucas Schwiderski 2023-02-25 17:26:24 +01:00
parent 974641b2ea
commit d6ee6e9a10
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8

View file

@ -59,8 +59,13 @@ local function patch_mod_loading_state()
print("[mod_main] Adding mod loading state") print("[mod_main] Adding mod loading state")
local GameStateMachine = require("scripts/foundation/utilities/game_state_machine") local GameStateMachine = require("scripts/foundation/utilities/game_state_machine")
local patched = false
local GameStateMachine_init = GameStateMachine.init local GameStateMachine_init = GameStateMachine.init
GameStateMachine.init = function(self, parent, start_state, params, ...) GameStateMachine.init = function(self, parent, start_state, params, ...)
if not patched then
patched = true
-- Hardcoded position after `StateRequireScripts`. -- Hardcoded position after `StateRequireScripts`.
-- We do want to wait until then, so that most of the game's core -- We do want to wait until then, so that most of the game's core
-- systems are at least loaded and can be hooked, even if they aren't -- systems are at least loaded and can be hooked, even if they aren't
@ -72,12 +77,11 @@ print("[mod_main] Adding mod loading state")
package_manager = params.package_manager, package_manager = params.package_manager,
}, },
}) })
-- Clean up after us
GameStateMachine.init = GameStateMachine_init
return GameStateMachine_init(self, parent, start_state, params, ...)
end end
GameStateMachine_init(self, parent, start_state, params, ...)
end
print("[mod_main] Mod patching complete")
end end
function init() function init()