Skip to content

Commit

Permalink
feat: add BulletDamage event
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed Aug 6, 2024
1 parent 52e6194 commit 3b8cde4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/demoinfocs/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,20 @@ type HostageStateChanged struct {
Hostage *common.Hostage
}

// BulletDamage signals that a bullet did some damage.
// Available only with CS2 demos after the 22/07/2024 update.
type BulletDamage struct {
Attacker *common.Player
Victim *common.Player
Distance float32
DamageDirX float32
DamageDirY float32
DamageDirZ float32
NumPenetrations int
IsNoScope bool
IsAttackerInAir bool
}

// HitGroup is the type for the various HitGroupXYZ constants.
//
// See PlayerHurt.
Expand Down
17 changes: 17 additions & 0 deletions pkg/demoinfocs/game_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func newGameEventHandler(parser *parser, ignoreBombsiteIndexNotFound bool) gameE
"bomb_pickup": delayIfNoPlayers(geh.bombPickup), // Bomb picked up
"bomb_planted": delayIfNoPlayers(geh.bombPlanted), // Plant finished
"bot_takeover": delay(geh.botTakeover), // Bot got taken over
"bullet_damage": delayIfNoPlayers(geh.bulletDamage), // CS2 only
"buytime_ended": nil, // Not actually end of buy time, seems to only be sent once per game at the start
"choppers_incoming_warning": nil, // Helicopters are coming (Danger zone mode)
"cs_intermission": nil, // Dunno, only in locally recorded (POV) demo
Expand Down Expand Up @@ -653,6 +654,22 @@ func (geh gameEventHandler) HostageRescuedAll(map[string]*msg.CSVCMsg_GameEventK
geh.dispatch(events.HostageRescuedAll{})
}

func (geh gameEventHandler) bulletDamage(data map[string]*msg.CSVCMsg_GameEventKeyT) {
event := events.BulletDamage{
Attacker: geh.playerByUserID32(data["attacker"].GetValShort()),
Victim: geh.playerByUserID32(data["victim"].GetValShort()),
Distance: data["distance"].GetValFloat(),
DamageDirX: data["damage_dir_x"].GetValFloat(),
DamageDirY: data["damage_dir_y"].GetValFloat(),
DamageDirZ: data["damage_dir_z"].GetValFloat(),
NumPenetrations: int(data["num_penetrations"].GetValShort()),
IsNoScope: data["no_scope"].GetValBool(),
IsAttackerInAir: data["in_air"].GetValBool(),
}

geh.dispatch(event)
}

func (geh gameEventHandler) playerConnect(data map[string]*msg.CSVCMsg_GameEventKeyT) {
pl := common.PlayerInfo{
UserID: int(data["userid"].GetValShort()),
Expand Down

0 comments on commit 3b8cde4

Please sign in to comment.