[Chat] Move chat commands here (#462)

* [Chat] Move chat commands here

* [General] Rename Cbuf_AddServerText to Cbuf_AddServerText_f
This commit is contained in:
Edo 2022-08-27 23:19:09 +02:00 committed by GitHub
parent 78e495f9f2
commit def50477fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 79 additions and 78 deletions

View File

@ -5,6 +5,7 @@ namespace Components
{
Dvar::Var Chat::cg_chatWidth;
Dvar::Var Chat::sv_disableChat;
Dvar::Var Chat::sv_sayName;
Game::dvar_t** Chat::cg_chatHeight = reinterpret_cast<Game::dvar_t**>(0x7ED398);
Game::dvar_t** Chat::cg_chatTime = reinterpret_cast<Game::dvar_t**>(0x9F5DE8);
@ -341,6 +342,66 @@ namespace Components
UnmuteInternal(steamId);
}
});
Command::AddSV("say", [](Command::Params* params)
{
if (params->size() < 2) return;
auto message = params->join(1);
auto name = sv_sayName.get<std::string>();
if (!name.empty())
{
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 0x68, name.data(), message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "{}: {}\n", name, message);
}
else
{
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 0x68, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Console: {}\n", message);
}
});
Command::AddSV("tell", [](Command::Params* params)
{
if (params->size() < 3) return;
const auto client = std::atoi(params->get(1));
auto message = params->join(2);
auto name = sv_sayName.get<std::string>();
if (!name.empty())
{
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 0x68, name.data(), message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, client, message);
}
else
{
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", client, message);
}
});
Command::AddSV("sayraw", [](Command::Params* params)
{
if (params->size() < 2) return;
auto message = params->join(1);
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x68, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message);
});
Command::AddSV("tellraw", [](Command::Params* params)
{
if (params->size() < 3) return;
const auto client = atoi(params->get(1));
std::string message = params->join(2);
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 0x68, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", client, message);
});
sv_sayName = Dvar::Register<const char*>("sv_sayName", "^7Console", Game::DVAR_NONE, "The alias of the server when broadcasting a chat message");
}
int Chat::GetCallbackReturn()

View File

@ -11,6 +11,7 @@ namespace Components
private:
static Dvar::Var cg_chatWidth;
static Dvar::Var sv_disableChat;
static Dvar::Var sv_sayName;
// Game dvars
static Game::dvar_t** cg_chatHeight;

View File

@ -113,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, false);
Command::AddRaw(name, Game::Cbuf_AddServerText_f, false);
}
void Command::Execute(std::string command, bool sync)

View File

@ -261,7 +261,12 @@ namespace Components
void Debug::Com_Assert_f()
{
assert(("a", false));
assert(0 && "a");
}
void Debug::Cbuf_AddServerText_f_Hk()
{
assert(0 && "Cbuf_AddServerText_f was called.");
}
void Debug::Com_Bug_f(Command::Params* params)
@ -336,6 +341,7 @@ namespace Components
Utils::Hook(0x49CB0A, CG_DrawDebugOverlays_Hk, HOOK_JUMP).install()->quick();
Utils::Hook::Set<void(*)()>(0x60BCEA, Com_Assert_f);
Utils::Hook(Game::Cbuf_AddServerText_f, Cbuf_AddServerText_f_Hk, HOOK_JUMP).install()->quick();
#ifdef _DEBUG
Command::Add("bug", Com_Bug_f);

View File

@ -42,6 +42,7 @@ namespace Components
static void CG_DrawDebugOverlays_Hk(int localClientNum);
static void Com_Assert_f();
static void Cbuf_AddServerText_f_Hk();
static void Com_Bug_f(Command::Params* params);
static void CL_InitDebugDvars();

View File

