Skip to content

Commit

Permalink
add more instrumentation to hooks init
Browse files Browse the repository at this point in the history
and disable DFHack if core init fails
  • Loading branch information
myk002 committed Dec 9, 2024
1 parent 60db26d commit 9ed2926
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions library/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ DFhackCExport const int32_t dfhooks_priority = 100;
// and the main event loop is initiated
DFhackCExport void dfhooks_init() {
if (getenv("DFHACK_DISABLE")) {
fprintf(stdout, "dfhack: DFHACK_DISABLE detected in environment; disabling\n");
fprintf(stderr, "dfhack: DFHACK_DISABLE detected in environment; disabling\n");
disabled = true;
return;
}

// we need to init DF globals before we can check the commandline
if (!DFHack::Core::getInstance().InitMainThread() || !df::global::game)
if (!DFHack::Core::getInstance().InitMainThread() || !df::global::game) {
disabled = true;
return;
}

const std::string & cmdline = df::global::game->command_line.original;
if (cmdline.find("--disable-dfhack") != std::string::npos) {
fprintf(stdout, "dfhack: --disable-dfhack specified on commandline; disabling\n");
fprintf(stderr, "dfhack: --disable-dfhack specified on commandline; disabling\n");
disabled = true;
return;
}

fprintf(stderr, "DFHack pre-init successful.\n");
}

// called from the main thread after the main event loops exits
Expand Down

0 comments on commit 9ed2926

Please sign in to comment.