iw4x-client/src/Components/Modules/ServerCommands.cpp

107 lines
2.0 KiB
C++
Raw Normal View History

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