diff --git a/docs/Core.rst b/docs/Core.rst index 62b91c19c..0e333702f 100644 --- a/docs/Core.rst +++ b/docs/Core.rst @@ -336,6 +336,11 @@ on UNIX-like systems: DFHACK_SOME_VAR=1 ./dfhack +- ``DFHACK_DISABLE``: if set, DFHack will not initialize, not even to redirect + :file:`stdout.txt` or :file:`stderr.txt`. This is provided as an alternative + to the ``--disable-dfhack`` commandline parameter above for when environment + variables are more convenient. + - ``DFHACK_PORT``: the port to use for the RPC server (used by ``dfhack-run`` and `remotefortressreader` among others) instead of the default ``5000``. As with the default, if this port cannot be used, the server is not started. diff --git a/library/Hooks.cpp b/library/Hooks.cpp index 1976d60d7..4e339e768 100644 --- a/library/Hooks.cpp +++ b/library/Hooks.cpp @@ -8,6 +8,13 @@ static bool disabled = false; // called from the main thread before the simulation thread is started // 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"); + disabled = true; + return; + } + + // we need to init DF globals before we can check the commandline if (!DFHack::Core::getInstance().InitMainThread() || !df::global::game) return; const std::string & cmdline = df::global::game->command_line.original;