core/UserMessages.h
author David Anderson <dvander@alliedmods.net>
Thu Jul 19 03:22:10 2007 +0000 (2007-07-19)
changeset 1134 68e8b8d386ff
parent 765 d78dd115f23a
child 1231 17badaf66ce4
permissions -rw-r--r--
fixed another translator cache issue
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
    16 #define _INCLUDE_SOURCEMOD_CUSERMESSAGES_H_
    17 
    18 #include "ShareSys.h"
    19 #include <IUserMessages.h>
    20 #include "sourcemm_api.h"
    21 #include "sm_trie.h"
    22 #include "CellRecipientFilter.h"
    23 
    24 using namespace SourceHook;
    25 using namespace SourceMod;
    26 
    27 #define INVALID_MESSAGE_ID -1
    28 
    29 struct ListenerInfo
    30 {
    31 	IUserMessageListener *Callback;
    32 	bool IsHooked;
    33 	bool KillMe;
    34 };
    35 
    36 typedef List<ListenerInfo *> MsgList;
    37 typedef List<ListenerInfo *>::iterator MsgIter;
    38 
    39 class UserMessages : 
    40 	public IUserMessages,
    41 	public SMGlobalClass
    42 {
    43 public:
    44 	UserMessages();
    45 	~UserMessages();
    46 public: //SMGlobalClass
    47 	void OnSourceModStartup(bool late);
    48 	void OnSourceModAllInitialized();
    49 	void OnSourceModAllShutdown();
    50 public: //IUserMessages
    51 	int GetMessageIndex(const char *msg);
    52 	bool GetMessageName(int msgid, char *buffer, size_t maxlength) const;
    53 	bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false);
    54 	bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false);
    55 	bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags);
    56 	bool EndMessage();
    57 public:
    58 	bf_write *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type);
    59 	bf_write *OnStartMessage_Post(IRecipientFilter *filter, int msg_type);
    60 	void OnMessageEnd_Pre();
    61 	void OnMessageEnd_Post();
    62 private:
    63 	void _DecRefCounter();
    64 private:
    65 	List<ListenerInfo *> m_msgHooks[255];
    66 	List<ListenerInfo *> m_msgIntercepts[255];
    67 	CStack<ListenerInfo *> m_FreeListeners;
    68 	unsigned char m_pBase[2500];
    69 	IRecipientFilter *m_CurRecFilter;
    70 	bf_write m_InterceptBuffer;
    71 	bf_write *m_OrigBuffer;
    72 	bf_read m_ReadBuffer;
    73 	size_t m_HookCount;
    74 	bool m_InHook;
    75 	bool m_BlockEndPost;
    76 	bool m_FallbackSearch;
    77 
    78 	Trie *m_Names;
    79 	CellRecipientFilter m_CellRecFilter;
    80 	bool m_InExec;
    81 	int m_CurFlags;
    82 	int m_CurId;
    83 };
    84 
    85 extern UserMessages g_UserMsgs;
    86 
    87 #endif //_INCLUDE_SOURCEMOD_CUSERMESSAGES_H_