Merge pull request #339 from diamante0018/sv_init_fix

[Command] Have SV commands register sooner
This commit is contained in:
Dss0 2022-06-28 22:05:08 +02:00 committed by GitHub
commit 7f8bf48c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 7 deletions

View File

@ -410,7 +410,7 @@ namespace Components
{
cg_chatWidth = Dvar::Register<int>("cg_chatWidth", 52, 1, std::numeric_limits<int>::max(), Game::DVAR_ARCHIVE, "The normalized maximum width of a chat message");
sv_disableChat = Dvar::Register<bool>("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();

View File

@ -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)

View File

@ -285,7 +285,7 @@ namespace Components
Dvar::Register<const char*>("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();

View File

@ -5,6 +5,7 @@ namespace Components
Utils::Signal<Events::ClientCallback> Events::ClientDisconnectSignal;
Utils::Signal<Events::Callback> Events::SteamDisconnectSignal;
Utils::Signal<Events::Callback> Events::ShutdownSystemSignal;
Utils::Signal<Events::Callback> Events::ServerInitSignal;
void Events::OnClientDisconnect(const Utils::Slot<ClientCallback>& callback)
{
@ -21,6 +22,11 @@ namespace Components
ShutdownSystemSignal.connect(callback);
}
void Events::OnSVInit(const Utils::Slot<Callback>& 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<void(unsigned char)>(0x421EE0)(sys); // Scr_ShutdownSystem
}
void Events::SV_Init_Hk()
{
ServerInitSignal();
ServerInitSignal.clear();
Utils::Hook::Call<void()>(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
}
}

View File

@ -18,13 +18,18 @@ namespace Components
static void OnVMShutdown(const Utils::Slot<Callback>& callback);
// Client & Server (triggered once)
static void OnSVInit(const Utils::Slot<Callback>& callback);
private:
static Utils::Signal<ClientCallback> ClientDisconnectSignal;
static Utils::Signal<Callback> SteamDisconnectSignal;
static Utils::Signal<Callback> ShutdownSystemSignal;
static Utils::Signal<Callback> ServerInitSignal;
static void ClientDisconnect_Hk(int clientNum);
static void SteamDisconnect_Hk();
static void Scr_ShutdownSystem_Hk(unsigned char sys);
static void SV_Init_Hk();
};
}

View File

@ -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()