3 * =============================================================================
5 * Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
33 #define _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
36 #include <IUserMessages.h>
37 #include "sourcemm_api.h"
39 #include "sm_stringutil.h"
40 #include "CellRecipientFilter.h"
42 using namespace SourceHook;
43 using namespace SourceMod;
45 #if SOURCE_ENGINE == SE_CSGO
46 #define USE_PROTOBUF_USERMESSAGES
49 #ifdef USE_PROTOBUF_USERMESSAGES
50 #include <google/protobuf/message.h>
51 #include <google/protobuf/descriptor.h>
52 #include <netmessages.pb.h>
54 using namespace google;
59 #define INVALID_MESSAGE_ID -1
63 #ifdef USE_PROTOBUF_USERMESSAGES
64 IProtobufUserMessageListener *Callback;
66 IBitBufUserMessageListener *Callback;
73 typedef List<ListenerInfo *> MsgList;
74 typedef List<ListenerInfo *>::iterator MsgIter;
83 public: //SMGlobalClass
84 void OnSourceModStartup(bool late);
85 void OnSourceModAllInitialized();
86 void OnSourceModAllShutdown();
87 public: //IUserMessages
88 int GetMessageIndex(const char *msg);
89 bool GetMessageName(int msgid, char *buffer, size_t maxlength) const;
90 bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false);
91 bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false);
92 bf_write *StartBitBufMessage(int msg_id, const cell_t players[], unsigned int playersNum, int flags);
93 google::protobuf::Message *StartProtobufMessage(int msg_id, const cell_t players[], unsigned int playersNum, int flags);
95 bool HookUserMessage2(int msg_id,
96 IUserMessageListener *pListener,
97 bool intercept=false);
98 bool UnhookUserMessage2(int msg_id,
99 IUserMessageListener *pListener,
100 bool intercept=false);
101 UserMessageType GetUserMessageType() const;
103 #if SOURCE_ENGINE == SE_CSGO
104 void OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg);
105 void OnSendUserMessage_Post(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg);
108 #if SOURCE_ENGINE == SE_CSGO
109 protobuf::Message *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name);
110 protobuf::Message *OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name);
111 #elif SOURCE_ENGINE >= SE_LEFT4DEAD
112 bf_write *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name);
113 bf_write *OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name);
115 bf_write *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type);
116 bf_write *OnStartMessage_Post(IRecipientFilter *filter, int msg_type);
118 void OnMessageEnd_Pre();
119 void OnMessageEnd_Post();
121 #ifdef USE_PROTOBUF_USERMESSAGES
122 bool InternalHook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew);
123 bool InternalUnhook(int msg_id, IProtobufUserMessageListener *pListener, bool intercept, bool isNew);
125 bool InternalHook(int msg_id, IBitBufUserMessageListener *pListener, bool intercept, bool isNew);
126 bool InternalUnhook(int msg_id, IBitBufUserMessageListener *pListener, bool intercept, bool isNew);
128 void _DecRefCounter();
130 List<ListenerInfo *> m_msgHooks[255];
131 List<ListenerInfo *> m_msgIntercepts[255];
132 CStack<ListenerInfo *> m_FreeListeners;
133 unsigned char m_pBase[2500];
134 IRecipientFilter *m_CurRecFilter;
135 #ifndef USE_PROTOBUF_USERMESSAGES
136 bf_write m_InterceptBuffer;
137 bf_write *m_OrigBuffer;
138 bf_read m_ReadBuffer;
140 // The engine used to provide this. Now we track it.
141 protobuf::Message *m_OrigBuffer;
142 protobuf::Message *m_FakeEngineBuffer;
143 META_RES m_FakeMetaRes;
145 protobuf::Message *m_InterceptBuffer;
150 #ifndef USE_PROTOBUF_USERMESSAGES
151 bool m_FallbackSearch;
155 CellRecipientFilter m_CellRecFilter;
161 extern UserMessages g_UserMsgs;
163 #endif //_INCLUDE_SOURCEMOD_CUSERMESSAGES_H_