Skip to content

Commit 894aeb3

Browse files
authored
Merge pull request #559 from markus-wa/bullet-and-chat
2 parents 52e6194 + 715d9ac commit 894aeb3

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

pkg/demoinfocs/events/events.go

+14
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,20 @@ type HostageStateChanged struct {
399399
Hostage *common.Hostage
400400
}
401401

402+
// BulletDamage signals that a bullet did some damage.
403+
// Available only with CS2 demos after the 22/07/2024 update.
404+
type BulletDamage struct {
405+
Attacker *common.Player
406+
Victim *common.Player
407+
Distance float32
408+
DamageDirX float32
409+
DamageDirY float32
410+
DamageDirZ float32
411+
NumPenetrations int
412+
IsNoScope bool
413+
IsAttackerInAir bool
414+
}
415+
402416
// HitGroup is the type for the various HitGroupXYZ constants.
403417
//
404418
// See PlayerHurt.

pkg/demoinfocs/game_events.go

+17
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func newGameEventHandler(parser *parser, ignoreBombsiteIndexNotFound bool) gameE
208208
"bomb_pickup": delayIfNoPlayers(geh.bombPickup), // Bomb picked up
209209
"bomb_planted": delayIfNoPlayers(geh.bombPlanted), // Plant finished
210210
"bot_takeover": delay(geh.botTakeover), // Bot got taken over
211+
"bullet_damage": delayIfNoPlayers(geh.bulletDamage), // CS2 only
211212
"buytime_ended": nil, // Not actually end of buy time, seems to only be sent once per game at the start
212213
"choppers_incoming_warning": nil, // Helicopters are coming (Danger zone mode)
213214
"cs_intermission": nil, // Dunno, only in locally recorded (POV) demo
@@ -653,6 +654,22 @@ func (geh gameEventHandler) HostageRescuedAll(map[string]*msg.CSVCMsg_GameEventK
653654
geh.dispatch(events.HostageRescuedAll{})
654655
}
655656

657+
func (geh gameEventHandler) bulletDamage(data map[string]*msg.CSVCMsg_GameEventKeyT) {
658+
event := events.BulletDamage{
659+
Attacker: geh.playerByUserID32(data["attacker"].GetValShort()),
660+
Victim: geh.playerByUserID32(data["victim"].GetValShort()),
661+
Distance: data["distance"].GetValFloat(),
662+
DamageDirX: data["damage_dir_x"].GetValFloat(),
663+
DamageDirY: data["damage_dir_y"].GetValFloat(),
664+
DamageDirZ: data["damage_dir_z"].GetValFloat(),
665+
NumPenetrations: int(data["num_penetrations"].GetValShort()),
666+
IsNoScope: data["no_scope"].GetValBool(),
667+
IsAttackerInAir: data["in_air"].GetValBool(),
668+
}
669+
670+
geh.dispatch(event)
671+
}
672+
656673
func (geh gameEventHandler) playerConnect(data map[string]*msg.CSVCMsg_GameEventKeyT) {
657674
pl := common.PlayerInfo{
658675
UserID: int(data["userid"].GetValShort()),

pkg/demoinfocs/net_messages.go

+46
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,52 @@ func (p *parser) handleServerInfoS2(srvInfo *msgs2.CSVCMsg_ServerInfo) {
109109
})
110110
}
111111

112+
func (p *parser) handleMessageSayText(msg *msgs2.CUserMessageSayText) {
113+
p.eventDispatcher.Dispatch(events.SayText{
114+
EntIdx: int(msg.GetPlayerindex()),
115+
IsChat: msg.GetChat(),
116+
IsChatAll: false,
117+
Text: msg.GetText(),
118+
})
119+
}
120+
121+
func (p *parser) handleMessageSayText2(msg *msgs2.CUserMessageSayText2) {
122+
p.eventDispatcher.Dispatch(events.SayText2{
123+
EntIdx: int(msg.GetEntityindex()),
124+
IsChat: msg.GetChat(),
125+
IsChatAll: false,
126+
MsgName: msg.GetMessagename(),
127+
Params: []string{msg.GetParam1(), msg.GetParam2(), msg.GetParam3(), msg.GetParam4()},
128+
})
129+
130+
switch msg.GetMessagename() {
131+
case "Cstrike_Chat_All":
132+
fallthrough
133+
case "Cstrike_Chat_AllDead":
134+
sender := p.gameState.playersByEntityID[int(msg.GetEntityindex())]
135+
136+
p.eventDispatcher.Dispatch(events.ChatMessage{
137+
Sender: sender,
138+
Text: msg.GetParam2(),
139+
IsChatAll: false,
140+
})
141+
142+
case "#CSGO_Coach_Join_T": // Ignore these
143+
case "#CSGO_Coach_Join_CT":
144+
case "#Cstrike_Name_Change":
145+
case "Cstrike_Chat_T_Loc":
146+
case "Cstrike_Chat_CT_Loc":
147+
case "Cstrike_Chat_T_Dead":
148+
case "Cstrike_Chat_CT_Dead":
149+
150+
default:
151+
errMsg := fmt.Sprintf("skipped sending ChatMessageEvent for SayText2 with unknown MsgName %q", msg.GetMessagename())
152+
153+
p.eventDispatcher.Dispatch(events.ParserWarn{Message: errMsg})
154+
unassert.Error(errMsg)
155+
}
156+
}
157+
112158
func (p *parser) handleServerRankUpdate(msg *msgs2.CCSUsrMsg_ServerRankUpdate) {
113159
for _, v := range msg.RankUpdate {
114160
steamID32 := uint32(v.GetAccountId())

pkg/demoinfocs/parser.go

+2
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) Parser {
427427
p.msgDispatcher.RegisterHandler(p.handleUpdateStringTableS2)
428428
p.msgDispatcher.RegisterHandler(p.handleSetConVarS2)
429429
p.msgDispatcher.RegisterHandler(p.handleServerRankUpdate)
430+
p.msgDispatcher.RegisterHandler(p.handleMessageSayText)
431+
p.msgDispatcher.RegisterHandler(p.handleMessageSayText2)
430432

431433
if config.MsgQueueBufferSize >= 0 {
432434
p.initMsgQueue(config.MsgQueueBufferSize)

0 commit comments

Comments
 (0)