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:
		
							parent
							
								
									93be4e29b8
								
							
						
					
					
						commit
						43856e7dc4
					
				@ -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<void **>(&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<void *>(msgid));
 | 
			
		||||
				return msgid;
 | 
			
		||||
			}
 | 
			
		||||
			msgid++;
 | 
			
		||||
			sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(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;
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user