@@ -57,19 +57,6 @@ var mod_data := {}
57
57
# Order for mods to be loaded in, set by `_get_load_order`
58
58
var mod_load_order := []
59
59
60
- # Override for the path mods are loaded from. Only set if the CLI arg is present.
61
- # Can be tested in the editor via: Project Settings > Display> Editor > Main Run Args
62
- # Default: "res://mods"
63
- # Set via: --mods-path
64
- # Example: --mods-path="C://path/mods"
65
- var os_mods_path_override := ""
66
-
67
- # Override for the path config JSONs are loaded from
68
- # Default: "res://configs"
69
- # Set via: --configs-path
70
- # Example: --configs-path="C://path/configs"
71
- var os_configs_path_override := ""
72
-
73
60
# Any mods that are missing their dependancies are added to this
74
61
# Example property: "mod_id": ["dep_mod_id_0", "dep_mod_id_2"]
75
62
var mod_missing_dependencies := {}
@@ -87,73 +74,30 @@ var loaded_vanilla_parents_cache := {}
87
74
# Helps to decide whether a script extension should go through the _handle_script_extensions process
88
75
var is_initializing := true
89
76
90
- # True if ModLoader has displayed the warning about using zipped mods
91
- var has_shown_editor_warning := false
92
-
93
- # Keeps track of logged messages, to avoid flooding the log with duplicate notices
94
- var logged_messages := []
95
-
96
- # Path to the options resource
97
- # See: res://addons/mod_loader/options/options_current_data.gd
98
- var ml_options_path := "res://addons/mod_loader/options/options.tres"
99
-
100
- # These variables handle various options, which can be changed via Godot's GUI
101
- # by adding a ModLoaderOptions resource to the resource file specified by
102
- # `ml_options_path`. See res://addons/mod_loader/options_examples for some
103
- # resource files you can add to the options_curent file.
104
- # See: res://addons/mod_loader/options/classes/options_profile.gd
105
- var ml_options := {
106
- enable_mods = true ,
107
- log_level = ModLoaderUtils .verbosity_level .DEBUG ,
108
- path_to_mods = "res://mods" ,
109
- path_to_configs = "res://configs" ,
110
-
111
- # If true, ModLoader will load mod ZIPs from the Steam workshop directory,
112
- # instead of the default location (res://mods)
113
- steam_workshop_enabled = false ,
114
-
115
- # Can be used in the editor to load mods from your Steam workshop directory
116
- steam_workshop_path_override = "" ,
117
-
118
- # Array of mod ID strings to skip in `_setup_mods`
119
- disabled_mods = []
120
- }
121
-
122
77
123
78
# Main
124
79
# =============================================================================
125
80
126
81
func _init () -> void :
127
- _update_ml_options ()
128
-
129
82
# if mods are not enabled - don't load mods
130
83
if REQUIRE_CMD_LINE and not ModLoaderUtils .is_running_with_command_line_arg ("--enable-mods" ):
131
84
return
132
85
133
- if not ml_options .enable_mods :
134
- ModLoaderUtils .log_info ("Mods are currently disabled" , LOG_NAME )
135
- return
136
-
137
86
# Rotate the log files once on startup. Can't be checked in utils, since it's static
138
87
ModLoaderUtils .rotate_log_file ()
139
88
140
- # Ensure ModLoader is the first autoload
141
- _check_first_autoload ()
89
+ # Ensure ModLoaderStore and ModLoader are the 1st and 2nd autoloads
90
+ _check_autoload_positions ()
91
+
92
+ # Log the autoloads order. Helpful when providing support to players
93
+ ModLoaderUtils .log_debug_json_print ("Autoload order" , ModLoaderUtils .get_autoload_array (), LOG_NAME )
142
94
143
95
# Log game install dir
144
96
ModLoaderUtils .log_info ("game_install_directory: %s " % ModLoaderUtils .get_local_folder_dir (), LOG_NAME )
145
97
146
- # check if we want to use a different mods path that is provided as a command line argument
147
- var cmd_line_mod_path := ModLoaderUtils .get_cmd_line_arg_value ("--mods-path" )
148
- if not cmd_line_mod_path == "" :
149
- os_mods_path_override = cmd_line_mod_path
150
- ModLoaderUtils .log_info ("The path mods are loaded from has been changed via the CLI arg `--mods-path`, to: " + cmd_line_mod_path , LOG_NAME )
151
-
152
- # Check for the CLI arg that overrides the configs path
153
- var cmd_line_configs_path := ModLoaderUtils .get_cmd_line_arg_value ("--configs-path" )
154
- if not cmd_line_configs_path == "" :
155
- os_configs_path_override = cmd_line_configs_path
156
- ModLoaderUtils .log_info ("The path configs are loaded from has been changed via the CLI arg `--configs-path`, to: " + cmd_line_configs_path , LOG_NAME )
98
+ if not ModLoaderStore .ml_options .enable_mods :
99
+ ModLoaderUtils .log_info ("Mods are currently disabled" , LOG_NAME )
100
+ return
157
101
158
102
# Loop over "res://mods" and add any mod zips to the unpacked virtual
159
103
# directory (UNPACKED_DIR)
@@ -220,58 +164,28 @@ func _init() -> void:
220
164
is_initializing = false
221
165
222
166
223
- # Update ModLoader's options, via the custom options resource
224
- func _update_ml_options () -> void :
225
- # Get user options for ModLoader
226
- if File .new ().file_exists (ml_options_path ):
227
- var options_resource := load (ml_options_path )
228
- if not options_resource .current_options == null :
229
- var current_options : Resource = options_resource .current_options
230
- # Update from the options in the resource
231
- for key in ml_options :
232
- ml_options [key ] = current_options [key ]
233
- else :
234
- ModLoaderUtils .log_fatal (str ("A critical file is missing: " , ml_options_path ), LOG_NAME )
235
-
236
-
237
- # Ensure ModLoader is the first autoload
238
- func _check_first_autoload () -> void :
239
- var autoload_array = ModLoaderUtils .get_autoload_array ()
240
- var mod_loader_index = autoload_array .find ("ModLoader" )
241
- var is_mod_loader_first = mod_loader_index == 0
242
-
243
- var override_cfg_path = ModLoaderUtils .get_override_path ()
244
- var is_override_cfg_setup = ModLoaderUtils .file_exists (override_cfg_path )
245
-
246
- # Log the autoloads order. Might seem superflous but could help when providing support
247
- ModLoaderUtils .log_debug_json_print ("Autoload order" , autoload_array , LOG_NAME )
248
-
167
+ # Check autoload positions:
168
+ # Ensure 1st autoload is `ModLoaderStore`, and 2nd is `ModLoader`.
169
+ func _check_autoload_positions () -> void :
249
170
# If the override file exists we assume the ModLoader was setup with the --setup-create-override-cfg cli arg
250
171
# In that case the ModLoader will be the last entry in the autoload array
172
+ var override_cfg_path := ModLoaderUtils .get_override_path ()
173
+ var is_override_cfg_setup := ModLoaderUtils .file_exists (override_cfg_path )
251
174
if is_override_cfg_setup :
252
175
ModLoaderUtils .log_info ("override.cfg setup detected, ModLoader will be the last autoload loaded." , LOG_NAME )
253
176
return
254
177
255
- var base_msg = "ModLoader needs to be the first autoload to work correctly, "
256
- var help_msg = ""
257
-
258
- if OS .has_feature ("editor" ):
259
- help_msg = "To configure your autoloads, go to Project > Project Settings > Autoload, and add ModLoader as the first item. For more info, see the 'Godot Project Setup' page on the ModLoader GitHub wiki."
260
- else :
261
- help_msg = "If you're seeing this error, something must have gone wrong in the setup process."
262
-
263
- if not is_mod_loader_first :
264
- ModLoaderUtils .log_fatal (str (base_msg , 'but the first autoload is currently: "%s ". ' % autoload_array [0 ], help_msg ), LOG_NAME )
178
+ var _pos_ml_store := ModLoaderGodot .check_autoload_position ("ModLoaderStore" , 0 , true )
179
+ var _pos_ml_core := ModLoaderGodot .check_autoload_position ("ModLoader" , 1 , true )
265
180
266
181
267
182
# Loop over "res://mods" and add any mod zips to the unpacked virtual directory
268
183
# (UNPACKED_DIR)
269
184
func _load_mod_zips () -> int :
270
185
var zipped_mods_count := 0
271
186
272
- if not ml_options .steam_workshop_enabled :
273
- # Path to the games mod folder
274
- var mods_folder_path := ModLoaderUtils .get_local_folder_dir ("mods" )
187
+ if not ModLoaderStore .ml_options .steam_workshop_enabled :
188
+ var mods_folder_path := ModLoaderUtils .get_path_to_mods ()
275
189
276
190
# If we're not using Steam workshop, just loop over the mod ZIPs.
277
191
zipped_mods_count += _load_zips_in_folder (mods_folder_path )
@@ -326,12 +240,12 @@ func _load_zips_in_folder(folder_path: String) -> int:
326
240
# "don't use ZIPs with unpacked mods!"
327
241
# https://github.com/godotengine/godot/issues/19815
328
242
# https://github.com/godotengine/godot/issues/16798
329
- if OS .has_feature ("editor" ) and not has_shown_editor_warning :
243
+ if OS .has_feature ("editor" ) and not ModLoaderStore . has_shown_editor_zips_warning :
330
244
ModLoaderUtils .log_warning (str (
331
245
"Loading any resource packs (.zip/.pck) with `load_resource_pack` will WIPE the entire virtual res:// directory. " ,
332
246
"If you have any unpacked mods in " , UNPACKED_DIR , ", they will not be loaded. " ,
333
247
"Please unpack your mod ZIPs instead, and add them to " , UNPACKED_DIR ), LOG_NAME )
334
- has_shown_editor_warning = true
248
+ ModLoaderStore . has_shown_editor_zips_warning = true
335
249
336
250
ModLoaderUtils .log_debug ("Found mod ZIP: %s " % mod_folder_global_path , LOG_NAME )
337
251
@@ -355,10 +269,7 @@ func _load_zips_in_folder(folder_path: String) -> int:
355
269
# inside each workshop item's folder
356
270
func _load_steam_workshop_zips () -> int :
357
271
var temp_zipped_mods_count := 0
358
- var workshop_folder_path := ModLoaderSteam .get_steam_workshop_dir ()
359
-
360
- if not ml_options .steam_workshop_path_override == "" :
361
- workshop_folder_path = ml_options .steam_workshop_path_override
272
+ var workshop_folder_path := ModLoaderSteam .get_path_to_workshop ()
362
273
363
274
ModLoaderUtils .log_info ("Checking workshop items, with path: \" %s \" " % workshop_folder_path , LOG_NAME )
364
275
@@ -428,7 +339,7 @@ func _setup_mods() -> int:
428
339
if mod_dir_name == "." or mod_dir_name == ".." :
429
340
continue
430
341
431
- if ml_options .disabled_mods .has (mod_dir_name ):
342
+ if ModLoaderStore . ml_options .disabled_mods .has (mod_dir_name ):
432
343
ModLoaderUtils .log_info ("Skipped setting up mod: \" %s \" " % mod_dir_name , LOG_NAME )
433
344
continue
434
345
@@ -443,12 +354,7 @@ func _setup_mods() -> int:
443
354
# Load mod config JSONs from res://configs
444
355
func _load_mod_configs () -> void :
445
356
var found_configs_count := 0
446
- var configs_path := ModLoaderUtils .get_local_folder_dir ("configs" )
447
-
448
- # CLI override, set with `--configs-path="C://path/configs"`
449
- # (similar to os_mods_path_override)
450
- if not os_configs_path_override == "" :
451
- configs_path = os_configs_path_override
357
+ var configs_path := ModLoaderUtils .get_path_to_configs ()
452
358
453
359
for dir_name in mod_data :
454
360
var json_path := configs_path .plus_file (dir_name + ".json" )
0 commit comments