From f1b22ee02568779b1ea23c944936eadf9bd6f76c Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Thu, 3 Jul 2025 16:28:45 -0700 Subject: [PATCH] Allow Web port to be playable in Firefox Private (#513) --- ISLE/emscripten/emscripten.patch | 18 ++++++++++++++++++ ISLE/emscripten/filesystem.cpp | 17 +++++++++++++---- ISLE/emscripten/filesystem.h | 2 +- ISLE/isleapp.cpp | 11 +++++++---- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ISLE/emscripten/emscripten.patch b/ISLE/emscripten/emscripten.patch index 899d72eb..0bc8222d 100644 --- a/ISLE/emscripten/emscripten.patch +++ b/ISLE/emscripten/emscripten.patch @@ -139,3 +139,21 @@ index e8c9f7e21..caf1971d2 100644 }, - }); +diff --git a/src/preamble.js b/src/preamble.js +index 572694517..0d2f4421b 100644 +--- a/src/preamble.js ++++ b/src/preamble.js +@@ -1062,3 +1062,13 @@ function getCompilerSetting(name) { + // dynamic linker as symbols are loaded. + var asyncifyStubs = {}; + #endif ++ ++(async () => { ++ try { ++ await navigator.storage.getDirectory(); ++ Module["disableOpfs"] = false; ++ } catch (e) { ++ Module["disableOpfs"] = true; ++ } ++})(); ++ diff --git a/ISLE/emscripten/filesystem.cpp b/ISLE/emscripten/filesystem.cpp index 395242a1..50cd9012 100644 --- a/ISLE/emscripten/filesystem.cpp +++ b/ISLE/emscripten/filesystem.cpp @@ -6,6 +6,7 @@ #include #include +#include #include static backend_t opfs = nullptr; @@ -13,10 +14,16 @@ static backend_t fetchfs = nullptr; extern const char* g_files[46]; -void Emscripten_SetupConfig(const char* p_iniConfig) +bool Emscripten_OPFSDisabled() { - if (!p_iniConfig || !*p_iniConfig) { - return; + return MAIN_THREAD_EM_ASM_INT({return !!Module["disableOpfs"]}); +} + +bool Emscripten_SetupConfig(const char* p_iniConfig) +{ + if (Emscripten_OPFSDisabled()) { + SDL_Log("OPFS is disabled; ignoring .ini path"); + return false; } opfs = wasmfs_create_opfs_backend(); @@ -28,6 +35,8 @@ void Emscripten_SetupConfig(const char* p_iniConfig) wasmfs_create_directory(iniConfig.GetData(), 0644, opfs); *parse = '/'; } + + return true; } void Emscripten_SetupFilesystem() @@ -66,7 +75,7 @@ void Emscripten_SetupFilesystem() registerFile(file); } - if (GameState()->GetSavePath() && *GameState()->GetSavePath()) { + if (GameState()->GetSavePath() && *GameState()->GetSavePath() && !Emscripten_OPFSDisabled()) { if (!opfs) { opfs = wasmfs_create_opfs_backend(); } diff --git a/ISLE/emscripten/filesystem.h b/ISLE/emscripten/filesystem.h index 131df1c8..ad78a349 100644 --- a/ISLE/emscripten/filesystem.h +++ b/ISLE/emscripten/filesystem.h @@ -10,7 +10,7 @@ inline static const char* Emscripten_savePath = "/save"; inline static const char* Emscripten_streamPath = "/"; inline static const char* Emscripten_streamHost = ISLE_EMSCRIPTEN_HOST; -void Emscripten_SetupConfig(const char* p_iniConfig); +bool Emscripten_SetupConfig(const char* p_iniConfig); void Emscripten_SetupFilesystem(); #endif // EMSCRIPTEN_FILESYSTEM_H diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index cfa3c50a..2e2066d8 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -778,6 +778,13 @@ bool IsleApp::LoadConfig() { char* prefPath = SDL_GetPrefPath("isledecomp", "isle"); char* iniConfig; + +#ifdef __EMSCRIPTEN__ + if (m_iniPath && !Emscripten_SetupConfig(m_iniPath)) { + m_iniPath = NULL; + } +#endif + if (m_iniPath) { iniConfig = new char[strlen(m_iniPath) + 1]; strcpy(iniConfig, m_iniPath); @@ -793,10 +800,6 @@ bool IsleApp::LoadConfig() } SDL_Log("Reading configuration from \"%s\"", iniConfig); -#ifdef __EMSCRIPTEN__ - Emscripten_SetupConfig(iniConfig); -#endif - dictionary* dict = iniparser_load(iniConfig); // [library:config]