core/HalfLife2.cpp
changeset 3743 a98686a77974
parent 3695 74cd59113b43
child 3763 336283ba3a38
     1.1 --- a/core/HalfLife2.cpp	Mon Jan 07 09:09:14 2013 -0500
     1.2 +++ b/core/HalfLife2.cpp	Tue Jan 22 21:43:12 2013 -0500
     1.3 @@ -42,6 +42,10 @@
     1.4  #include "logic_bridge.h"
     1.5  #include <tier0/mem.h>
     1.6  
     1.7 +#if SOURCE_ENGINE == SE_CSGO
     1.8 +#include <cstrike15_usermessages.pb.h>
     1.9 +#endif
    1.10 +
    1.11  
    1.12  typedef ICommandLine *(*FakeGetCommandLine)();
    1.13  
    1.14 @@ -487,7 +491,9 @@
    1.15  
    1.16  bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
    1.17  {
    1.18 +#if SOURCE_ENGINE != SE_CSGO
    1.19  	bf_write *pBitBuf = NULL;
    1.20 +#endif
    1.21  	cell_t players[] = {client};
    1.22  
    1.23  	if (dest == HUD_PRINTTALK)
    1.24 @@ -500,7 +506,18 @@
    1.25  			char buffer[192];
    1.26  			UTIL_Format(buffer, sizeof(buffer), "%s\1\n", msg);
    1.27  
    1.28 -			if ((pBitBuf = g_UserMsgs.StartMessage(m_SayTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.29 +#if SOURCE_ENGINE == SE_CSGO
    1.30 +			CCSUsrMsg_SayText *pMsg;
    1.31 +			if ((pMsg = (CCSUsrMsg_SayText *)g_UserMsgs.StartProtobufMessage(m_SayTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.32 +			{
    1.33 +				return false;
    1.34 +			}
    1.35 +
    1.36 +			pMsg->set_ent_idx(0);
    1.37 +			pMsg->set_text(buffer);
    1.38 +			pMsg->set_chat(false);
    1.39 +#else
    1.40 +			if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_SayTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.41  			{
    1.42  				return false;
    1.43  			}
    1.44 @@ -508,6 +525,7 @@
    1.45  			pBitBuf->WriteByte(0);
    1.46  			pBitBuf->WriteString(buffer);
    1.47  			pBitBuf->WriteByte(1);
    1.48 +#endif
    1.49  
    1.50  			g_UserMsgs.EndMessage();
    1.51  
    1.52 @@ -515,13 +533,29 @@
    1.53  		}
    1.54  	}
    1.55  
    1.56 -	if ((pBitBuf = g_UserMsgs.StartMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.57 +#if SOURCE_ENGINE == SE_CSGO
    1.58 +	CCSUsrMsg_TextMsg *pMsg;
    1.59 +	if ((pMsg = (CCSUsrMsg_TextMsg *)g_UserMsgs.StartProtobufMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.60 +	{
    1.61 +		return false;
    1.62 +	}
    1.63 +
    1.64 +	// Client tries to read all 5 'params' and will crash if less
    1.65 +	pMsg->set_msg_dst(dest);
    1.66 +	pMsg->add_params(msg);
    1.67 +	pMsg->add_params("");
    1.68 +	pMsg->add_params("");
    1.69 +	pMsg->add_params("");
    1.70 +	pMsg->add_params("");
    1.71 +#else
    1.72 +	if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.73  	{
    1.74  		return false;
    1.75  	}
    1.76  
    1.77  	pBitBuf->WriteByte(dest);
    1.78  	pBitBuf->WriteString(msg);
    1.79 +#endif
    1.80  
    1.81  	g_UserMsgs.EndMessage();
    1.82  
    1.83 @@ -530,10 +564,20 @@
    1.84  
    1.85  bool CHalfLife2::HintTextMsg(int client, const char *msg)
    1.86  {
    1.87 -	bf_write *pBitBuf = NULL;
    1.88  	cell_t players[] = {client};
    1.89  
    1.90 -	if ((pBitBuf = g_UserMsgs.StartMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.91 +#if SOURCE_ENGINE == SE_CSGO
    1.92 +	CCSUsrMsg_HintText *pMsg;
    1.93 +	if ((pMsg = (CCSUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
    1.94 +	{
    1.95 +		return false;
    1.96 +	}
    1.97 +
    1.98 +	pMsg->set_text(msg);
    1.99 +#else
   1.100 +	bf_write *pBitBuf = NULL;
   1.101 +
   1.102 +	if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
   1.103  	{
   1.104  		return false;
   1.105  	}
   1.106 @@ -544,6 +588,7 @@
   1.107  		pBitBuf->WriteByte(1);
   1.108  	}
   1.109  	pBitBuf->WriteString(msg);
   1.110 +#endif
   1.111  	g_UserMsgs.EndMessage();
   1.112  
   1.113  	return true;
   1.114 @@ -551,9 +596,18 @@
   1.115  
   1.116  bool CHalfLife2::HintTextMsg(cell_t *players, int count, const char *msg)
   1.117  {
   1.118 +#if SOURCE_ENGINE == SE_CSGO
   1.119 +	CCSUsrMsg_HintText *pMsg;
   1.120 +	if ((pMsg = (CCSUsrMsg_HintText *)g_UserMsgs.StartProtobufMessage(m_HinTextMsg, players, count, USERMSG_RELIABLE)) == NULL)
   1.121 +	{
   1.122 +		return false;
   1.123 +	}
   1.124 +
   1.125 +	pMsg->set_text(msg);
   1.126 +#else
   1.127  	bf_write *pBitBuf = NULL;
   1.128  
   1.129 -	if ((pBitBuf = g_UserMsgs.StartMessage(m_HinTextMsg, players, count, USERMSG_RELIABLE)) == NULL)
   1.130 +	if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_HinTextMsg, players, count, USERMSG_RELIABLE)) == NULL)
   1.131  	{
   1.132  		return false;
   1.133  	}
   1.134 @@ -564,6 +618,8 @@
   1.135  		pBitBuf->WriteByte(1);
   1.136  	}
   1.137  	pBitBuf->WriteString(msg);
   1.138 +#endif
   1.139 +
   1.140  	g_UserMsgs.EndMessage();
   1.141  
   1.142  	return true;
   1.143 @@ -571,15 +627,23 @@
   1.144  
   1.145  bool CHalfLife2::ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show)
   1.146  {
   1.147 -	bf_write *pBitBuf = NULL;
   1.148  	KeyValues *SubKey = NULL;
   1.149  	int count = 0;
   1.150  	cell_t players[] = {client};
   1.151  
   1.152 -	if ((pBitBuf = g_UserMsgs.StartMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
   1.153 +#if SOURCE_ENGINE == SE_CSGO
   1.154 +	CCSUsrMsg_VGUIMenu *pMsg;
   1.155 +	if ((pMsg = (CCSUsrMsg_VGUIMenu *)g_UserMsgs.StartProtobufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
   1.156  	{
   1.157  		return false;
   1.158  	}
   1.159 +#else
   1.160 +	bf_write *pBitBuf = NULL;
   1.161 +	if ((pBitBuf = g_UserMsgs.StartBitBufMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
   1.162 +	{
   1.163 +		return false;
   1.164 +	}
   1.165 +#endif
   1.166  
   1.167  	if (data)
   1.168  	{
   1.169 @@ -592,6 +656,18 @@
   1.170  		SubKey = data->GetFirstSubKey();
   1.171  	}
   1.172  
   1.173 +#if SOURCE_ENGINE == SE_CSGO
   1.174 +	pMsg->set_name(name);
   1.175 +	pMsg->set_show(show);
   1.176 +
   1.177 +	while (SubKey)
   1.178 +	{
   1.179 +		CCSUsrMsg_VGUIMenu_Subkey *key = pMsg->add_subkeys();
   1.180 +		key->set_name(SubKey->GetName());
   1.181 +		key->set_str(SubKey->GetString());
   1.182 +		SubKey = SubKey->GetNextKey();
   1.183 +	}
   1.184 +#else
   1.185  	pBitBuf->WriteString(name);
   1.186  	pBitBuf->WriteByte((show) ? 1 : 0);
   1.187  	pBitBuf->WriteByte(count);
   1.188 @@ -601,6 +677,8 @@
   1.189  		pBitBuf->WriteString(SubKey->GetString());
   1.190  		SubKey = SubKey->GetNextKey();
   1.191  	}
   1.192 +#endif
   1.193 +
   1.194  	g_UserMsgs.EndMessage();
   1.195  
   1.196  	return true;