diff --git a/scripts/mods/dmf/dmf_loader.lua b/scripts/mods/dmf/dmf_loader.lua index ee64df5..ff0b3c9 100644 --- a/scripts/mods/dmf/dmf_loader.lua +++ b/scripts/mods/dmf/dmf_loader.lua @@ -97,6 +97,13 @@ end function dmf_mod_object:on_game_state_changed(status, state) print("DMF:ON_GAME_STATE_CHANGED(), status: " .. tostring(status) .. ", state: " .. tostring(state)) + + -- Certain intialization procedures need to be delayed until the game's core systems are + -- fully initialized and running + if status == "enter" and state == "StateTitle" then + dmf.initialize_options() + end + dmf.mods_game_state_changed_event(status, state) dmf.save_unsaved_settings_to_file() dmf.apply_delayed_hooks() diff --git a/scripts/mods/dmf/modules/dmf_mod_manager.lua b/scripts/mods/dmf/modules/dmf_mod_manager.lua index 66b520e..5399aab 100644 --- a/scripts/mods/dmf/modules/dmf_mod_manager.lua +++ b/scripts/mods/dmf/modules/dmf_mod_manager.lua @@ -170,11 +170,13 @@ function dmf.initialize_mod_data(mod, mod_data) -- Mod's options initialization if mod_data.options or (not mod_data.is_mutator and not mod_data.options_widgets) then - local success, error_message = pcall(dmf.initialize_mod_options, mod, mod_data.options) - if not success then - mod:error(ERRORS.REGULAR.mod_options_initializing_failed, error_message) - return - end + dmf.safe_call( + dmf, + ERRORS.REGULAR.mod_options_initializing_failed, + dmf.initialize_mod_options, + mod, + mod_data.options + ) end -- Textures initialization @TODO: move to a separate function diff --git a/scripts/mods/dmf/modules/dmf_options.lua b/scripts/mods/dmf/modules/dmf_options.lua index c8ccf72..48626a3 100644 --- a/scripts/mods/dmf/modules/dmf_options.lua +++ b/scripts/mods/dmf/modules/dmf_options.lua @@ -257,24 +257,26 @@ end -- ##### Script ####################################################################################################### -- #################################################################################################################### -dmf.initialize_mod_data(dmf, dmf_mod_data) +dmf.initialize_options = function() + dmf.initialize_mod_data(dmf, dmf_mod_data) --- first DMF initialization --- it will be run only 1 time, when the player launch the game with DMF for the first time -if not dmf:get("dmf_initialized") then + -- first DMF initialization + -- it will be run only 1 time, when the player launch the game with DMF for the first time + if not dmf:get("dmf_initialized") then - dmf.load_logging_settings() - dmf.load_developer_mode_settings() - dmf.load_network_settings() - dmf.load_custom_textures_settings() - dmf.load_dev_console_settings() - dmf.load_chat_history_settings() + dmf.load_logging_settings() + dmf.load_developer_mode_settings() + dmf.load_network_settings() + dmf.load_custom_textures_settings() + dmf.load_dev_console_settings() + dmf.load_chat_history_settings() - -- Not necessary until the view is loaded - if dmf.load_dmf_options_view_settings then - dmf.load_dmf_options_view_settings() + -- Not necessary until the view is loaded + if dmf.load_dmf_options_view_settings then + dmf.load_dmf_options_view_settings() + end + + dmf:notify(dmf:localize("dmf_first_run_notification")) + dmf:set("dmf_initialized", true) end - - dmf:notify(dmf:localize("dmf_first_run_notification")) - dmf:set("dmf_initialized", true) end