@ -138,71 +138,6 @@ namespace Components
return Game::Dvar_RegisterInt(dvarName, 1000, min, 1000, Game::DVAR_NONE, description);
}
void Dedicated::AddDedicatedCommands()
{
// Say command
Command::AddSV("say", [](Command::Params* params)
{
if (params->size() < 2) return;
auto message = params->join(1);
auto name = Dvar::Var("sv_sayName").get<std::string>();
if (!name.empty())
{
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "{}: {}\n", name, message);
}
else
{
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Console: {}\n", message);
}
});
// Tell command
Command::AddSV("tell", [](Command::Params* params)
{
if (params->size() < 3) return;
const auto client = atoi(params->get(1));
auto message = params->join(2);
auto name = Dvar::Var("sv_sayName").get<std::string>();
if (!name.empty())
{
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s: %s\"", 104, name.data(), message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, client, message);
}
else
{
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Console: %s\"", 104, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", client, message);
}
});
// Sayraw command
Command::AddSV("sayraw", [](Command::Params* params)
{
if (params->size() < 2) return;
auto message = params->join(1);
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message);
});
// Tellraw command
Command::AddSV("tellraw", [](Command::Params* params)
{
if (params->size() < 3) return;
const auto client = atoi(params->get(1));
std::string message = params->join(2);
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"%s\"", 104, message.data()));
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", client, message);
});
}
Dedicated::Dedicated()
{
Dedicated::COMLogFilter = Dvar::Register<bool>("com_logFilter", true,
@ -281,12 +216,9 @@ namespace Components
{
Scheduler::Once([]
{
Dvar::Register<const char*>("sv_sayName", "^7Console", Game::DVAR_NONE, "The name to pose as for 'say' commands");
Dvar::Register<const char*>("sv_motd", "", Game::DVAR_NONE, "A custom message of the day for servers");
}, Scheduler::Pipeline::MAIN);
Events::OnSVInit(Dedicated::AddDedicatedCommands);
// Post initialization point
Utils::Hook(0x60BFBF, Dedicated::PostInitializationStub, HOOK_JUMP).install()->quick();

View File

@ -26,7 +26,5 @@ namespace Components
static void TimeWrapStub(Game::errorParm_t code, const char* message);
static Game::dvar_t* Dvar_RegisterSVNetworkFps(const char* dvarName, int value, int min, int max, int flags, const char* description);
static void AddDedicatedCommands();
};
}

View File

@ -859,6 +859,11 @@ namespace Components
Menus::Add("ui_mp/resetclass.menu");
Menus::Add("ui_mp/popup_customtitle.menu");
Menus::Add("ui_mp/popup_customclan.menu");
Menus::Add("ui_mp/scriptmenus/callvote.menu");
Menus::Add("ui_mp/scriptmenus/changegametype.menu");
Menus::Add("ui_mp/scriptmenus/changemap.menu");
Menus::Add("ui_mp/scriptmenus/kickplayer.menu");
}
Menus::~Menus()

View File

@ -565,9 +565,6 @@ namespace Components
}
});
// Ignore call to print 'Offhand class mismatch when giving weapon...'
Utils::Hook(0x5D9047, 0x4BB9B0, HOOK_CALL).install()->quick();
Command::Add("unlockstats", QuickPatch::UnlockStats);
Command::Add("dumptechsets", [](Command::Params* param)

View File

@ -5,7 +5,7 @@ namespace Game
{
AngleVectors_t AngleVectors = AngleVectors_t(0x4691A0);
Cbuf_AddServerText_t Cbuf_AddServerText = Cbuf_AddServerText_t(0x4BB9B0);
Cbuf_AddServerText_f_t Cbuf_AddServerText_f = Cbuf_AddServerText_f_t(0x4BB9B0);
Cbuf_AddText_t Cbuf_AddText = Cbuf_AddText_t(0x404B20);
Cbuf_InsertText_t Cbuf_InsertText = Cbuf_InsertText_t(0x4940B0);

View File

@ -6,8 +6,8 @@ namespace Game
typedef void(*AngleVectors_t)(float* angles, float* forward, float* right, float* up);
extern AngleVectors_t AngleVectors;
typedef void(*Cbuf_AddServerText_t)();
extern Cbuf_AddServerText_t Cbuf_AddServerText;
typedef void(*Cbuf_AddServerText_f_t)();
extern Cbuf_AddServerText_f_t Cbuf_AddServerText_f;
typedef void(*Cbuf_AddText_t)(int localClientNum, const char* text);
extern Cbuf_AddText_t Cbuf_AddText;