From 43856e7dc47c4aebb3dd569314c96b7007a2434b Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Sun, 15 Apr 2007 05:43:43 +0000 Subject: [PATCH] User message functions now use SourceMM 1.4's new API --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40704 --- core/UserMessages.cpp | 25 ++++--------------------- core/UserMessages.h | 1 - core/smn_usermsgs.cpp | 24 +++++++----------------- public/IUserMessages.h | 4 ---- 4 files changed, 11 insertions(+), 43 deletions(-) diff --git a/core/UserMessages.cpp b/core/UserMessages.cpp index 7c21c88f..32b0d4ca 100644 --- a/core/UserMessages.cpp +++ b/core/UserMessages.cpp @@ -19,8 +19,6 @@ UserMessages g_UserMsgs; SH_DECL_HOOK2(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int); SH_DECL_HOOK0_void(IVEngineServer, MessageEnd, SH_NOATTRIB, 0); -//:TODO: USE NEW MM IFACE TO SEARCH FOR MESSAGE NAMES ETC! faluco--> i'll do this when i have some spare time - UserMessages::UserMessages() : m_InterceptBuffer(m_pBase, 2500) { m_Names = sm_trie_create(); @@ -63,35 +61,20 @@ void UserMessages::OnSourceModAllShutdown() int UserMessages::GetMessageIndex(const char *msg) { int msgid; + if (!sm_trie_retrieve(m_Names, msg, reinterpret_cast(&msgid))) { - char buf[255]; - int dummy; - msgid = 0; + msgid = g_SMAPI->FindUserMessage(msg); - while (gamedll->GetUserMessageInfo(msgid, buf, sizeof(buf), dummy)) + if (msgid != INVALID_MESSAGE_ID) { - if (strcmp(msg, buf) == 0) - { - sm_trie_insert(m_Names, msg, reinterpret_cast(msgid)); - return msgid; - } - msgid++; + sm_trie_insert(m_Names, msg, reinterpret_cast(msgid)); } - - return INVALID_MESSAGE_ID; } return msgid; } -bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlen) const -{ - int dummy; - - return gamedll->GetUserMessageInfo(msgid, buffer, maxlen, dummy); -} - bf_write *UserMessages::StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags) { bf_write *buffer; diff --git a/core/UserMessages.h b/core/UserMessages.h index 2d3b1d9b..17571479 100644 --- a/core/UserMessages.h +++ b/core/UserMessages.h @@ -48,7 +48,6 @@ public: //SMGlobalClass void OnSourceModAllShutdown(); public: //IUserMessages int GetMessageIndex(const char *msg); - bool GetMessageName(int msgid, char *buffer, size_t maxlen) const; bool HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false); bool UnhookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false); bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags); diff --git a/core/smn_usermsgs.cpp b/core/smn_usermsgs.cpp index 1d40e90a..f7570802 100644 --- a/core/smn_usermsgs.cpp +++ b/core/smn_usermsgs.cpp @@ -303,28 +303,22 @@ static UsrMessageNatives s_UsrMessageNatives; static cell_t smn_GetUserMessageId(IPluginContext *pCtx, const cell_t *params) { char *msgname; - int err; - if ((err=pCtx->LocalToString(params[1], &msgname)) != SP_ERROR_NONE) - { - pCtx->ThrowNativeErrorEx(err, NULL); - return 0; - } + pCtx->LocalToString(params[1], &msgname); return g_UserMsgs.GetMessageIndex(msgname); } static cell_t smn_GetUserMessageName(IPluginContext *pCtx, const cell_t *params) { - char *msgname; + const char *msgname = g_SMAPI->GetUserMessage(params[1]); - pCtx->LocalToPhysAddr(params[2], (cell_t **)&msgname); - - if (!g_UserMsgs.GetMessageName(params[1], msgname, params[3])) + if (msgname == NULL) { - msgname = ""; return 0; } + pCtx->StringToLocalUTF8(params[2], params[3], msgname, NULL); + return 1; } @@ -332,7 +326,7 @@ static cell_t smn_StartMessage(IPluginContext *pCtx, const cell_t *params) { char *msgname; cell_t *cl_array; - int msgid, err; + int msgid; bf_write *pBitBuf; if (g_IsMsgInExec) @@ -340,11 +334,7 @@ static cell_t smn_StartMessage(IPluginContext *pCtx, const cell_t *params) return pCtx->ThrowNativeError("Unable to execute a new message, there is already one in progress"); } - if ((err=pCtx->LocalToString(params[1], &msgname)) != SP_ERROR_NONE) - { - pCtx->ThrowNativeErrorEx(err, NULL); - return 0; - } + pCtx->LocalToString(params[1], &msgname); if ((msgid=g_UserMsgs.GetMessageIndex(msgname)) == INVALID_MESSAGE_ID) { diff --git a/public/IUserMessages.h b/public/IUserMessages.h index 52e22648..1362482f 100644 --- a/public/IUserMessages.h +++ b/public/IUserMessages.h @@ -97,10 +97,6 @@ namespace SourceMod public: /** * @brief Finds a message id by name. - * - * Note: due to a bug in Valve's earlier SDK versions, this - * may cause crashes alongside IServerGameDLL003 if the message is - * not found. * * @param msg Case-sensitive string containing the message. * @return A message index, or -1 on failure.