New Usermessage system

Official Announcements about Source.Python.
freddukes
Developer
Posts: 29
Joined: Mon Nov 19, 2012 10:12 pm

New Usermessage system

Postby freddukes » Wed Jan 23, 2013 11:45 pm

Just implemented the protobuf changes to CS:GO that happened today. It will require a python code update, but until the libraries are updated, you should be able to run the new usermessages with the following information.

Now, rather than passing in message IDs / strings, you create a specific message instance. These instances will be from classes which are game specific. Hopefully Python libraries should be able to hide this implantation. The CS:GO specific classes are as follows:

Code: Select all

CCSUsrMsg_AchievementEvent
CCSUsrMsg_AdjustMoney
CCSUsrMsg_AmmoDenied
CCSUsrMsg_BarTime
CCSUsrMsg_CallVoteFailed
CCSUsrMsg_ClientInfo
CCSUsrMsg_CloseCaption
CCSUsrMsg_CloseCaptionDirect
CCSUsrMsg_CurrentTimescale
CCSUsrMsg_Damage
CCSUsrMsg_DesiredTimescale
CCSUsrMsg_DisconnectToLobby
CCSUsrMsg_DisplayInventory
CCSUsrMsg_Fade
CCSUsrMsg_GameTitle
CCSUsrMsg_Geiger
CCSUsrMsg_HintText
CCSUsrMsg_HudMsg
CCSUsrMsg_HudText
CCSUsrMsg_ItemDrop
CCSUsrMsg_ItemPickup
CCSUsrMsg_KeyHintText
CCSUsrMsg_KillCam
CCSUsrMsg_MarkAchievement
CCSUsrMsg_MatchEndConditions
CCSUsrMsg_MatchStatsUpdate
CCSUsrMsg_PlayerStatsUpdate
CCSUsrMsg_PlayerStatsUpdate_Stat
CCSUsrMsg_ProcessSpottedEntityUpdate
CCSUsrMsg_ProcessSpottedEntityUpdate_SpottedEntityUpdate
CCSUsrMsg_RadioText
CCSUsrMsg_RawAudio
CCSUsrMsg_ReloadEffect
CCSUsrMsg_RequestEloBracketInfo
CCSUsrMsg_RequestState
CCSUsrMsg_ResetHud
CCSUsrMsg_Rumble
CCSUsrMsg_SayText
CCSUsrMsg_SayText2
CCSUsrMsg_SendAudio
CCSUsrMsg_SendLastKillerDamageToClient
CCSUsrMsg_ServerRankRevealAll
CCSUsrMsg_ServerRankUpdate
CCSUsrMsg_ServerRankUpdate_RankUpdate
CCSUsrMsg_SetEloBracketInfo
CCSUsrMsg_SetPlayerEloDisplayBracket
CCSUsrMsg_Shake
CCSUsrMsg_ShowMenu
CCSUsrMsg_StopSpectatorMode
CCSUsrMsg_TextMsg
CCSUsrMsg_Train
CCSUsrMsg_VGUIMenu
CCSUsrMsg_VGUIMenu_Subkey
CCSUsrMsg_VoiceMask
CCSUsrMsg_VoiceMask_PlayerMask
CCSUsrMsg_VoteFailed
CCSUsrMsg_VotePass
CCSUsrMsg_VoteSetup
CCSUsrMsg_VoteStart
CCSUsrMsg_WarmupHasEnded
CCSUsrMsg_XRankGet
CCSUsrMsg_XRankUpd


Each class will have their own separate properties. This means you'll no longer be calling "Write*" commands such as "WriteByte" or "WriteChar". Instead you can access the properties directly.

The last change to note is you no longer have to "start" and "end" user messages. Now the whole process relies on creating an instance, and passing it to the game engine. A new engine function exists to process this:

IVEngineServer.SendUserMessage(IRecipientFilter, message_id, message_instance)

The IDs differ to the old IDs. The new IDs are as follows:

Syntax: Select all

