diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index d40e2082..beb95f0b 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -410,7 +410,7 @@ namespace Components { cg_chatWidth = Dvar::Register("cg_chatWidth", 52, 1, std::numeric_limits::max(), Game::DVAR_ARCHIVE, "The normalized maximum width of a chat message"); sv_disableChat = Dvar::Register("sv_disableChat", false, Game::dvar_flag::DVAR_NONE, "Disable chat messages from clients"); - Scheduler::OnGameInitialized(AddChatCommands, Scheduler::Pipeline::SERVER); + Events::OnSVInit(AddChatCommands); // Intercept chat sending Utils::Hook(0x4D000B, PreSayStub, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index 7e9f58dd..0df8ec9c 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -98,9 +98,6 @@ namespace Components if (!Command::FunctionMapSV.contains(command)) { Command::AddRawSV(name, Command::MainCallbackSV); - - // If the main command is registered as Cbuf_AddServerText, the command will be redirected to the SV handler - Command::AddRaw(name, Game::Cbuf_AddServerText); } FunctionMapSV.insert_or_assign(command, callback); @@ -116,7 +113,7 @@ namespace Components Game::Cmd_AddServerCommand(name, callback, Command::Allocate()); // If the main command is registered as Cbuf_AddServerText, the command will be redirected to the SV handler - Command::AddRaw(name, Game::Cbuf_AddServerText); + Command::AddRaw(name, Game::Cbuf_AddServerText, false); } void Command::Execute(std::string command, bool sync) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 7d68e749..22f49aef 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -285,7 +285,7 @@ namespace Components Dvar::Register("sv_motd", "", Game::dvar_flag::DVAR_NONE, "A custom message of the day for servers"); }, Scheduler::Pipeline::MAIN); - Scheduler::OnGameInitialized(Dedicated::AddDedicatedCommands, Scheduler::Pipeline::SERVER); + Events::OnSVInit(Dedicated::AddDedicatedCommands); // Post initialization point Utils::Hook(0x60BFBF, Dedicated::PostInitializationStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/Events.cpp b/src/Components/Modules/Events.cpp index 5a940f2a..b73ef3a1 100644 --- a/src/Components/Modules/Events.cpp +++ b/src/Components/Modules/Events.cpp @@ -5,6 +5,7 @@ namespace Components Utils::Signal Events::ClientDisconnectSignal; Utils::Signal Events::SteamDisconnectSignal; Utils::Signal Events::ShutdownSystemSignal; + Utils::Signal Events::ServerInitSignal; void Events::OnClientDisconnect(const Utils::Slot& callback) { @@ -21,6 +22,11 @@ namespace Components ShutdownSystemSignal.connect(callback); } + void Events::OnSVInit(const Utils::Slot& callback) + { + ServerInitSignal.connect(callback); + } + /* * Should be called when a client drops from the server * but not "between levels" (Quake-III-Arena) @@ -46,6 +52,14 @@ namespace Components Utils::Hook::Call(0x421EE0)(sys); // Scr_ShutdownSystem } + void Events::SV_Init_Hk() + { + ServerInitSignal(); + ServerInitSignal.clear(); + + Utils::Hook::Call(0x474320)(); // SV_InitGameMode + } + Events::Events() { Utils::Hook(0x625235, ClientDisconnect_Hk, HOOK_CALL).install()->quick(); // SV_FreeClient @@ -54,5 +68,7 @@ namespace Components Utils::Hook(0x47548B, Scr_ShutdownSystem_Hk, HOOK_CALL).install()->quick(); // G_LoadGame Utils::Hook(0x4D06BA, Scr_ShutdownSystem_Hk, HOOK_CALL).install()->quick(); // G_ShutdownGame + + Utils::Hook(0x4D3665, SV_Init_Hk, HOOK_CALL).install()->quick(); // SV_Init } } diff --git a/src/Components/Modules/Events.hpp b/src/Components/Modules/Events.hpp index 8da45250..08a3675a 100644 --- a/src/Components/Modules/Events.hpp +++ b/src/Components/Modules/Events.hpp @@ -18,13 +18,18 @@ namespace Components static void OnVMShutdown(const Utils::Slot& callback); + // Client & Server (triggered once) + static void OnSVInit(const Utils::Slot& callback); + private: static Utils::Signal ClientDisconnectSignal; static Utils::Signal SteamDisconnectSignal; static Utils::Signal ShutdownSystemSignal; + static Utils::Signal ServerInitSignal; static void ClientDisconnect_Hk(int clientNum); static void SteamDisconnect_Hk(); static void Scr_ShutdownSystem_Hk(unsigned char sys); + static void SV_Init_Hk(); }; } diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 34c9c0b4..9d9ecf89 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -379,7 +379,7 @@ namespace Components Utils::Hook(Game::Com_Printf, Logger::PrintStub, HOOK_JUMP).install()->quick(); } - Scheduler::OnGameInitialized(Logger::AddServerCommands, Scheduler::Pipeline::SERVER); + Events::OnSVInit(Logger::AddServerCommands); } Logger::~Logger()