1.1 --- a/core/CMsgListenerWrapper.h Sat Mar 10 21:02:40 2007 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,144 +0,0 @@
1.4 -/**
1.5 -* vim: set ts=4 :
1.6 -* ===============================================================
1.7 -* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.8 -* ===============================================================
1.9 -*
1.10 -* This file is not open source and may not be copied without explicit
1.11 -* written permission of AlliedModders LLC. This file may not be redistributed
1.12 -* in whole or significant part.
1.13 -* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
1.14 -*
1.15 -* Version: $Id$
1.16 -*/
1.17 -
1.18 -#ifndef _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_
1.19 -#define _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_
1.20 -
1.21 -extern int g_MsgPlayers[256];
1.22 -
1.23 -class MsgListenerWrapper : public IUserMessageListener
1.24 -{
1.25 -public:
1.26 - void InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept);
1.27 - bool IsInterceptHook() const;
1.28 - int GetMessageId() const;
1.29 - IPluginFunction *GetHookedFunction() const;
1.30 - IPluginFunction *GetNotifyFunction() const;
1.31 -public: //IUserMessageListener
1.32 - void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
1.33 - ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
1.34 - void OnUserMessageSent(int msg_id);
1.35 -private:
1.36 - size_t PreparePlArray(int *pl_array, IRecipientFilter *pFilter);
1.37 -private:
1.38 - IPluginFunction *m_Hook;
1.39 - IPluginFunction *m_Intercept;
1.40 - IPluginFunction *m_Notify;
1.41 - bool m_IsInterceptHook;
1.42 - int m_MsgId;
1.43 -};
1.44 -
1.45 -inline size_t MsgListenerWrapper::PreparePlArray(int *pl_array, IRecipientFilter *pFilter)
1.46 -{
1.47 - size_t size = static_cast<size_t>(pFilter->GetRecipientCount());
1.48 -
1.49 - for (size_t i=0; i<size; i++)
1.50 - {
1.51 - pl_array[i] = pFilter->GetRecipientIndex(i);
1.52 - }
1.53 -
1.54 - return size;
1.55 -}
1.56 -
1.57 -inline bool MsgListenerWrapper::IsInterceptHook() const
1.58 -{
1.59 - return m_IsInterceptHook;
1.60 -}
1.61 -
1.62 -inline int MsgListenerWrapper::GetMessageId() const
1.63 -{
1.64 - return m_MsgId;
1.65 -}
1.66 -
1.67 -inline IPluginFunction *MsgListenerWrapper::GetHookedFunction() const
1.68 -{
1.69 - if (m_Hook)
1.70 - {
1.71 - return m_Hook;
1.72 - } else {
1.73 - return m_Intercept;
1.74 - }
1.75 -}
1.76 -
1.77 -inline IPluginFunction *MsgListenerWrapper::GetNotifyFunction() const
1.78 -{
1.79 - return m_Notify;
1.80 -}
1.81 -
1.82 -inline void MsgListenerWrapper::InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept)
1.83 -{
1.84 - if (intercept)
1.85 - {
1.86 - m_Intercept = hook;
1.87 - m_Hook = NULL;
1.88 - } else {
1.89 - m_Hook = hook;
1.90 - m_Intercept = NULL;
1.91 - }
1.92 -
1.93 - if (notify)
1.94 - {
1.95 - m_Notify = notify;
1.96 - } else {
1.97 - m_Notify = NULL;
1.98 - }
1.99 -
1.100 - m_MsgId = msgid;
1.101 - m_IsInterceptHook = intercept;
1.102 -}
1.103 -
1.104 -inline void MsgListenerWrapper::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
1.105 -{
1.106 - cell_t res;
1.107 - size_t size = PreparePlArray(g_MsgPlayers, pFilter);
1.108 -
1.109 - m_Hook->PushCell(msg_id);
1.110 - m_Hook->PushCell(0); //:TODO: push handle!
1.111 - m_Hook->PushArray(g_MsgPlayers, size);
1.112 - m_Hook->PushCell(size);
1.113 - m_Hook->PushCell(pFilter->IsReliable());
1.114 - m_Hook->PushCell(pFilter->IsInitMessage());
1.115 - m_Hook->Execute(&res);
1.116 -}
1.117 -
1.118 -inline ResultType MsgListenerWrapper::InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
1.119 -{
1.120 - cell_t res = static_cast<cell_t>(Pl_Continue);
1.121 - size_t size = PreparePlArray(g_MsgPlayers, pFilter);
1.122 -
1.123 - m_Intercept->PushCell(msg_id);
1.124 - m_Intercept->PushCell(0); //:TODO: push handle!
1.125 - m_Intercept->PushArray(g_MsgPlayers, size);
1.126 - m_Intercept->PushCell(size);
1.127 - m_Intercept->PushCell(pFilter->IsReliable());
1.128 - m_Intercept->PushCell(pFilter->IsInitMessage());
1.129 - m_Intercept->Execute(&res);
1.130 -
1.131 - return static_cast<ResultType>(res);
1.132 -}
1.133 -
1.134 -inline void MsgListenerWrapper::OnUserMessageSent(int msg_id)
1.135 -{
1.136 - cell_t res;
1.137 -
1.138 - if (!m_Notify)
1.139 - {
1.140 - return;
1.141 - }
1.142 -
1.143 - m_Notify->PushCell(msg_id);
1.144 - m_Notify->Execute(&res);
1.145 -}
1.146 -
1.147 -#endif //_INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_
2.1 --- a/core/msvc8/sourcemod_mm.vcproj Sat Mar 10 21:02:40 2007 +0000
2.2 +++ b/core/msvc8/sourcemod_mm.vcproj Sat Mar 10 21:12:40 2007 +0000
2.3 @@ -1,7 +1,7 @@
2.4 <?xml version="1.0" encoding="Windows-1252"?>
2.5 <VisualStudioProject
2.6 ProjectType="Visual C++"
2.7 - Version="8,00"
2.8 + Version="8.00"
2.9 Name="sourcemod_mm"
2.10 ProjectGUID="{E39527CD-7CAB-4420-97CC-DA1B93B260BC}"
2.11 RootNamespace="sourcemod_mm"
2.12 @@ -298,10 +298,6 @@
2.13 >
2.14 </File>
2.15 <File
2.16 - RelativePath="..\CMsgListenerWrapper.h"
2.17 - >
2.18 - </File>
2.19 - <File
2.20 RelativePath="..\ConCmdManager.h"
2.21 >
2.22 </File>
2.23 @@ -366,6 +362,10 @@
2.24 >
2.25 </File>
2.26 <File
2.27 + RelativePath="..\smn_usermsgs.h"
2.28 + >
2.29 + </File>
2.30 + <File
2.31 RelativePath="..\sourcemm_api.h"
2.32 >
2.33 </File>
3.1 --- a/core/smn_usermsgs.cpp Sat Mar 10 21:02:40 2007 +0000
3.2 +++ b/core/smn_usermsgs.cpp Sat Mar 10 21:12:40 2007 +0000
3.3 @@ -15,7 +15,7 @@
3.4 #include "HandleSys.h"
3.5 #include "PluginSys.h"
3.6 #include "CUserMessages.h"
3.7 -#include "CMsgListenerWrapper.h"
3.8 +#include "smn_usermsgs.h"
3.9
3.10 HandleType_t g_WrBitBufType;
3.11 Handle_t g_CurMsgHandle;
3.12 @@ -149,11 +149,119 @@
3.13 return true;
3.14 }
3.15
3.16 -/**************************************
3.17 -* *
3.18 -* USER MESSAGE NATIVE IMPLEMENTATIONS *
3.19 -* *
3.20 -***************************************/
3.21 +/***************************************
3.22 + * *
3.23 + * USER MESSAGE WRAPPER IMPLEMENTATION *
3.24 + * *
3.25 + ***************************************/
3.26 +
3.27 +size_t MsgListenerWrapper::PreparePlArray(int *pl_array, IRecipientFilter *pFilter)
3.28 +{
3.29 + size_t size = static_cast<size_t>(pFilter->GetRecipientCount());
3.30 +
3.31 + for (size_t i=0; i<size; i++)
3.32 + {
3.33 + pl_array[i] = pFilter->GetRecipientIndex(i);
3.34 + }
3.35 +
3.36 + return size;
3.37 +}
3.38 +
3.39 +bool MsgListenerWrapper::IsInterceptHook() const
3.40 +{
3.41 + return m_IsInterceptHook;
3.42 +}
3.43 +
3.44 +int MsgListenerWrapper::GetMessageId() const
3.45 +{
3.46 + return m_MsgId;
3.47 +}
3.48 +
3.49 +IPluginFunction *MsgListenerWrapper::GetHookedFunction() const
3.50 +{
3.51 + if (m_Hook)
3.52 + {
3.53 + return m_Hook;
3.54 + } else {
3.55 + return m_Intercept;
3.56 + }
3.57 +}
3.58 +
3.59 +IPluginFunction *MsgListenerWrapper::GetNotifyFunction() const
3.60 +{
3.61 + return m_Notify;
3.62 +}
3.63 +
3.64 +void MsgListenerWrapper::InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept)
3.65 +{
3.66 + if (intercept)
3.67 + {
3.68 + m_Intercept = hook;
3.69 + m_Hook = NULL;
3.70 + } else {
3.71 + m_Hook = hook;
3.72 + m_Intercept = NULL;
3.73 + }
3.74 +
3.75 + if (notify)
3.76 + {
3.77 + m_Notify = notify;
3.78 + } else {
3.79 + m_Notify = NULL;
3.80 + }
3.81 +
3.82 + m_MsgId = msgid;
3.83 + m_IsInterceptHook = intercept;
3.84 +}
3.85 +
3.86 +void MsgListenerWrapper::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
3.87 +{
3.88 + cell_t res;
3.89 + size_t size = PreparePlArray(g_MsgPlayers, pFilter);
3.90 +
3.91 + m_Hook->PushCell(msg_id);
3.92 + m_Hook->PushCell(0); //:TODO: push handle!
3.93 + m_Hook->PushArray(g_MsgPlayers, size);
3.94 + m_Hook->PushCell(size);
3.95 + m_Hook->PushCell(pFilter->IsReliable());
3.96 + m_Hook->PushCell(pFilter->IsInitMessage());
3.97 + m_Hook->Execute(&res);
3.98 +}
3.99 +
3.100 +ResultType MsgListenerWrapper::InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
3.101 +{
3.102 + cell_t res = static_cast<cell_t>(Pl_Continue);
3.103 + size_t size = PreparePlArray(g_MsgPlayers, pFilter);
3.104 +
3.105 + m_Intercept->PushCell(msg_id);
3.106 + m_Intercept->PushCell(0); //:TODO: push handle!
3.107 + m_Intercept->PushArray(g_MsgPlayers, size);
3.108 + m_Intercept->PushCell(size);
3.109 + m_Intercept->PushCell(pFilter->IsReliable());
3.110 + m_Intercept->PushCell(pFilter->IsInitMessage());
3.111 + m_Intercept->Execute(&res);
3.112 +
3.113 + return static_cast<ResultType>(res);
3.114 +}
3.115 +
3.116 +void MsgListenerWrapper::OnUserMessageSent(int msg_id)
3.117 +{
3.118 + cell_t res;
3.119 +
3.120 + if (!m_Notify)
3.121 + {
3.122 + return;
3.123 + }
3.124 +
3.125 + m_Notify->PushCell(msg_id);
3.126 + m_Notify->Execute(&res);
3.127 +}
3.128 +
3.129 +/***************************************
3.130 + * *
3.131 + * USER MESSAGE NATIVE IMPLEMENTATIONS *
3.132 + * *
3.133 + ***************************************/
3.134
3.135 static UsrMessageNatives s_UsrMessageNatives;
3.136
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/core/smn_usermsgs.h Sat Mar 10 21:12:40 2007 +0000
4.3 @@ -0,0 +1,42 @@
4.4 +/**
4.5 +* vim: set ts=4 :
4.6 +* ===============================================================
4.7 +* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4.8 +* ===============================================================
4.9 +*
4.10 +* This file is not open source and may not be copied without explicit
4.11 +* written permission of AlliedModders LLC. This file may not be redistributed
4.12 +* in whole or significant part.
4.13 +* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
4.14 +*
4.15 +* Version: $Id$
4.16 +*/
4.17 +
4.18 +#ifndef _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_
4.19 +#define _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_
4.20 +
4.21 +extern int g_MsgPlayers[256];
4.22 +
4.23 +class MsgListenerWrapper : public IUserMessageListener
4.24 +{
4.25 +public:
4.26 + void InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept);
4.27 + bool IsInterceptHook() const;
4.28 + int GetMessageId() const;
4.29 + IPluginFunction *GetHookedFunction() const;
4.30 + IPluginFunction *GetNotifyFunction() const;
4.31 +public: //IUserMessageListener
4.32 + void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
4.33 + ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
4.34 + void OnUserMessageSent(int msg_id);
4.35 +private:
4.36 + size_t PreparePlArray(int *pl_array, IRecipientFilter *pFilter);
4.37 +private:
4.38 + IPluginFunction *m_Hook;
4.39 + IPluginFunction *m_Intercept;
4.40 + IPluginFunction *m_Notify;
4.41 + bool m_IsInterceptHook;
4.42 + int m_MsgId;
4.43 +};
4.44 +
4.45 +#endif //_INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_