diff --git a/src/pc/mods/mod.c b/src/pc/mods/mod.c index c475f077..54d401d6 100644 --- a/src/pc/mods/mod.c +++ b/src/pc/mods/mod.c @@ -127,6 +127,12 @@ void mod_activate(struct Mod* mod) { for (int i = 0; i < mod->fileCount; i++) { struct ModFile* file = &mod->files[i]; mod_cache_add(mod, file, false); + + // forcefully update md5 hash + if (gNetworkType == NT_SERVER) { + mod_cache_update(mod, file); + } + if (str_ends_with(file->relativePath, ".bin")) { mod_activate_bin(file); } diff --git a/src/pc/mods/mod_cache.c b/src/pc/mods/mod_cache.c index 8c1fd433..b270638c 100644 --- a/src/pc/mods/mod_cache.c +++ b/src/pc/mods/mod_cache.c @@ -221,6 +221,29 @@ void mod_cache_add(struct Mod* mod, struct ModFile* file, bool useFilePath) { mod_cache_add_internal(file->dataHash, 0, strdup(file->cachedPath)); } +void mod_cache_update(struct Mod* mod, struct ModFile* file) { + // sanity check + if (mod == NULL || file == NULL) { + LOG_ERROR("Could not add to cache, mod or file is null"); + return; + } + + // build the path + char modFilePath[SYS_MAX_PATH] = { 0 }; + if (!concat_path(modFilePath, mod->basePath, file->relativePath)) { + LOG_ERROR("Could not concat mod file path"); + return; + } + + // set path + normalize_path(modFilePath); + file->cachedPath = strdup(modFilePath); + + // hash and cache + mod_cache_md5(file->cachedPath, file->dataHash); + mod_cache_add_internal(file->dataHash, 0, strdup(file->cachedPath)); +} + void mod_cache_load(void) { mod_cache_shutdown(); LOG_INFO("Loading mod cache"); diff --git a/src/pc/mods/mod_cache.h b/src/pc/mods/mod_cache.h index ea9029a4..0e9acb5f 100644 --- a/src/pc/mods/mod_cache.h +++ b/src/pc/mods/mod_cache.h @@ -14,6 +14,7 @@ void mod_cache_shutdown(void); struct ModCacheEntry* mod_cache_get_from_hash(u8* dataHash); struct ModCacheEntry* mod_cache_get_from_path(const char* path, bool validate); void mod_cache_add(struct Mod* mod, struct ModFile* modFile, bool useFilePath); +void mod_cache_update(struct Mod* mod, struct ModFile* file); void mod_cache_load(void); void mod_cache_save(void);