18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-14 13:25:56 +01:00

fix(simulation): the test mode gives nothing to the outside and leaves the player's files alone

The test mode turned off what comes in from outside, but a few settings
of the user's eu07.ini still reached out of a test run:

- feedbackmode: 1 and 2 toggle Caps Lock / Scroll Lock by injecting key
  events into the whole system, 3 and 4 drive an LPT port or a PoKeys
  desk (and 4 reads the desk's switches);
- multiplayer: events are reported to a multiplayer server, and some
  events are held back for it;
- execonexit: a program is run with system() at the end of each run,
  which also waits for it;
- showsystemconsole: a console of the run's own pops up and stdout is
  reopened on it, so whoever started the test with a redirected output
  doesn't get the `test:` line (and a console the run was started from
  would be hidden without it);
- imgui.ini in the game folder was written by every run, and by several
  at once with run.py -j.

All of these are off in test mode. Nothing changes outside it.
This commit is contained in:
jerrrrycho
2026-11-08 09:36:51 +01:00
parent ced4e06b35
commit 93e2b85d08
2 changed files with 23 additions and 0 deletions

View File

@@ -31,6 +31,9 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/dictionary.h"
#include "version_info.h"
#include "simulation/simulationtest.h"
#ifdef _WIN32
#include "Console.h"
#endif
#include <algorithm>
#include <charconv>
#include <chrono>
@@ -1048,6 +1051,13 @@ void eu07_application::init_debug()
void eu07_application::init_console()
{
#ifdef _WIN32
if (Global.test.enabled)
{
// a test is started by whoever waits for its result, often reading its output: no console of its own
// (showsystemconsole) pops up and takes stdout away from them, and a console it was started from isn't hidden
return;
}
HWND consoleWnd = ::GetConsoleWindow();
const bool hadConsole = consoleWnd != nullptr;
@@ -1176,6 +1186,14 @@ void apply_test_mode_settings()
#ifdef WITH_ZMQ
Global.zmq_address.clear();
#endif
// nor anything to the outside: no keyboard leds, LPT or PoKeys desk (feedbackmode), no messages to a
// multiplayer server (multiplayer, which also holds some events back for it), no program run at the end
Global.iFeedbackMode = 0;
#ifdef _WIN32
Console::ModeSet(Global.iFeedbackMode, Global.iFeedbackPort);
#endif
Global.iMultiplayer = 0;
Global.exec_on_exit.clear();
// and the same way every time, unless given another seed (-seed, or randomseed in the settings)
if (!Global.random_seed)
Global.random_seed = seed_of("test");