Skip to content

Commit 650de59

Browse files
committed
update(hooks): SendNetMessage
1 parent 238ee03 commit 650de59

File tree

4 files changed

+44
-31
lines changed

4 files changed

+44
-31
lines changed

plugin_files/gamedata/signatures.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@
8989
"windows": "48 89 74 24 2A 55 41 54 41 55 41 56 41 57 48 8D 6C 24 2A 48 81 EC 2A 2A 2A 2A 4C 8B F9",
9090
"linux": "55 48 89 E5 41 57 41 56 41 55 49 89 FD 41 54 45 89 C4"
9191
},
92-
"SendNetMessage": {
93-
"lib": "networksystem",
94-
"windows": "48 89 5C 24 10 48 89 6C 24 18 56 57 41 56 48 83 EC 40 48 8D A9 D8 75 00 00",
95-
"linux": "55 48 89 E5 41 57 41 56 4C 8D B7 18 76 00 00 41 55 49 89 F5"
96-
},
9792
"HostStateRequest": {
9893
"lib": "engine2",
9994
"windows": "48 89 74 24 10 57 48 83 EC 30 33 F6 48 8B FA",

src/addons/addons.cpp

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <cmath>
1717
#include <algorithm>
1818

19+
#include "../../vendor/dynlib/module.h"
1920
#include "networkbasetypes.pb.h"
2021

2122
#define HAS_MEMBER(DOCUMENT, MEMBER_NAME, MEMBER_PATH) \
@@ -35,7 +36,9 @@
3536
if (!DOCUMENT[MEMBER_NAME].IsUint()) \
3637
return AddonsPrint(string_format("The field \"%s\" is not an unsigned integer.", MEMBER_PATH))
3738

38-
FuncHook<decltype(Hook_SendNetMessage)> TSendNetMessage(Hook_SendNetMessage, "SendNetMessage");
39+
SH_DECL_MANUALHOOK2(SendNetMessage, WIN_LINUX(15, 16), 0, 0, bool, CNetMessage*, NetChannelBufType_t);
40+
int sendNetMessageHookID = -1;
41+
3942
FuncHook<decltype(Hook_HostStateRequest)> THostStateRequest(Hook_HostStateRequest, "HostStateRequest");
4043

4144
size_t FormatArgs(char* buffer, size_t maxlength, const char* fmt, va_list params)
@@ -65,30 +68,6 @@ const char* format(const char* str, ...)
6568
return return_str.c_str();
6669
}
6770

68-
void Hook_SendNetMessage(INetChannel* pNetChan, CNetMessage* pData, NetChannelBufType_t bufType)
69-
{
70-
NetMessageInfo_t* info = pData->GetNetMessage()->GetNetMessageInfo();
71-
72-
if (!UserMessages_SendNetMessage(pNetChan, pData, bufType))
73-
return;
74-
75-
if (info->m_MessageId != 7 || g_addons.GetStatus() == false || g_addons.GetAddons().size() == 0)
76-
return TSendNetMessage(pNetChan, pData, bufType);
77-
78-
ClientJoinInfo_t* pPendingClient = GetPendingClient(pNetChan);
79-
80-
if (pPendingClient)
81-
{
82-
auto pMsg = pData->ToPB<CNETMsg_SignonState>();
83-
pMsg->set_addons(g_addons.GetAddons()[pPendingClient->addon].c_str());
84-
pMsg->set_signon_state(SIGNONSTATE_CHANGELEVEL);
85-
86-
pPendingClient->signon_timestamp = Plat_FloatTime();
87-
}
88-
89-
TSendNetMessage(pNetChan, pData, bufType);
90-
}
91-
9271
void* Hook_HostStateRequest(void* a1, void** pRequest)
9372
{
9473
if (g_addons.GetStatus() == false || g_addons.GetAddons().size() == 0)
@@ -135,6 +114,40 @@ void AddonsPrint(std::string str)
135114
PLUGIN_PRINTF("Addons", "%s\n", str.c_str());
136115
}
137116

117+
void Addons::Initialize()
118+
{
119+
DynLibUtils::CModule enginemodule("engine2");
120+
void* serverSideClientVTable = enginemodule.GetVirtualTableByName("CServerSideClient");
121+
sendNetMessageHookID = SH_ADD_MANUALDVPHOOK(SendNetMessage, serverSideClientVTable, SH_MEMBER(this, &Addons::SendNetMessage), false);
122+
}
123+
124+
void Addons::Destroy()
125+
{
126+
SH_REMOVE_HOOK_ID(sendNetMessageHookID);
127+
}
128+
129+
bool Addons::SendNetMessage(CNetMessage* pData, NetChannelBufType_t bufType)
130+
{
131+
CServerSideClient* pClient = META_IFACEPTR(CServerSideClient);
132+
NetMessageInfo_t* info = pData->GetNetMessage()->GetNetMessageInfo();
133+
if (!UserMessages_SendNetMessage(pClient->GetNetChannel(), pData, bufType))
134+
RETURN_META_VALUE(MRES_SUPERCEDE, false);
135+
136+
if (info->m_MessageId != 7 || g_addons.GetStatus() == false || g_addons.GetAddons().size() == 0)
137+
RETURN_META_VALUE(MRES_IGNORED, true);
138+
139+
ClientJoinInfo_t* pPendingClient = GetPendingClient(pClient->GetNetChannel());
140+
if (pPendingClient)
141+
{
142+
auto pMsg = pData->ToPB<CNETMsg_SignonState>();
143+
pMsg->set_addons(g_addons.GetAddons()[pPendingClient->addon].c_str());
144+
pMsg->set_signon_state(SIGNONSTATE_CHANGELEVEL);
145+
pPendingClient->signon_timestamp = Plat_FloatTime();
146+
}
147+
148+
RETURN_META_VALUE(MRES_HANDLED, true);
149+
}
150+
138151
void Addons::BuildAddonPath(std::string pszAddon, std::string& buffer)
139152
{
140153
static CBufferStringGrowable<MAX_PATH> s_sWorkingDir;

src/addons/addons.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <vector>
1616

17-
void Hook_SendNetMessage(INetChannel *pNetChan, CNetMessage *pData, NetChannelBufType_t bufType);
1817
void *Hook_HostStateRequest(void *a1, void **pRequest);
1918

2019
struct DownloadInfo
@@ -75,6 +74,10 @@ class Addons
7574
bool OnClientConnect(uint64 xuid);
7675

7776
void ReloadMap();
77+
78+
void Initialize();
79+
void Destroy();
80+
bool SendNetMessage(CNetMessage* msg, NetChannelBufType_t bufType);
7881
};
7982

8083
extern Addons g_addons;

src/entrypoint.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ bool Swiftly::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool
179179
g_dbManager->LoadDatabases();
180180

181181
g_addons.LoadAddons();
182+
g_addons.Initialize();
182183

183184
if (!InitializeHooks())
184185
PRINTRET("Hooks failed to initialize.\n", false)
@@ -246,6 +247,7 @@ bool Swiftly::Unload(char* error, size_t maxlen)
246247
UnloadHooks();
247248
UnregisterEventListeners();
248249
g_voiceManager.OnShutdown();
250+
g_addons.Destroy();
249251

250252
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, server, this, &Swiftly::Hook_GameFrame, true);
251253
SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, gameclients, this, &Swiftly::Hook_ClientDisconnect, true);

0 commit comments

Comments
 (0)