enum ECstrike15UserMessages {
CS_UM_VGUIMenu = 1,
CS_UM_Geiger = 2,
CS_UM_Train = 3,
CS_UM_HudText = 4,
CS_UM_SayText = 5,
CS_UM_SayText2 = 6,
CS_UM_TextMsg = 7,
CS_UM_HudMsg = 8,
CS_UM_ResetHud = 9,
CS_UM_GameTitle = 10,
CS_UM_Shake = 12,
CS_UM_Fade = 13,
CS_UM_Rumble = 14,
CS_UM_CloseCaption = 15,
CS_UM_CloseCaptionDirect = 16,
CS_UM_SendAudio = 17,
CS_UM_RawAudio = 18,
CS_UM_VoiceMask = 19,
CS_UM_RequestState = 20,
CS_UM_Damage = 21,
CS_UM_RadioText = 22,
CS_UM_HintText = 23,
CS_UM_KeyHintText = 24,
CS_UM_ProcessSpottedEntityUpdate = 25,
CS_UM_ReloadEffect = 26,
CS_UM_AdjustMoney = 27,
CS_UM_UpdateTeamMoney = 28,
CS_UM_StopSpectatorMode = 29,
CS_UM_KillCam = 30,
CS_UM_DesiredTimescale = 31,
CS_UM_CurrentTimescale = 32,
CS_UM_AchievementEvent = 33,
CS_UM_MatchEndConditions = 34,
CS_UM_DisconnectToLobby = 35,
CS_UM_PlayerStatsUpdate = 36,
CS_UM_DisplayInventory = 37,
CS_UM_WarmupHasEnded = 38,
CS_UM_ClientInfo = 39,
CS_UM_XRankGet = 40,
CS_UM_XRankUpd = 41,
CS_UM_SetPlayerEloDisplayBracket = 42,
CS_UM_RequestEloBracketInfo = 43,
CS_UM_SetEloBracketInfo = 44,
CS_UM_CallVoteFailed = 45,
CS_UM_VoteStart = 46,
CS_UM_VotePass = 47,
CS_UM_VoteFailed = 48,
CS_UM_VoteSetup = 49,
CS_UM_ServerRankRevealAll = 50,
CS_UM_SendLastKillerDamageToClient = 51,
CS_UM_ServerRankUpdate = 52,
CS_UM_ItemPickup = 53,
CS_UM_ShowMenu = 54,
CS_UM_BarTime = 55,
CS_UM_AmmoDenied = 56,
CS_UM_MarkAchievement = 57,
CS_UM_MatchStatsUpdate = 58,
CS_UM_ItemDrop = 59
};


These should also exist as global defines in Source.Usermessages, i.e.

Syntax: Select all

from Source import Usermessages

print("The ID of SayText2 is %d" % Usermessages.CS_UM_SayText2)


Although this has been untested.

The quick script I used to test this was as follows:

Syntax: Select all

from Source import Usermessages
from Source import Player
from core import GameEngine
from events import Event

from core.cvar import ServerVar
# Filters
from filters.recipients import get_recipients


@Event
def player_say(GameEvent):
if GameEvent.GetString("text") == "!test":
# Create the SayText2 instance
saytext2 = Usermessages.CCSUsrMsg_SayText2()
# Assign the entity ID to use in the string manipulation. This is to change the colour code from blue to red etc
saytext2.set_ent_idx(Player.IndexOfUserid(GameEvent.GetInt("userid")))
# Text to send
saytext2.set_msg_name("Test")
# Send to team-only? (I think that's what this boolean is for)
saytext2.set_chat(False)
# Client is expecting 4 parameters, so we need to add in an extra parameter to be serialized to prevent client crashes
saytext2.add_params('')
if ServerVar('sp_engine_ver').GetInt() == 3:
# This method only exists in CS:GO engine, this will be an invalid call in older engines
# 6 = SayText2
GameEngine.SendUserMessage(get_recipients(saytext2.ent_idx), 6, saytext2)


Note: This is highly untested, and it will probably require much more work. Hopefully you won't have too long until someone who knows what they're doing (Satoon?) updates the python side so you shouldn't have to mess with this stuff directly. This is just the first pass, so I'm sure many bugs / improvements will follow shortly.

-freddukes
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Jan 24, 2013 1:26 am

Awesome job, freddukes, I'll get started on these changes, finally!!! Wish Valve would have not messed up the versions of the beta...

Satoon
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Jan 24, 2013 4:15 am

I totally missed your first pass about protobuf few days ago, nice work!

L'In20Cible
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Feb 01, 2013 5:09 pm

Good to see this happening after being away for a while. I like it! :)

Return to “News & Announcements”

Who is online

Users browsing this forum: No registered users and 5 guests