From f6a1db7633548b97d03436a69631ba2d7724d1fa Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 6 Jun 2007 22:37:36 +0000 Subject: [PATCH] added say_team hooks --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40903 --- core/ChatTriggers.cpp | 31 +++++++++++++++++++++++++++++-- core/ChatTriggers.h | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp index 5a9260a4..dda4a8b7 100644 --- a/core/ChatTriggers.cpp +++ b/core/ChatTriggers.cpp @@ -18,6 +18,13 @@ ChatTriggers::ChatTriggers() : m_pSayCmd(NULL), m_bWillProcessInPost(false), m_PrivTriggerSize = 1; } +ChatTriggers::~ChatTriggers() +{ + delete [] m_PubTrigger; + m_PubTrigger = NULL; + delete [] m_PrivTrigger; + m_PrivTrigger = NULL; +} ConfigResult ChatTriggers::OnSourceModConfigChanged(const char *key, const char *value, @@ -43,6 +50,7 @@ ConfigResult ChatTriggers::OnSourceModConfigChanged(const char *key, void ChatTriggers::OnSourceModGameInitialized() { + unsigned int total = 2; ConCommandBase *pCmd = icvar->GetCommands(); const char *name; while (pCmd) @@ -50,10 +58,19 @@ void ChatTriggers::OnSourceModGameInitialized() if (pCmd->IsCommand()) { name = pCmd->GetName(); - if (strcmp(name, "say") == 0) + if (!m_pSayCmd && strcmp(name, "say") == 0) { m_pSayCmd = (ConCommand *)pCmd; - break; + if (--total == 0) + { + break; + } + } else if (!m_pSayTeamCmd && strcmp(name, "say_team") == 0) { + m_pSayTeamCmd = (ConCommand *)pCmd; + if (--total == 0) + { + break; + } } } pCmd = const_cast(pCmd->GetNext()); @@ -64,10 +81,20 @@ void ChatTriggers::OnSourceModGameInitialized() SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Pre, false); SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Post, true); } + if (m_pSayTeamCmd) + { + SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Pre, false); + SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Post, true); + } } void ChatTriggers::OnSourceModShutdown() { + if (m_pSayTeamCmd) + { + SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Post, true); + SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Pre, false); + } if (m_pSayCmd) { SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Post, true); diff --git a/core/ChatTriggers.h b/core/ChatTriggers.h index b47a1eb6..926187f7 100644 --- a/core/ChatTriggers.h +++ b/core/ChatTriggers.h @@ -11,6 +11,7 @@ class ChatTriggers : public SMGlobalClass { public: ChatTriggers(); + ~ChatTriggers(); public: //SMGlobalClass void OnSourceModGameInitialized(); void OnSourceModShutdown(); @@ -29,6 +30,7 @@ private: bool ProcessTrigger(edict_t *pEdict, const char *args, bool is_quoted); private: ConCommand *m_pSayCmd; + ConCommand *m_pSayTeamCmd; char *m_PubTrigger; size_t m_PubTriggerSize; char *m_PrivTrigger;