Skip to content

Commit 3b8cde4

Browse files
committed
feat: add BulletDamage event
1 parent 52e6194 commit 3b8cde4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pkg/demoinfocs/events/events.go

Lines changed: 14 additions & 0 deletions
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

Lines changed: 17 additions & 0 deletions
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()),

0 commit comments

Comments
 (0)