diff --git a/src/hooks/Shutdown.cpp b/src/hooks/Shutdown.cpp index 70b80a42..2ab9e39e 100644 --- a/src/hooks/Shutdown.cpp +++ b/src/hooks/Shutdown.cpp @@ -19,6 +19,8 @@ extern std::string name_forced; namespace hooked_methods { +static TextFile randomnames_file; + DEFINE_HOOKED_METHOD(Shutdown, void, INetChannel *this_, const char *reason) { g_Settings.bInvalid = true; @@ -51,13 +53,30 @@ DEFINE_HOOKED_METHOD(Shutdown, void, INetChannel *this_, const char *reason) votelogger::onShutdown(message); if (*random_name) { - static TextFile file; - if (file.TryLoad("names.txt")) + if (randomnames_file.TryLoad("names.txt")) { - name_forced = file.lines.at(rand() % file.lines.size()); + name_forced = randomnames_file.lines.at(rand() % randomnames_file.lines.size()); } } else name_forced = ""; } + +static InitRoutine init( + []() + { + random_name.installChangeCallback( + [](settings::VariableBase &, bool after) + { + if (after) + { + if (randomnames_file.TryLoad("names.txt")) + { + name_forced = randomnames_file.lines.at(rand() % randomnames_file.lines.size()); + } + } + else + name_forced = ""; + }); + }); } // namespace hooked_methods