2022-04-27 16:29:14 +02:00
|
|
|
//===============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//
|
|
|
|
//===============================================================================//
|
|
|
|
// netmessages.cpp: implementation of the CNetMessage types.
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "core/stdafx.h"
|
2022-08-15 02:59:41 +02:00
|
|
|
#include "engine/net.h"
|
2022-04-27 16:29:14 +02:00
|
|
|
#include "common/netmessages.h"
|
|
|
|
|
2022-08-15 14:44:54 +02:00
|
|
|
bool SVC_Print::ProcessImpl()
|
2022-04-27 16:29:14 +02:00
|
|
|
{
|
2022-04-27 18:42:49 +02:00
|
|
|
if (this->m_szText)
|
2022-04-27 16:29:14 +02:00
|
|
|
{
|
2023-04-09 22:22:06 +02:00
|
|
|
Assert(m_szText == m_szTextBuffer); // Should always point to 'm_szTextBuffer'.
|
|
|
|
|
|
|
|
size_t len = strnlen_s(m_szText, sizeof(m_szTextBuffer));
|
|
|
|
Assert(len < sizeof(m_szTextBuffer));
|
|
|
|
|
|
|
|
if (len < sizeof(m_szTextBuffer))
|
|
|
|
{
|
|
|
|
DevMsg(eDLL_T::SERVER, m_szText[len-1] == '\n' ? "%s" : "%s\n", m_szText);
|
|
|
|
}
|
2022-04-27 16:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true; // Original just return true also.
|
|
|
|
}
|
|
|
|
|
2022-08-15 14:44:54 +02:00
|
|
|
bool SVC_UserMessage::ProcessImpl()
|
2022-04-30 03:00:24 +02:00
|
|
|
{
|
|
|
|
bf_read buf = m_DataIn;
|
2022-08-15 02:59:41 +02:00
|
|
|
int type = buf.ReadByte();
|
2022-04-30 03:00:24 +02:00
|
|
|
|
2022-08-15 02:59:41 +02:00
|
|
|
if (type == HUD_PRINTCONSOLE ||
|
|
|
|
type == HUD_PRINTCENTER)
|
2022-04-30 03:00:24 +02:00
|
|
|
{
|
2022-08-15 02:59:41 +02:00
|
|
|
char text[MAX_USER_MSG_DATA];
|
2023-04-09 22:22:06 +02:00
|
|
|
int len;
|
|
|
|
|
|
|
|
buf.ReadString(text, sizeof(text), false, &len);
|
|
|
|
Assert(len < sizeof(text));
|
|
|
|
|
|
|
|
if (len >= NET_MIN_MESSAGE && len < sizeof(text))
|
2022-04-30 03:00:24 +02:00
|
|
|
{
|
2023-04-09 22:22:06 +02:00
|
|
|
DevMsg(eDLL_T::SERVER, text[len-1] == '\n' ? "%s" : "%s\n", text);
|
2022-04-30 03:00:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SVC_UserMessage_Process(this); // Need to return original.
|
|
|
|
}
|
|
|
|
|
2023-01-25 02:26:52 +01:00
|
|
|
void V_NetMessages::Attach() const
|
2022-04-27 16:29:14 +02:00
|
|
|
{
|
2023-01-25 02:26:52 +01:00
|
|
|
#if !defined(DEDICATED)
|
2022-08-15 14:44:54 +02:00
|
|
|
auto SVCPrint = &SVC_Print::ProcessImpl;
|
|
|
|
auto SVCUserMessage = &SVC_UserMessage::ProcessImpl;
|
2022-09-09 19:47:31 +02:00
|
|
|
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_Print_VFTable, (LPVOID&)SVCPrint, 3, (LPVOID*)&SVC_Print_Process);
|
|
|
|
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_UserMessage_VFTable, (LPVOID&)SVCUserMessage, 3, (LPVOID*)&SVC_UserMessage_Process);
|
2023-01-25 02:26:52 +01:00
|
|
|
#endif // DEDICATED
|
2022-04-27 16:29:14 +02:00
|
|
|
}
|
|
|
|
|
2023-01-25 02:26:52 +01:00
|
|
|
void V_NetMessages::Detach() const
|
2022-04-27 16:29:14 +02:00
|
|
|
{
|
2023-01-25 02:26:52 +01:00
|
|
|
#if !defined(DEDICATED)
|
2022-04-30 03:00:24 +02:00
|
|
|
void* hkRestore = nullptr;
|
2022-09-09 19:47:31 +02:00
|
|
|
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_Print_VFTable, (LPVOID)SVC_Print_Process, 3, (LPVOID*)&hkRestore);
|
|
|
|
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_UserMessage_VFTable, (LPVOID)SVC_UserMessage_Process, 3, (LPVOID*)&hkRestore);
|
2023-01-25 02:26:52 +01:00
|
|
|
#endif // DEDICATED
|
2022-04-27 16:29:14 +02:00
|
|
|
}
|