From 97792e8ace36116eb711f095672242ef352c780e Mon Sep 17 00:00:00 2001 From: mohui666 Date: Fri, 14 Aug 2026 16:38:23 +0800 Subject: [PATCH] Honor ignore_disable_switch for inherited DOORSTOP_INITIALIZED Steam and self-restarts leak DOORSTOP_INITIALIZED into the new process. Doorstop then skips Mono bootstrap even when ignore_disable_switch is set, so BepInEx never reaches Doorstop.Entrypoint.Start. Clear the inherited flags after config load, and use a process-local flag for genuine in-process re-entry. Fixes the Steam/Windows case seen with Unity Mono titles (e.g. Legend of Mortal) and the restart path in #73. --- src/bootstrap.c | 12 +++++++++++- src/nix/entrypoint.c | 5 +++++ src/windows/entrypoint.c | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bootstrap.c b/src/bootstrap.c index ed38f71..df3a35e 100644 --- a/src/bootstrap.c +++ b/src/bootstrap.c @@ -10,12 +10,22 @@ bool_t mono_debug_init_called = FALSE; bool_t mono_is_net35 = FALSE; +static bool_t doorstop_bootstrapped = FALSE; void mono_doorstop_bootstrap(void *mono_domain) { - if (getenv(TEXT("DOORSTOP_INITIALIZED"))) { + if (doorstop_bootstrapped) { + LOG("Doorstop already bootstrapped in this process, skipping!"); + return; + } + // Steam (and other launchers) can leak DOORSTOP_INITIALIZED into a new + // game process, the same env-isolation issue ignore_disable_switch already + // covers for DOORSTOP_DISABLE. Honor that switch here; use the static flag + // above for genuine in-process re-entry. + if (getenv(TEXT("DOORSTOP_INITIALIZED")) && !config.ignore_disabled_env) { LOG("DOORSTOP_INITIALIZED is set! Skipping!"); return; } + doorstop_bootstrapped = TRUE; setenv(TEXT("DOORSTOP_INITIALIZED"), TEXT("TRUE"), TRUE); mono.thread_set_main(mono.thread_current()); diff --git a/src/nix/entrypoint.c b/src/nix/entrypoint.c index 457e11d..aa2950b 100644 --- a/src/nix/entrypoint.c +++ b/src/nix/entrypoint.c @@ -95,6 +95,11 @@ int dup2_hook(int od, int nd) { __attribute__((constructor)) void doorstop_ctor() { init_logger(); load_config(); + if (config.ignore_disabled_env) { + unsetenv("DOORSTOP_INITIALIZED"); + unsetenv("DOORSTOP_DISABLE"); + LOG("Cleared inherited DOORSTOP_INITIALIZED / DOORSTOP_DISABLE"); + } if (!config.enabled) { LOG("Doorstop not enabled! Skipping!"); diff --git a/src/windows/entrypoint.c b/src/windows/entrypoint.c index 7de774b..663a477 100644 --- a/src/windows/entrypoint.c +++ b/src/windows/entrypoint.c @@ -284,6 +284,11 @@ BOOL WINAPI DllEntry(HINSTANCE hInstDll, DWORD reasonForDllLoad, load_config(); LOG("Config loaded"); + if (config.ignore_disabled_env) { + SetEnvironmentVariableW(L"DOORSTOP_INITIALIZED", NULL); + SetEnvironmentVariableW(L"DOORSTOP_DISABLE", NULL); + LOG("Cleared inherited DOORSTOP_INITIALIZED / DOORSTOP_DISABLE"); + } redirect_output_log(paths);