[ServerCommands] Server command hooks added

This commit is contained in:
RektInator 2017-05-30 14:29:09 +02:00
parent 9f0dc1139d
commit dcb6c2b9e8
6 changed files with 134 additions and 0 deletions

View File

@ -95,6 +95,7 @@ namespace Components
Loader::Register(new AssetHandler());
Loader::Register(new Localization());
Loader::Register(new MusicalTalent());
Loader::Register(new ServerCommands());
Loader::Register(new StructuredData());
Loader::Register(new ConnectProtocol());
Loader::Register(new StartupMessages());

View File

@ -104,6 +104,7 @@ namespace Components
#include "Modules/AssetHandler.hpp"
#include "Modules/Localization.hpp"
#include "Modules/MusicalTalent.hpp"
#include "Modules/ServerCommands.hpp"
#include "Modules/StructuredData.hpp"
#include "Modules/ConnectProtocol.hpp"
#include "Modules/StartupMessages.hpp"

View File

@ -166,12 +166,45 @@ namespace Components
}
}
void CardTitles::ParseCustomTitles(char* msg)
{
char* playerTitle;
for (int i = 0; i < 18; i++)
{
playerTitle = msg; // nullptr; // (msg, std::to_string(i).c_str());
if (playerTitle != nullptr)
{
CustomTitles[i] = playerTitle;
}
else
{
CustomTitles[i] = "";
}
}
}
CardTitles::CardTitles()
{
Dvar::OnInit([]() {
CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("cardtitle", "", Game::dvar_flag::DVAR_FLAG_SAVED, "Custom card title");
});
ServerCommands::OnCommand(20, [](Command::Params* params) {
if (params->get(1) == "customTitles"s && !Flags::HasFlag("dedicated"))
{
if (params->length() == 3)
{
CardTitles::ParseCustomTitles(params->get(2));
return true;
}
}
return false;
});
CardTitles::CustomTitles.resize(18);
Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick();

View File

@ -60,6 +60,8 @@ namespace Components
public:
static Game::dvar_t* CustomTitleDvar;
static void ParseCustomTitles(char * msg);
CardTitles();
~CardTitles();

View File

@ -0,0 +1,79 @@
#include "STDInclude.hpp"
namespace Components
{
std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > ServerCommands::Commands;
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(&params);
}
}
}
return false;
}
void __declspec(naked) ServerCommands::OnServerCommandStub()
{
__asm
{
call OnServerCommand;
test al, al;
jnz jumpback;
push 0x5944AE;
retn;
jumpback:
push 0x594536;
retn;
}
}
/*void __declspec(naked) OnServerCommandPreFailStub()
{
static DWORD jmpAbove = 0x0059449F;
static DWORD jmpContinue = 0x00593C28;
__asm mov lastServerCommand, ecx;
if (lastServerCommand > 0x79)
__asm jmp jmpAbove;
else
__asm jmp jmpContinue;
}
void OnServerCommandFailPrint(int type, const char *trash, ...)
{
const char *cmd = "";
for (int i = 1; i < Cmd_Argc(); i++)
cmd = va("%s %s", cmd, Cmd_Argv(i));
Com_Printf(type, "Unknown client game command: %i %s\n", lastServerCommand, cmd);
}*/
ServerCommands::ServerCommands()
{
Utils::Hook(0x59449F, OnServerCommandStub).install()->quick();
}
ServerCommands::~ServerCommands()
{
}
}

View File

@ -0,0 +1,18 @@
#pragma once
namespace Components
{
class ServerCommands : public Component
{
public:
ServerCommands();
~ServerCommands();
static void OnCommand(std::int32_t cmd, std::function<bool(Command::Params*)> cb);
private:
static std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > Commands;
static bool OnServerCommand();
static void OnServerCommandStub();
};
}