Raised This Month: $ Target: $400
 0% 

[CSGO] UserMessageBegin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ajaxx
Senior Member
Join Date: Oct 2009
Old 01-31-2013 , 23:22   [CSGO] UserMessageBegin
Reply With Quote #1

Has IVEngineServer.UserMessageBeing() in eiface.h gone away? I’ve been using it as


Code:
msg = engine->UserMessageBegin((IRecipientFilter *)&f, 3, "");
to display user messages. What is suggested I use in it’s place?
Ajaxx is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-01-2013 , 07:40   Re: [CSGO] UserMessageBegin
Reply With Quote #2

Yes, it's gone in CS:GO.

Instead of UserMessageBegin, write data to returned bitbuf, EndMessage, it's now:
Create new message, call engine->SendUserMessage.

The new messages use Google's protobuf format. You'll need to include common/protobuf-2.3.0/src and link libprotobuf from lib/. The generated protobuf files specific to the CS:GO engine and game also need to be compiled in from public/engine/protobuf and public/game/shared/csgo/protobuf/ and there are some helpers in the latter to help map message descriptors to message ids.

A good example can be found in this post: https://forums.alliedmods.net/showthread.php?t=206803
psychonic is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-04-2013 , 22:29   Re: [CSGO] UserMessageBegin
Reply With Quote #3

Thank you for your detailed, as always, explanation. I’m afraid I’m still not getting it. I included common/protobuf-2.3.0/src in C/C++->General->Additional Include Directories, I linked \lib\win32\release\vs2010\libprotobuf.lib in Linker->Input->Additional Dependencies.

I’m not following the example you suggested, it seems to be for a menu. This is the code I’d like to replace.

Code:
void StubPlugin::MessagePlayer(int pIndex, char* text)
{
	char message[256];
	sprintf(message, text);

	bf_write *msg;
	MRecipientFilter f;
	f.AddRecipient(pIndex);
	msg = engine->UserMessageBegin((IRecipientFilter *)&f, 3, "");
	msg->WriteByte(pIndex);
	msg->WriteString(message);
	msg->WriteByte(true);
	engine->MessageEnd();
}

How do I compile in the generated protobuf files, and how do I expose the protobuf methods in code?
Ajaxx is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-04-2013 , 22:57   Re: [CSGO] UserMessageBegin
Reply With Quote #4

Quote:
Originally Posted by Ajaxx View Post
Thank you for your detailed, as always, explanation. I’m afraid I’m still not getting it. I included common/protobuf-2.3.0/src in C/C++->General->Additional Include Directories, I linked \lib\win32\release\vs2010\libprotobuf.lib in Linker->Input->Additional Dependencies.

I’m not following the example you suggested, it seems to be for a menu. This is the code I’d like to replace.

Code:
void StubPlugin::MessagePlayer(int pIndex, char* text)
{
	char message[256];
	sprintf(message, text);

	bf_write *msg;
	MRecipientFilter f;
	f.AddRecipient(pIndex);
	msg = engine->UserMessageBegin((IRecipientFilter *)&f, 3, "");
	msg->WriteByte(pIndex);
	msg->WriteString(message);
	msg->WriteByte(true);
	engine->MessageEnd();
}

How do I compile in the generated protobuf files, and how do I expose the protobuf methods in code?
Add the following to paths to your include paths as well:
public/engine/protobuf
public/game/shared/csgo/protobuf


Then add:
Code:
#include <cstrike15_usermessage_helpers.h>
Your code then becomes:
Code:
void StubPlugin::MessagePlayer(int pIndex, char* text)
{
	char message[256];
	sprintf(message, text);

	google::protobuf::Message *msg = g_Cstrike15UsermessageHelpers.GetPrototype(CS_UM_SayText)->New();
	MRecipientFilter f;
	f.AddRecipient(pIndex);
	msg->set_ent_idx(pIndex);
	msg->set_text(message);
	msg->set_chat(true);
	engine->SendUserMessage(f, CS_UM_SayText, *msg);
	delete msg;
}
Please pardon any typos. Vbulletin's edit box doesn't make a great IDE and I'm just going off of headers.
psychonic is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-05-2013 , 00:10   Re: [CSGO] UserMessageBegin
Reply With Quote #5

