diff --git a/core/CMsgListenerWrapper.h b/core/CMsgListenerWrapper.h deleted file mode 100644 index d06fe8e2..00000000 --- a/core/CMsgListenerWrapper.h +++ /dev/null @@ -1,144 +0,0 @@ -/** -* vim: set ts=4 : -* =============================================================== -* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. -* =============================================================== -* -* This file is not open source and may not be copied without explicit -* written permission of AlliedModders LLC. This file may not be redistributed -* in whole or significant part. -* For information, see LICENSE.txt or http://www.sourcemod.net/license.php -* -* Version: $Id$ -*/ - -#ifndef _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_ -#define _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_ - -extern int g_MsgPlayers[256]; - -class MsgListenerWrapper : public IUserMessageListener -{ -public: - void InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept); - bool IsInterceptHook() const; - int GetMessageId() const; - IPluginFunction *GetHookedFunction() const; - IPluginFunction *GetNotifyFunction() const; -public: //IUserMessageListener - void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter); - ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter); - void OnUserMessageSent(int msg_id); -private: - size_t PreparePlArray(int *pl_array, IRecipientFilter *pFilter); -private: - IPluginFunction *m_Hook; - IPluginFunction *m_Intercept; - IPluginFunction *m_Notify; - bool m_IsInterceptHook; - int m_MsgId; -}; - -inline size_t MsgListenerWrapper::PreparePlArray(int *pl_array, IRecipientFilter *pFilter) -{ - size_t size = static_cast(pFilter->GetRecipientCount()); - - for (size_t i=0; iGetRecipientIndex(i); - } - - return size; -} - -inline bool MsgListenerWrapper::IsInterceptHook() const -{ - return m_IsInterceptHook; -} - -inline int MsgListenerWrapper::GetMessageId() const -{ - return m_MsgId; -} - -inline IPluginFunction *MsgListenerWrapper::GetHookedFunction() const -{ - if (m_Hook) - { - return m_Hook; - } else { - return m_Intercept; - } -} - -inline IPluginFunction *MsgListenerWrapper::GetNotifyFunction() const -{ - return m_Notify; -} - -inline void MsgListenerWrapper::InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept) -{ - if (intercept) - { - m_Intercept = hook; - m_Hook = NULL; - } else { - m_Hook = hook; - m_Intercept = NULL; - } - - if (notify) - { - m_Notify = notify; - } else { - m_Notify = NULL; - } - - m_MsgId = msgid; - m_IsInterceptHook = intercept; -} - -inline void MsgListenerWrapper::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter) -{ - cell_t res; - size_t size = PreparePlArray(g_MsgPlayers, pFilter); - - m_Hook->PushCell(msg_id); - m_Hook->PushCell(0); //:TODO: push handle! - m_Hook->PushArray(g_MsgPlayers, size); - m_Hook->PushCell(size); - m_Hook->PushCell(pFilter->IsReliable()); - m_Hook->PushCell(pFilter->IsInitMessage()); - m_Hook->Execute(&res); -} - -inline ResultType MsgListenerWrapper::InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter) -{ - cell_t res = static_cast(Pl_Continue); - size_t size = PreparePlArray(g_MsgPlayers, pFilter); - - m_Intercept->PushCell(msg_id); - m_Intercept->PushCell(0); //:TODO: push handle! - m_Intercept->PushArray(g_MsgPlayers, size); - m_Intercept->PushCell(size); - m_Intercept->PushCell(pFilter->IsReliable()); - m_Intercept->PushCell(pFilter->IsInitMessage()); - m_Intercept->Execute(&res); - - return static_cast(res); -} - -inline void MsgListenerWrapper::OnUserMessageSent(int msg_id) -{ - cell_t res; - - if (!m_Notify) - { - return; - } - - m_Notify->PushCell(msg_id); - m_Notify->Execute(&res); -} - -#endif //_INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_ diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index 76298884..46e68a91 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -1,7 +1,7 @@ - - @@ -365,6 +361,10 @@ RelativePath="..\sm_version.h" > + + diff --git a/core/smn_usermsgs.cpp b/core/smn_usermsgs.cpp index c9eff762..155d7c22 100644 --- a/core/smn_usermsgs.cpp +++ b/core/smn_usermsgs.cpp @@ -15,7 +15,7 @@ #include "HandleSys.h" #include "PluginSys.h" #include "CUserMessages.h" -#include "CMsgListenerWrapper.h" +#include "smn_usermsgs.h" HandleType_t g_WrBitBufType; Handle_t g_CurMsgHandle; @@ -149,11 +149,119 @@ bool UsrMessageNatives::RemoveListener(IPluginContext *pCtx, MsgListenerWrapper return true; } -/************************************** -* * -* USER MESSAGE NATIVE IMPLEMENTATIONS * -* * -***************************************/ +/*************************************** + * * + * USER MESSAGE WRAPPER IMPLEMENTATION * + * * + ***************************************/ + +size_t MsgListenerWrapper::PreparePlArray(int *pl_array, IRecipientFilter *pFilter) +{ + size_t size = static_cast(pFilter->GetRecipientCount()); + + for (size_t i=0; iGetRecipientIndex(i); + } + + return size; +} + +bool MsgListenerWrapper::IsInterceptHook() const +{ + return m_IsInterceptHook; +} + +int MsgListenerWrapper::GetMessageId() const +{ + return m_MsgId; +} + +IPluginFunction *MsgListenerWrapper::GetHookedFunction() const +{ + if (m_Hook) + { + return m_Hook; + } else { + return m_Intercept; + } +} + +IPluginFunction *MsgListenerWrapper::GetNotifyFunction() const +{ + return m_Notify; +} + +void MsgListenerWrapper::InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept) +{ + if (intercept) + { + m_Intercept = hook; + m_Hook = NULL; + } else { + m_Hook = hook; + m_Intercept = NULL; + } + + if (notify) + { + m_Notify = notify; + } else { + m_Notify = NULL; + } + + m_MsgId = msgid; + m_IsInterceptHook = intercept; +} + +void MsgListenerWrapper::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter) +{ + cell_t res; + size_t size = PreparePlArray(g_MsgPlayers, pFilter); + + m_Hook->PushCell(msg_id); + m_Hook->PushCell(0); //:TODO: push handle! + m_Hook->PushArray(g_MsgPlayers, size); + m_Hook->PushCell(size); + m_Hook->PushCell(pFilter->IsReliable()); + m_Hook->PushCell(pFilter->IsInitMessage()); + m_Hook->Execute(&res); +} + +ResultType MsgListenerWrapper::InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter) +{ + cell_t res = static_cast(Pl_Continue); + size_t size = PreparePlArray(g_MsgPlayers, pFilter); + + m_Intercept->PushCell(msg_id); + m_Intercept->PushCell(0); //:TODO: push handle! + m_Intercept->PushArray(g_MsgPlayers, size); + m_Intercept->PushCell(size); + m_Intercept->PushCell(pFilter->IsReliable()); + m_Intercept->PushCell(pFilter->IsInitMessage()); + m_Intercept->Execute(&res); + + return static_cast(res); +} + +void MsgListenerWrapper::OnUserMessageSent(int msg_id) +{ + cell_t res; + + if (!m_Notify) + { + return; + } + + m_Notify->PushCell(msg_id); + m_Notify->Execute(&res); +} + +/*************************************** + * * + * USER MESSAGE NATIVE IMPLEMENTATIONS * + * * + ***************************************/ static UsrMessageNatives s_UsrMessageNatives; diff --git a/core/smn_usermsgs.h b/core/smn_usermsgs.h new file mode 100644 index 00000000..54efc186 --- /dev/null +++ b/core/smn_usermsgs.h @@ -0,0 +1,42 @@ +/** +* vim: set ts=4 : +* =============================================================== +* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. +* =============================================================== +* +* This file is not open source and may not be copied without explicit +* written permission of AlliedModders LLC. This file may not be redistributed +* in whole or significant part. +* For information, see LICENSE.txt or http://www.sourcemod.net/license.php +* +* Version: $Id$ +*/ + +#ifndef _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_ +#define _INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_ + +extern int g_MsgPlayers[256]; + +class MsgListenerWrapper : public IUserMessageListener +{ +public: + void InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept); + bool IsInterceptHook() const; + int GetMessageId() const; + IPluginFunction *GetHookedFunction() const; + IPluginFunction *GetNotifyFunction() const; +public: //IUserMessageListener + void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter); + ResultType InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter); + void OnUserMessageSent(int msg_id); +private: + size_t PreparePlArray(int *pl_array, IRecipientFilter *pFilter); +private: + IPluginFunction *m_Hook; + IPluginFunction *m_Intercept; + IPluginFunction *m_Notify; + bool m_IsInterceptHook; + int m_MsgId; +}; + +#endif //_INCLUDE_SOURCEMOD_CMSGLISTENERWRAPPER_H_