Fix for SVC_UserMessage

Removed padding that was causing the structure to misalign with the game's one.
Enabled 'SVC_UserMessage::Process()' hook (function works properly after the structure alignment).
This commit is contained in:
Kawe Mazidjatari 2022-06-23 18:20:17 +02:00
parent f1395c0bad
commit 1b6f40d941
5 changed files with 22 additions and 20 deletions

View File

@ -30,7 +30,7 @@ bool SVC_UserMessage::Process()
{
char text[256];
buf.ReadString(text, sizeof(text));
if (strnlen_s(text, 256) > 0)
if (strnlen_s(text, sizeof(text)) > 0)
{
DevMsg(eDLL_T::SERVER, text);
}
@ -44,12 +44,12 @@ void CNetMessages_Attach()
auto SVCPrint = &SVC_Print::Process;
auto SVCUserMessage = &SVC_UserMessage::Process;
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_Print_VTable, (LPVOID&)SVCPrint, (LPVOID*)&SVC_Print_Process, 3);
//CMemory::HookVirtualMethod((uintptr_t)g_pSVC_UserMessage_VTable, (LPVOID&)SVCUserMessage, (LPVOID*)&SVC_UserMessage_Process, 3);
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_UserMessage_VTable, (LPVOID&)SVCUserMessage, (LPVOID*)&SVC_UserMessage_Process, 3);
}
void CNetMessages_Detach()
{
void* hkRestore = nullptr;
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_Print_VTable, (LPVOID)SVC_Print_Process, (LPVOID*)&hkRestore, 3);
//CMemory::HookVirtualMethod((uintptr_t)g_pSVC_UserMessage_VTable, (LPVOID)SVC_UserMessage_Process, (LPVOID*)&hkRestore, 3);
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_UserMessage_VTable, (LPVOID)SVC_UserMessage_Process, (LPVOID*)&hkRestore, 3);
}

View File

@ -1,41 +1,43 @@
#pragma once
#include "tier1/bitbuf.h"
#include "public/include/inetmsghandler.h"
enum class UserMessages : int
{
TextMsg = 0x2
};
class CNetMessage
class INetMessage
{
void* __vftable /*VFT*/;
};
class CNetMessage : public INetMessage
{
public:
void* iNetMessageVTable;
int m_nGroup;
bool m_bReliable;
char padding[3];
void* m_NetChannel;
};
class SVC_Print : public CNetMessage
class SVC_Print : public CNetMessage, IServerMessageHandler
{
public:
bool Process();
void* m_pMessageHandler;
char padding[8];
const char* m_szText;
private:
char m_szTextBuffer[2048];
};
class SVC_UserMessage : public CNetMessage
class SVC_UserMessage : public CNetMessage, IServerMessageHandler
{
public:
bool Process();
void* m_pMessageHandler;
char padding[8];
int m_nMsgType;
int m_nLength; // data length in bits
bf_read m_DataIn;

View File

@ -17,12 +17,6 @@ struct __declspec(align(8)) CClientSnapshotManager
CUtlMemoryPool m_ClientFramePool;
};
struct IServerMessageHandler : INetMessageHandler
{};
struct CS_INetChannelHandler : INetChannelHandler
{};
///////////////////////////////////////////////////////////////////////////////
class CClientState : CS_INetChannelHandler, IConnectionlessPacketHandler, IServerMessageHandler, CClientSnapshotManager
{

View File

@ -16,10 +16,8 @@ struct INetChannelHandler
void* __vftable /*VFT*/;
};
struct INetMessageHandler
{
void* __vftable /*VFT*/;
};
struct CS_INetChannelHandler : INetChannelHandler
{};
typedef struct netpacket_s netpacket_t;
typedef struct __declspec(align(8)) netpacket_s

View File

@ -18,4 +18,12 @@ struct IConnectionlessPacketHandler
void* __vftable /*VFT*/;
};
struct INetMessageHandler
{
void* __vftable /*VFT*/;
};
struct IServerMessageHandler : INetMessageHandler
{};
#endif // INETMSGHANDLER_H