diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 20948b10..61b1dc5e 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -244,13 +244,19 @@ void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset) } } -void CHalfLife2::TextMsg(int client, int dest, const char *msg) +bool CHalfLife2::TextMsg(int client, int dest, const char *msg) { bf_write *pBitBuf = NULL; cell_t players[] = {client}; - pBitBuf = g_UserMsgs.StartMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE); + if ((pBitBuf = g_UserMsgs.StartMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL) + { + return false; + } + pBitBuf->WriteByte(dest); pBitBuf->WriteString(msg); g_UserMsgs.EndMessage(); + + return true; } diff --git a/core/HalfLife2.h b/core/HalfLife2.h index 5ab6ab82..2b0bc92b 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -56,7 +56,7 @@ public: //IGameHelpers ServerClass *FindServerClass(const char *classname); typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset); void SetEdictStateChanged(edict_t *pEdict, unsigned short offset); - void TextMsg(int client, int dest, const char *msg); + bool TextMsg(int client, int dest, const char *msg); private: DataTableInfo *_FindServerClass(const char *classname); private: diff --git a/core/UserMessages.cpp b/core/UserMessages.cpp index 6583418a..1241462e 100644 --- a/core/UserMessages.cpp +++ b/core/UserMessages.cpp @@ -330,6 +330,8 @@ void UserMessages::OnMessageEnd_Post() iter++; } + m_InHook = false; + pList = &m_msgHooks[m_CurId]; for (iter=pList->begin(); iter!=pList->end(); ) { @@ -348,8 +350,6 @@ void UserMessages::OnMessageEnd_Post() pInfo->IsHooked = false; iter++; } - - m_InHook = false; } void UserMessages::OnMessageEnd_Pre() diff --git a/core/smn_halflife.cpp b/core/smn_halflife.cpp index 1ce44b47..d1b2b7b9 100644 --- a/core/smn_halflife.cpp +++ b/core/smn_halflife.cpp @@ -284,7 +284,10 @@ static cell_t PrintToChat(IPluginContext *pContext, const cell_t *params) return 0; } - g_HL2.TextMsg(client, HUD_PRINTTALK, buffer); + if (!g_HL2.TextMsg(client, HUD_PRINTTALK, buffer)) + { + return pContext->ThrowNativeError("Could not send a usermessage"); + } return 1; } @@ -315,7 +318,10 @@ static cell_t PrintCenterText(IPluginContext *pContext, const cell_t *params) return 0; } - g_HL2.TextMsg(client, HUD_PRINTCENTER, buffer); + if (!g_HL2.TextMsg(client, HUD_PRINTCENTER, buffer)) + { + return pContext->ThrowNativeError("Could not send a usermessage"); + } return 1; } diff --git a/public/IGameHelpers.h b/public/IGameHelpers.h index 0d0de5b3..41d04a67 100644 --- a/public/IGameHelpers.h +++ b/public/IGameHelpers.h @@ -95,8 +95,9 @@ namespace SourceMod * @param client Client index. * @param dest Destination on the HUD. * @param msg Message to send. + * @return True on success, false on failure. */ - virtual void TextMsg(int client, int dest, const char *msg) =0; + virtual bool TextMsg(int client, int dest, const char *msg) =0; }; }