mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-22 10:01:46 +00:00
Yet another mod cache fix
This commit is contained in:
parent
ad9e8995d7
commit
d08507edbb
5 changed files with 40 additions and 16 deletions
|
|
@ -107,7 +107,7 @@ void smlua_audio_utils_replace_sequence(u8 sequenceId, u8 bankId, u8 defaultVolu
|
|||
|
||||
for (s32 i = 0; i < gLuaActiveMod->fileCount; i++) {
|
||||
struct ModFile* file = &gLuaActiveMod->files[i];
|
||||
if (!strcmp(file->relativePath, m64path)) {
|
||||
if (str_ends_with(file->cachedPath, m64path)) {
|
||||
struct AudioOverride* override = &sAudioOverrides[sequenceId];
|
||||
smlua_audio_utils_reset(override);
|
||||
LOG_INFO("Loading audio: %s", file->cachedPath);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include "pc/utils/md5.h"
|
||||
|
||||
#define MOD_CACHE_FILENAME "mod.cache"
|
||||
#define MOD_CACHE_VERSION 4
|
||||
#define MOD_CACHE_VERSION 5
|
||||
#define MD5_BUFFER_SIZE 1024
|
||||
|
||||
struct ModCacheEntry* sModCacheHead = NULL;
|
||||
|
|
@ -138,17 +138,9 @@ void mod_cache_add(struct Mod* mod, struct ModFile* file) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (modFilePath[0] == '.' && (modFilePath[1] == '/' || modFilePath[1] == '\\')) {
|
||||
char modAbsFilePath[SYS_MAX_PATH] = { 0 };
|
||||
getcwd(modAbsFilePath, SYS_MAX_PATH-1);
|
||||
strncat(modAbsFilePath, "/", SYS_MAX_PATH-1);
|
||||
strncat(modAbsFilePath, modFilePath, SYS_MAX_PATH-1);
|
||||
normalize_path(modAbsFilePath);
|
||||
file->cachedPath = strdup(modAbsFilePath);
|
||||
} else {
|
||||
normalize_path(modFilePath);
|
||||
file->cachedPath = strdup(modFilePath);
|
||||
}
|
||||
// set path
|
||||
normalize_path(modFilePath);
|
||||
file->cachedPath = strdup(modFilePath);
|
||||
|
||||
// hash and cache
|
||||
mod_cache_md5(file->cachedPath, file->dataHash);
|
||||
|
|
|
|||
|
|
@ -156,10 +156,12 @@ void mods_init(void) {
|
|||
|
||||
// load mods
|
||||
if (hasUserPath) { mods_load(&gLocalMods, userModPath); }
|
||||
|
||||
const char* exePath = path_to_executable();
|
||||
char defaultModsPath[SYS_MAX_PATH] = { 0 };
|
||||
if (snprintf(defaultModsPath, SYS_MAX_PATH - 1, "%s", "./" MOD_DIRECTORY) >= 0) {
|
||||
mods_load(&gLocalMods, defaultModsPath);
|
||||
}
|
||||
path_get_folder((char*)exePath, defaultModsPath);
|
||||
strncat(defaultModsPath, MOD_DIRECTORY, SYS_MAX_PATH-1);
|
||||
mods_load(&gLocalMods, defaultModsPath);
|
||||
|
||||
// calculate total size
|
||||
gLocalMods.size = 0;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,13 @@
|
|||
#include "mods_utils.h"
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
#include <winuser.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void mods_size_enforce(struct Mods* mods) {
|
||||
for (int i = 0; i < mods->entryCount; i++) {
|
||||
struct Mod* mod = mods->entries[i];
|
||||
|
|
@ -156,6 +163,28 @@ char* extract_lua_field(char* fieldName, char* buffer) {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const char* path_to_executable(void) {
|
||||
static char exePath[SYS_MAX_PATH] = { 0 };
|
||||
if (exePath[0] != '\0') { return exePath; }
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
HMODULE hModule = GetModuleHandle(NULL);
|
||||
if (hModule == NULL) {
|
||||
LOG_ERROR("unable to retrieve absolute exe path!");
|
||||
return NULL;
|
||||
}
|
||||
GetModuleFileName(hModule, exePath, SYS_MAX_PATH-1);
|
||||
#else
|
||||
snprintf(exePath, MAX_LAUNCH_CMD - 1, "/proc/%d/exe", getpid());
|
||||
rc = readlink(exePath, cmd, MAX_LAUNCH_CMD - 1);
|
||||
if (rc <= 0) {
|
||||
LOG_ERROR("unable to retrieve absolute exe path!");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return exePath;
|
||||
}
|
||||
|
||||
bool path_is_portable_filename(char* string) {
|
||||
char* s = string;
|
||||
while (*s != '\0') {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ bool str_ends_with(char* string, char* suffix);
|
|||
|
||||
char* extract_lua_field(char* fieldName, char* buffer);
|
||||
|
||||
const char* path_to_executable(void);
|
||||
bool path_is_portable_filename(char* string);
|
||||
bool path_exists(char* path);
|
||||
bool is_directory(char* path);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue