From 1b6f40d9418c95ae7bbb95434c855b6ce816c92d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 23 Jun 2022 18:20:17 +0200 Subject: [PATCH] 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). --- r5dev/common/netmessages.cpp | 6 +++--- r5dev/common/netmessages.h | 16 +++++++++------- r5dev/engine/client/clientstate.h | 6 ------ r5dev/public/include/inetchannel.h | 6 ++---- r5dev/public/include/inetmsghandler.h | 8 ++++++++ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/r5dev/common/netmessages.cpp b/r5dev/common/netmessages.cpp index fb4eac9a..614e4448 100644 --- a/r5dev/common/netmessages.cpp +++ b/r5dev/common/netmessages.cpp @@ -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); } \ No newline at end of file diff --git a/r5dev/common/netmessages.h b/r5dev/common/netmessages.h index d47ae99f..656867ec 100644 --- a/r5dev/common/netmessages.h +++ b/r5dev/common/netmessages.h @@ -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; diff --git a/r5dev/engine/client/clientstate.h b/r5dev/engine/client/clientstate.h index 075923b6..272fe5f2 100644 --- a/r5dev/engine/client/clientstate.h +++ b/r5dev/engine/client/clientstate.h @@ -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 { diff --git a/r5dev/public/include/inetchannel.h b/r5dev/public/include/inetchannel.h index 37c22c62..f3711a71 100644 --- a/r5dev/public/include/inetchannel.h +++ b/r5dev/public/include/inetchannel.h @@ -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 diff --git a/r5dev/public/include/inetmsghandler.h b/r5dev/public/include/inetmsghandler.h index 8e1900f9..d6b395c9 100644 --- a/r5dev/public/include/inetmsghandler.h +++ b/r5dev/public/include/inetmsghandler.h @@ -18,4 +18,12 @@ struct IConnectionlessPacketHandler void* __vftable /*VFT*/; }; +struct INetMessageHandler +{ + void* __vftable /*VFT*/; +}; + +struct IServerMessageHandler : INetMessageHandler +{}; + #endif // INETMSGHANDLER_H \ No newline at end of file