mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files. Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer. TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
//===============================================================================//
|
|
//
|
|
// Purpose:
|
|
//
|
|
// $NoKeywords: $
|
|
//
|
|
//===============================================================================//
|
|
// netmessages.cpp: implementation of the CNetMessage types.
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
#include "core/stdafx.h"
|
|
#include "engine/net.h"
|
|
#include "common/netmessages.h"
|
|
|
|
bool SVC_Print::ProcessImpl()
|
|
{
|
|
if (this->m_szText)
|
|
{
|
|
DevMsg(eDLL_T::SERVER, this->m_szText);
|
|
}
|
|
|
|
return true; // Original just return true also.
|
|
}
|
|
|
|
bool SVC_UserMessage::ProcessImpl()
|
|
{
|
|
bf_read buf = m_DataIn;
|
|
int type = buf.ReadByte();
|
|
|
|
if (type == HUD_PRINTCONSOLE ||
|
|
type == HUD_PRINTCENTER)
|
|
{
|
|
char text[MAX_USER_MSG_DATA];
|
|
buf.ReadString(text, sizeof(text));
|
|
if (strnlen_s(text, sizeof(text)) >= NET_MIN_MESSAGE)
|
|
{
|
|
DevMsg(eDLL_T::SERVER, text);
|
|
}
|
|
}
|
|
|
|
return SVC_UserMessage_Process(this); // Need to return original.
|
|
}
|
|
|
|
void V_NetMessages::Attach() const
|
|
{
|
|
#if !defined(DEDICATED)
|
|
auto SVCPrint = &SVC_Print::ProcessImpl;
|
|
auto SVCUserMessage = &SVC_UserMessage::ProcessImpl;
|
|
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);
|
|
#endif // DEDICATED
|
|
}
|
|
|
|
void V_NetMessages::Detach() const
|
|
{
|
|
#if !defined(DEDICATED)
|
|
void* hkRestore = nullptr;
|
|
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);
|
|
#endif // DEDICATED
|
|
} |