core/UserMessages.cpp
changeset 765 d78dd115f23a
parent 698 8c68fc683dba
child 766 c9195659604c
     1.1 --- a/core/UserMessages.cpp	Sat May 12 02:14:12 2007 +0000
     1.2 +++ b/core/UserMessages.cpp	Sat May 12 04:47:58 2007 +0000
     1.3 @@ -13,6 +13,7 @@
     1.4   */
     1.5  
     1.6  #include "UserMessages.h"
     1.7 +#include "sm_stringutil.h"
     1.8  
     1.9  UserMessages g_UserMsgs;
    1.10  
    1.11 @@ -41,6 +42,12 @@
    1.12  	m_FreeListeners.popall();
    1.13  }
    1.14  
    1.15 +void UserMessages::OnSourceModStartup(bool late)
    1.16 +{
    1.17 +	/* -1 means SourceMM was unable to get the user message list */
    1.18 +	m_FallbackSearch = (g_SMAPI->GetUserMessageCount() == -1);
    1.19 +}
    1.20 +
    1.21  void UserMessages::OnSourceModAllInitialized()
    1.22  {
    1.23  	g_ShareSys.AddInterface(NULL, this);
    1.24 @@ -64,6 +71,23 @@
    1.25  
    1.26  	if (!sm_trie_retrieve(m_Names, msg, reinterpret_cast<void **>(&msgid)))
    1.27  	{
    1.28 +		if (m_FallbackSearch)
    1.29 +		{
    1.30 +			char msgbuf[64];
    1.31 +			int size;
    1.32 +			msgid = 0;
    1.33 +
    1.34 +			while (gamedll->GetUserMessageInfo(msgid, msgbuf, sizeof(msgbuf), size))
    1.35 +			{
    1.36 +				if (strcmp(msgbuf, msg) == 0)
    1.37 +				{
    1.38 +					sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
    1.39 +					return msgid;
    1.40 +				}
    1.41 +				msgid++;
    1.42 +			}
    1.43 +		}
    1.44 +
    1.45  		msgid = g_SMAPI->FindUserMessage(msg);
    1.46  
    1.47  		if (msgid != INVALID_MESSAGE_ID)
    1.48 @@ -75,6 +99,26 @@
    1.49  	return msgid;
    1.50  }
    1.51  
    1.52 +bool UserMessages::GetMessageName(int msgid, char *buffer, size_t maxlength) const
    1.53 +{
    1.54 +	if (m_FallbackSearch)
    1.55 +	{
    1.56 +		printf("hello");
    1.57 +		int size;
    1.58 +		return gamedll->GetUserMessageInfo(msgid, buffer, maxlength, size);
    1.59 +	}
    1.60 +	printf("hello2");
    1.61 +	const char *msg = g_SMAPI->GetUserMessage(msgid);
    1.62 +
    1.63 +	if (msg)
    1.64 +	{
    1.65 +		strncopy(buffer, msg, maxlength);
    1.66 +		return true;
    1.67 +	}
    1.68 +
    1.69 +	return false;
    1.70 +}
    1.71 +
    1.72  bf_write *UserMessages::StartMessage(int msg_id, cell_t players[], unsigned int playersNum, int flags)
    1.73  {
    1.74  	bf_write *buffer;