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

74 lines
1.2 KiB
C++
Raw Normal View History

2022-02-27 07:53:44 -05:00
#include <STDInclude.hpp>
#include "ServerCommands.hpp"
namespace Components
{
std::unordered_map<std::int32_t, ServerCommands::serverCommandHandler> ServerCommands::Commands;
void ServerCommands::OnCommand(std::int32_t cmd, const serverCommandHandler& callback)
{
Commands.insert_or_assign(cmd, callback);
}
bool ServerCommands::OnServerCommand()
{
2022-03-17 14:50:20 -04:00
Command::ClientParams params;
for (const auto& [id, callback] : Commands)
{
2022-03-17 14:50:20 -04:00
if (params.size() >= 1)
{
2022-04-12 08:34:51 -04:00
if (params.get(0)[0] == id) // Compare ID of server command
{
2022-04-12 08:34:51 -04:00
return callback(&params);
}
}
}
return false;
}
2022-04-12 08:34:51 -04:00
__declspec(naked) void ServerCommands::CG_DeployServerCommand_Stub()
{
__asm
{
push eax
pushad
// Missing localClientNum!
call ServerCommands::OnServerCommand
mov [esp + 20h], eax
popad
pop eax
test al, al
jnz jumpback
test eax, eax
jle error
2022-04-12 08:34:51 -04:00
mov eax, dword ptr [edx * 4 + 1AAC634h]
mov eax, [eax]
push 5944B3h
retn
error:
push 5944AEh
retn
jumpback:
push 594536h
retn
}
}
ServerCommands::ServerCommands()
{
// Server command receive hook
Utils::Hook(0x59449F, CG_DeployServerCommand_Stub).install()->quick();
Utils::Hook::Nop(0x5944A4, 6);
}
}