Skip to content

Commit 276ade5

Browse files
committed
fix: 🐛 check overwrites in zip
1 parent 0aaed36 commit 276ade5

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

addons/mod_loader/api/profile.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ static func enable_mod(mod_id: String, user_profile:= ModLoaderStore.current_use
2525
return _set_mod_state(mod_id, user_profile.name, true)
2626

2727

28+
## Forces enabling a mod - it will be loaded on the next game start even if load warnigns are present[br]
29+
## [br]
30+
## [b]Parameters:[/b][br]
31+
## - [code]mod_id[/code] ([String]): The ID of the mod to enable.[br]
32+
## - [code]user_profile[/code] ([ModUserProfile]): (Optional) The user profile to enable the mod for. Default is the current user profile.[br]
33+
## [br]
34+
## [b]Returns:[/b] [bool]
35+
static func force_enable_mod(mod_id: String, user_profile:= ModLoaderStore.current_user_profile) -> bool:
36+
return _set_mod_state(mod_id, user_profile.name, true, true)
37+
38+
2839
## Disables a mod - it will not be loaded on the next game start[br]
2940
## [br]
3041
## [b]Parameters:[/b][br]

addons/mod_loader/internal/file.gd

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,31 @@ static func remove_file(file_path: String) -> bool:
193193
# Checks
194194
# =============================================================================
195195

196-
static func file_exists(path: String) -> bool:
196+
static func file_exists(path: String, zip_path: String = "") -> bool:
197+
if not zip_path.is_empty():
198+
return zip_file_exists(path, zip_path)
199+
197200
return FileAccess.file_exists(path)
198201

199202

200203
static func dir_exists(path: String) -> bool:
201204
return DirAccess.dir_exists_absolute(path)
202205

203206

207+
static func zip_file_exists(path: String, zip_path: String = "") -> bool:
208+
var reader := zip_reader_open(zip_path)
209+
return reader.file_exists(path.trim_prefix("res://"))
210+
211+
212+
static func zip_reader_open(zip_path) -> ZIPReader:
213+
var reader := ZIPReader.new()
214+
var err := reader.open(zip_path)
215+
if err != OK:
216+
ModLoaderLog.error("Could not open zip with error: %s" % error_string(err), LOG_NAME)
217+
return
218+
return reader
219+
220+
204221
# Internal util functions
205222
# =============================================================================
206223
# These are duplicates of the functions in mod_loader_utils.gd to prevent

addons/mod_loader/resources/mod_data.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func _init(mod_id: String, _zip_path := "") -> void:
7777
dir_name = mod_id
7878

7979
var mod_overwrites_path := get_optional_mod_file_path(ModData.optional_mod_files.OVERWRITES)
80-
is_overwrite = _ModLoaderFile.file_exists(mod_overwrites_path)
80+
is_overwrite = _ModLoaderFile.file_exists(mod_overwrites_path, zip_path)
8181
is_locked = mod_id in ModLoaderStore.ml_options.locked_mods
8282

8383
# Get the mod file paths
@@ -243,7 +243,7 @@ func _has_manifest(mod_manifest: ModManifest) -> bool:
243243

244244

245245
# Converts enum indices [member required_mod_files] into their respective file paths
246-
func get_required_mod_file_path(required_file: int) -> String:
246+
func get_required_mod_file_path(required_file: required_mod_files) -> String:
247247
match required_file:
248248
required_mod_files.MOD_MAIN:
249249
return dir_path.path_join("mod_main.gd")
@@ -252,7 +252,7 @@ func get_required_mod_file_path(required_file: int) -> String:
252252
return ""
253253

254254

255-
func get_optional_mod_file_path(optional_file: int) -> String:
255+
func get_optional_mod_file_path(optional_file: optional_mod_files) -> String:
256256
match optional_file:
257257
optional_mod_files.OVERWRITES:
258258
return dir_path.path_join("overwrites.gd")

0 commit comments

Comments
 (0)