|
16 | 16 | #include <cmath> |
17 | 17 | #include <algorithm> |
18 | 18 |
|
| 19 | +#include "../../vendor/dynlib/module.h" |
19 | 20 | #include "networkbasetypes.pb.h" |
20 | 21 |
|
21 | 22 | #define HAS_MEMBER(DOCUMENT, MEMBER_NAME, MEMBER_PATH) \ |
|
35 | 36 | if (!DOCUMENT[MEMBER_NAME].IsUint()) \ |
36 | 37 | return AddonsPrint(string_format("The field \"%s\" is not an unsigned integer.", MEMBER_PATH)) |
37 | 38 |
|
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 | + |
39 | 42 | FuncHook<decltype(Hook_HostStateRequest)> THostStateRequest(Hook_HostStateRequest, "HostStateRequest"); |
40 | 43 |
|
41 | 44 | size_t FormatArgs(char* buffer, size_t maxlength, const char* fmt, va_list params) |
@@ -65,30 +68,6 @@ const char* format(const char* str, ...) |
65 | 68 | return return_str.c_str(); |
66 | 69 | } |
67 | 70 |
|
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 | | - |
92 | 71 | void* Hook_HostStateRequest(void* a1, void** pRequest) |
93 | 72 | { |
94 | 73 | if (g_addons.GetStatus() == false || g_addons.GetAddons().size() == 0) |
@@ -135,6 +114,40 @@ void AddonsPrint(std::string str) |
135 | 114 | PLUGIN_PRINTF("Addons", "%s\n", str.c_str()); |
136 | 115 | } |
137 | 116 |
|
| 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 | + |
138 | 151 | void Addons::BuildAddonPath(std::string pszAddon, std::string& buffer) |
139 | 152 | { |
140 | 153 | static CBufferStringGrowable<MAX_PATH> s_sWorkingDir; |
|
0 commit comments