I must be doing something else wrong. I’ve added the includes and the code, but I’m getting the following errors:

Code:
error C2039: 'set_ent_idx' : is not a member of 'google::protobuf::Message'
error C2039: 'set_text' : is not a member of 'google::protobuf::Message'
error C2039: 'set_chat' : is not a member of 'google::protobuf::Message'
Ajaxx is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 02-05-2013 , 00:52   Re: [CSGO] UserMessageBegin
Reply With Quote #6

With your help, I’m able to compile using this line. Thank you!
Code:
CCSUsrMsg_SayText* msg = (CCSUsrMsg_SayText *)g_Cstrike15UsermessageHelpers.GetPrototype(CS_UM_SayText)->New();
Ajaxx is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-05-2013 , 07:07   Re: [CSGO] UserMessageBegin
Reply With Quote #7

Quote:
Originally Posted by Ajaxx View Post
With your help, I’m able to compile using this line. Thank you!
Code:
CCSUsrMsg_SayText* msg = (CCSUsrMsg_SayText *)g_Cstrike15UsermessageHelpers.GetPrototype(CS_UM_SayText)->New();
Quote:
Originally Posted by Ajaxx View Post
I must be doing something else wrong. I’ve added the includes and the code, but I’m getting the following errors:

Code:
error C2039: 'set_ent_idx' : is not a member of 'google::protobuf::Message'
error C2039: 'set_text' : is not a member of 'google::protobuf::Message'
error C2039: 'set_chat' : is not a member of 'google::protobuf::Message'
Ah, indeed. I had forgotten the cast.

Also forgot to mention that the following files need to be compiled into the project:
public/game/shared/csgo/protobuf/cstrike15_usermessage_helpers.cpp
public/game/shared/csgo/protobuf/cstrike15_usermessages.pb.cc
public/engine/protobuf/netmessages.pb.cc

Last edited by psychonic; 02-05-2013 at 07:07.
psychonic is offline
Martek
Junior Member
Join Date: Aug 2012
Old 02-05-2013 , 10:34   Re: [CSGO] UserMessageBegin
Reply With Quote #8

If I compile everything, I get Linker erros like:

error LNK2038: Konflikt ermittelt für "_MSC_VER": Der Wert "1600" stimmt nicht mit dem Wert "1700" in netmessages.pb.obj überein.

In English this intents that some files are not compiled with VS2012 and some are.

Is this because the libprotobuf.lib was compiled with VS2010 so that I also need to compile it with that version of Visual studio or is it more like a problem of my other project files?

Kind regards
Martek
Martek is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-05-2013 , 11:08   Re: [CSGO] UserMessageBegin
Reply With Quote #9

Quote:
Originally Posted by Martek View Post
If I compile everything, I get Linker erros like:

error LNK2038: Konflikt ermittelt für "_MSC_VER": Der Wert "1600" stimmt nicht mit dem Wert "1700" in netmessages.pb.obj überein.

In English this intents that some files are not compiled with VS2012 and some are.

Is this because the libprotobuf.lib was compiled with VS2010 so that I also need to compile it with that version of Visual studio or is it more like a problem of my other project files?

Kind regards
Martek
You can either change your Platform Toolset in your plugin's project configuration to VS 2010 :




Or you can compile your own copy of libprotobuf. See the wiki article Compiling libprotobuf.

We may put other versions in the sdk at some point. I just haven't had time yet.

Last edited by psychonic; 02-05-2013 at 11:09.
psychonic is offline
Martek
Junior Member
Join Date: Aug 2012
Old 02-05-2013 , 11:34   Re: [CSGO] UserMessageBegin
Reply With Quote #10

Thanks for the fast answere. I will have to use the VS2010 toolset I guess because also the tier1 lib is not compatible as it seems.

On the wiki I can not find information on how to compile that lib so I will go the easier way.
Martek is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode