Fix mod cache issue where server wouldn't update the hash when it should

This commit is contained in:
MysterD 2022-06-06 19:34:44 -07:00
parent 3b626845e1
commit 29f3e8f1bf
3 changed files with 30 additions and 0 deletions

View file

@ -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);
}

View file

@ -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");

View file

@ -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);