Skip to content

Commit 0722cfc

Browse files
authored
Merge pull request #600 from markus-wa/nil-fields
fix: possible nil players/weapons fields in some events
2 parents f5f80e7 + 579b959 commit 0722cfc

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

pkg/demoinfocs/common/equipment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func initEqNameToWeapon() {
165165
eqNameToWeapon["hkp2000"] = EqP2000
166166
eqNameToWeapon["incgrenade"] = EqIncendiary
167167
eqNameToWeapon["incendiarygrenade"] = EqIncendiary
168+
eqNameToWeapon["inferno"] = EqIncendiary
168169
eqNameToWeapon["m249"] = EqM249
169170
eqNameToWeapon["m4a1"] = EqM4A4
170171
eqNameToWeapon["mac10"] = EqMac10

pkg/demoinfocs/game_events.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ func (geh gameEventHandler) playerDeath(data map[string]*msg.CSVCMsg_GameEventKe
470470
victimUserID := data["userid"].GetValShort()
471471
wepType = geh.attackerWeaponType(wepType, victimUserID)
472472

473+
if killer == nil && data["attacker_pawn"] != nil {
474+
// CS2 only, fallback to pawn handle if the killer was not found by its user ID
475+
killer = geh.parser.gameState.Participants().FindByPawnHandle(uint64(data["attacker_pawn"].GetValLong()))
476+
}
477+
473478
geh.dispatch(events.Kill{
474479
Victim: geh.playerByUserID32(data["userid"].GetValShort()),
475480
Killer: killer,
@@ -997,7 +1002,18 @@ func (geh gameEventHandler) bombPickup(data map[string]*msg.CSVCMsg_GameEventKey
9971002

9981003
// Just so we can nicely create GrenadeEvents in one line
9991004
func (geh gameEventHandler) nadeEvent(data map[string]*msg.CSVCMsg_GameEventKeyT, nadeType common.EquipmentType) events.GrenadeEvent {
1000-
thrower := geh.playerByUserID32(data["userid"].GetValShort())
1005+
var thrower *common.Player
1006+
// Sometimes only the position and the entityid are present.
1007+
// Since GetValShort() returns 0 for nil values, the thrower would be the player with UserID 0, so we need to check for the existence of the key.
1008+
if data["userid"] != nil {
1009+
thrower = geh.playerByUserID32(data["userid"].GetValShort())
1010+
}
1011+
1012+
// CS2 only - userid may be missing, but userid_pawn present.
1013+
if thrower == nil && data["userid_pawn"] != nil {
1014+
thrower = geh.gameState().Participants().FindByPawnHandle(uint64(data["userid_pawn"].GetValLong()))
1015+
}
1016+
10011017
position := r3.Vector{
10021018
X: float64(data["x"].GetValFloat()),
10031019
Y: float64(data["y"].GetValFloat()),

pkg/demoinfocs/net_messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func (p *parser) handleMessageSayText2(msg *msgs2.CUserMessageSayText2) {
141141

142142
case "#CSGO_Coach_Join_T": // Ignore these
143143
case "#CSGO_Coach_Join_CT":
144+
case "#CSGO_No_Longer_Coach":
144145
case "#Cstrike_Name_Change":
145146
case "Cstrike_Chat_T_Loc":
146147
case "Cstrike_Chat_CT_Loc":

pkg/demoinfocs/user_messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (umh userMessageHandler) sayText2(um *msg.CSVCMsg_UserMessage) {
107107

108108
case "#CSGO_Coach_Join_T": // Ignore these
109109
case "#CSGO_Coach_Join_CT":
110+
case "#CSGO_No_Longer_Coach":
110111
case "#Cstrike_Name_Change":
111112
case "Cstrike_Chat_T_Loc":
112113
case "Cstrike_Chat_CT_Loc":

0 commit comments

Comments
 (0)