2017-05-30 08:29:09 -04:00
|
|
|
#include "STDInclude.hpp"
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > ServerCommands::Commands;
|
2017-05-30 09:37:50 -04:00
|
|
|
std::uint32_t ServerCommands::lastServerCommand;
|
2017-05-30 08:29:09 -04:00
|
|
|
|
|
|
|
void ServerCommands::OnCommand(std::int32_t cmd, std::function < bool(Command::Params*) > cb)
|
|
|
|
{
|
|
|
|
Commands[cmd] = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ServerCommands::OnServerCommand()
|
|
|
|
{
|
|
|
|
Command::ClientParams params(*Game::cmd_id);
|
|
|
|
|
|
|
|
for (auto &ServerCommandCB : Commands)
|
|
|
|
{
|
|
|
|
if (params.length() >= 1)
|
|
|
|
{
|
|
|
|
if (params.get(0)[0] == ServerCommandCB.first)
|
|
|
|
{
|
|
|
|
return ServerCommandCB.second(¶ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __declspec(naked) ServerCommands::OnServerCommandStub()
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
call OnServerCommand;
|
|
|
|
test al, al;
|
|
|
|
jnz jumpback;
|
|
|
|
|
2017-05-30 12:38:54 -04:00
|
|
|
push 5944AEh;
|
2017-05-30 08:29:09 -04:00
|
|
|
retn;
|
|
|
|
|
|
|
|
jumpback:
|
2017-05-30 12:38:54 -04:00
|
|
|
push 594536h;
|
2017-05-30 08:29:09 -04:00
|
|
|
retn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 09:37:50 -04:00
|
|
|
void __declspec(naked) ServerCommands::OnServerCommandPreFailStub()
|
2017-05-30 08:29:09 -04:00
|
|
|
{
|
2017-05-30 09:37:50 -04:00
|
|
|
__asm
|
|
|
|
{
|
|
|
|
mov lastServerCommand, ecx;
|
2017-05-30 12:38:54 -04:00
|
|
|
cmp ecx, 79h;
|
2017-05-30 08:29:09 -04:00
|
|
|
|
2017-05-30 09:37:50 -04:00
|
|
|
jl above;
|
2017-05-30 08:29:09 -04:00
|
|
|
|
2017-05-30 12:38:54 -04:00
|
|
|
push 59449Fh;
|
2017-05-30 09:37:50 -04:00
|
|
|
retn;
|
|
|
|
|
|
|
|
above:
|
2017-05-30 12:38:54 -04:00
|
|
|
push 593C28h;
|
2017-05-30 09:37:50 -04:00
|
|
|
retn;
|
|
|
|
}
|
2017-05-30 08:29:09 -04:00
|
|
|
}
|
|
|
|
|
2017-05-30 09:58:39 -04:00
|
|
|
void ServerCommands::OnServerCommandFailPrint(int type, const char *, ...)
|
2017-05-30 08:29:09 -04:00
|
|
|
{
|
2017-05-30 09:37:50 -04:00
|
|
|
Command::ClientParams params(*Game::cmd_id);
|
2017-05-30 08:29:09 -04:00
|
|
|
const char *cmd = "";
|
|
|
|
|
2017-05-30 09:58:39 -04:00
|
|
|
for (std::size_t i = 1; i < params.length(); i++)
|
2017-05-30 09:37:50 -04:00
|
|
|
cmd = Utils::String::VA("%s %s", cmd, params.get(i));
|
2017-05-30 08:29:09 -04:00
|
|
|
|
2017-05-30 09:37:50 -04:00
|
|
|
Game::Com_Printf(type, "Unknown client game command: %i %s\n", lastServerCommand, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __declspec(naked) ServerCommands::OnServerCommandFailPrintStub()
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
2017-05-30 12:38:54 -04:00
|
|
|
pushad;
|
2017-05-30 09:37:50 -04:00
|
|
|
call OnServerCommandFailPrint;
|
2017-05-30 12:38:54 -04:00
|
|
|
popad;
|
2017-05-30 09:37:50 -04:00
|
|
|
|
2017-05-30 12:38:54 -04:00
|
|
|
push 5944C0h;
|
2017-05-30 09:37:50 -04:00
|
|
|
retn;
|
|
|
|
}
|
|
|
|
}
|
2017-05-30 08:29:09 -04:00
|
|
|
|
|
|
|
ServerCommands::ServerCommands()
|
|
|
|
{
|
2017-05-30 09:37:50 -04:00
|
|
|
// Server command receive hook
|
2017-05-30 08:29:09 -04:00
|
|
|
Utils::Hook(0x59449F, OnServerCommandStub).install()->quick();
|
2017-05-30 09:37:50 -04:00
|
|
|
|
|
|
|
// Server command fail hooks
|
|
|
|
Utils::Hook(0x593C1F, OnServerCommandPreFailStub).install()->quick();
|
|
|
|
Utils::Hook(0x5944BB, OnServerCommandFailPrintStub).install()->quick();
|
|
|
|
Utils::Hook::Set(0x5944D3, 0xEB);
|
2017-05-30 08:29:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ServerCommands::~ServerCommands()
|
|
|
|
{
|
2017-05-30 12:38:54 -04:00
|
|
|
Commands.clear();
|
2017-05-30 08:29:09 -04:00
|
|
|
}
|
|
|
|
}
|