Skip to content

Commit d8973b2

Browse files
authored
Honor ignore_disable_switch for inherited DOORSTOP_INITIALIZED (#109)
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.
1 parent 0bb8912 commit d8973b2

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎src/bootstrap.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@
1010

1111
bool_t mono_debug_init_called = FALSE;
1212
bool_t mono_is_net35 = FALSE;
13+
static bool_t doorstop_bootstrapped = FALSE;
1314

1415
void mono_doorstop_bootstrap(void *mono_domain) {
15-
if (getenv(TEXT("DOORSTOP_INITIALIZED"))) {
16+
if (doorstop_bootstrapped) {
17+
LOG("Doorstop already bootstrapped in this process, skipping!");
18+
return;
19+
}
20+
// Steam (and other launchers) can leak DOORSTOP_INITIALIZED into a new
21+
// game process, the same env-isolation issue ignore_disable_switch already
22+
// covers for DOORSTOP_DISABLE. Honor that switch here; use the static flag
23+
// above for genuine in-process re-entry.
24+
if (getenv(TEXT("DOORSTOP_INITIALIZED")) && !config.ignore_disabled_env) {
1625
LOG("DOORSTOP_INITIALIZED is set! Skipping!");
1726
return;
1827
}
28+
doorstop_bootstrapped = TRUE;
1929
setenv(TEXT("DOORSTOP_INITIALIZED"), TEXT("TRUE"), TRUE);
2030

2131
mono.thread_set_main(mono.thread_current());

‎src/nix/entrypoint.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ static bool_t main_module_is_unity_player(void) {
139139
__attribute__((constructor)) void doorstop_ctor() {
140140
init_logger();
141141
load_config();
142+
if (config.ignore_disabled_env) {
143+
unsetenv("DOORSTOP_INITIALIZED");
144+
unsetenv("DOORSTOP_DISABLE");
145+
LOG("Cleared inherited DOORSTOP_INITIALIZED / DOORSTOP_DISABLE");
146+
}
142147

143148
if (!config.enabled) {
144149
LOG("Doorstop not enabled! Skipping!");

‎src/windows/entrypoint.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ BOOL WINAPI DllEntry(HINSTANCE hInstDll, DWORD reasonForDllLoad,
284284

285285
load_config();
286286
LOG("Config loaded");
287+
if (config.ignore_disabled_env) {
288+
SetEnvironmentVariableW(L"DOORSTOP_INITIALIZED", NULL);
289+
SetEnvironmentVariableW(L"DOORSTOP_DISABLE", NULL);
290+
LOG("Cleared inherited DOORSTOP_INITIALIZED / DOORSTOP_DISABLE");
291+
}
287292

288293
redirect_output_log(paths);
289294

0 commit comments

Comments
 (0)