From 53d02a112f60ee04b7906fcdbacba6148346022e Mon Sep 17 00:00:00 2001 From: Razor-Thert Date: Fri, 13 Mar 2026 21:11:08 -0500 Subject: [PATCH] fix mod storage on android this completely fixes the error that was preventing .sav files from loading --- src/pc/mods/mod_storage.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/pc/mods/mod_storage.cpp b/src/pc/mods/mod_storage.cpp index 8659a4a9f7..fbc92b0123 100644 --- a/src/pc/mods/mod_storage.cpp +++ b/src/pc/mods/mod_storage.cpp @@ -158,7 +158,9 @@ static mINI::INIStructure &mod_storage_read_file(const char *filename) { mINI::INIFile file(filename); mINI::INIStructure ini; + if (fs_sys_path_exists(filename)) { file.read(ini); + } sModStorageFiles[filename] = ini; return sModStorageFiles[filename]; } @@ -168,28 +170,18 @@ C_FIELD const char* mod_storage_load(const char* key) { if (!mod_storage_check_inputs(key, NULL, filename)) { return NULL; } +const mINI::INIStructure &ini = mod_storage_read_file(filename); +std::string str = ini.get("storage").get(key); +if (str.empty()) { return NULL; } +// save cache before read #ifdef __ANDROID__ - char *cached_value = NULL; - cached_value = key_cached(key, NULL); - if (cached_value) { - return cached_value; - } + cache_key(key, str.c_str()); #endif - const mINI::INIStructure &ini = mod_storage_read_file(filename); - std::string str = ini.get("storage").get(key); - if (str.empty()) { return NULL; } - - // Store string results in a temporary buffer - // this assumes mod_storage_load will only ever be called by Lua - static char value[MAX_KEY_VALUE_LENGTH]; - snprintf(value, MAX_KEY_VALUE_LENGTH, "%s", str.c_str()); - -#ifdef __ANDROID__ - cache_key(key, (char*)value); -#endif - return value; +static char value[MAX_KEY_VALUE_LENGTH]; +snprintf(value, MAX_KEY_VALUE_LENGTH, "%s", str.c_str()); +return value; } C_FIELD f32 mod_storage_load_number(const char* key) { @@ -316,3 +308,9 @@ C_FIELD void mod_storage_shutdown(void) { } sModStorageFiles.clear(); } + +C_FIELD void mod_storage_init(void) { +#ifdef __ANDROID__ + key_cache_init(); +#endif +}