User message functions now use SourceMM 1.4's new API

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40704
This commit is contained in:
Scott Ehlert 2007-04-15 05:43:43 +00:00
parent 93be4e29b8
commit 43856e7dc4
4 changed files with 11 additions and 43 deletions

View File

@ -19,8 +19,6 @@ UserMessages g_UserMsgs;
SH_DECL_HOOK2(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int); SH_DECL_HOOK2(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int);
SH_DECL_HOOK0_void(IVEngineServer, MessageEnd, SH_NOATTRIB, 0); 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) UserMessages::UserMessages() : m_InterceptBuffer(m_pBase, 2500)
{ {
m_Names = sm_trie_create(); m_Names = sm_trie_create();
@ -63,35 +61,20 @@ void UserMessages::OnSourceModAllShutdown()
int UserMessages::GetMessageIndex(const char *msg) int UserMessages::GetMessageIndex(const char *msg)
{ {
int msgid; int msgid;
if (!sm_trie_retrieve(m_Names, msg, reinterpret_cast<void **>(&msgid))) if (!sm_trie_retrieve(m_Names, msg, reinterpret_cast<void **>(&msgid)))
{ {
char buf[255]; msgid = g_SMAPI->FindUserMessage(msg);
int dummy;
msgid = 0;
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<void *>(msgid));
{
sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
return msgid;
}
msgid++;
} }
return INVALID_MESSAGE_ID;
} }
return msgid; 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 *UserMessages::StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags)
{ {
bf_write *buffer; bf_write *buffer;

View File

@ -48,7 +48,6 @@ public: //SMGlobalClass
void OnSourceModAllShutdown(); void OnSourceModAllShutdown();
public: //IUserMessages public: //IUserMessages
int GetMessageIndex(const char *msg); 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 HookUserMessage(int msg_id, IUserMessageListener *pListener, bool intercept=false);
bool UnhookUserMessage(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); bf_write *StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags);

View File

@ -303,28 +303,22 @@ static UsrMessageNatives s_UsrMessageNatives;
static cell_t smn_GetUserMessageId(IPluginContext *pCtx, const cell_t *params) static cell_t smn_GetUserMessageId(IPluginContext *pCtx, const cell_t *params)
{ {
char *msgname; char *msgname;
int err; pCtx->LocalToString(params[1], &msgname);
if ((err=pCtx->LocalToString(params[1], &msgname)) != SP_ERROR_NONE)
{
pCtx->ThrowNativeErrorEx(err, NULL);
return 0;
}
return g_UserMsgs.GetMessageIndex(msgname); return g_UserMsgs.GetMessageIndex(msgname);
} }
static cell_t smn_GetUserMessageName(IPluginContext *pCtx, const cell_t *params) 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 (msgname == NULL)
if (!g_UserMsgs.GetMessageName(params[1], msgname, params[3]))
{ {
msgname = "";
return 0; return 0;
} }
pCtx->StringToLocalUTF8(params[2], params[3], msgname, NULL);
return 1; return 1;
} }
@ -332,7 +326,7 @@ static cell_t smn_StartMessage(IPluginContext *pCtx, const cell_t *params)
{ {
char *msgname; char *msgname;
cell_t *cl_array; cell_t *cl_array;
int msgid, err; int msgid;
bf_write *pBitBuf; bf_write *pBitBuf;
if (g_IsMsgInExec) 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"); 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->LocalToString(params[1], &msgname);
{
pCtx->ThrowNativeErrorEx(err, NULL);
return 0;
}
if ((msgid=g_UserMsgs.GetMessageIndex(msgname)) == INVALID_MESSAGE_ID) if ((msgid=g_UserMsgs.GetMessageIndex(msgname)) == INVALID_MESSAGE_ID)
{ {

View File

@ -97,10 +97,6 @@ namespace SourceMod
public: public:
/** /**
* @brief Finds a message id by name. * @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. * @param msg Case-sensitive string containing the message.
* @return A message index, or -1 on failure. * @return A message index, or -1 on failure.