Skip to content

Commit dfd6dcf

Browse files
committed
fix: possible nil player in game events
fix akiver/cs-demo-manager#863
1 parent 24dee87 commit dfd6dcf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,19 @@ func (p *parser) bindPlayers() {
416416

417417
func (p *parser) getOrCreatePlayer(entityID int, rp *common.PlayerInfo) (isNew bool, player *common.Player) {
418418
player = p.gameState.playersByEntityID[entityID]
419+
userID := -1
420+
421+
if rp != nil {
422+
userID = rp.UserID
423+
}
424+
425+
if p.isSource2() && userID <= math.MaxUint16 {
426+
userID &= 0xff
427+
}
419428

420429
if player == nil {
421430
if rp != nil {
422-
player = p.gameState.playersByUserID[rp.UserID]
431+
player = p.gameState.playersByUserID[userID]
423432

424433
if player == nil {
425434
isNew = true
@@ -428,7 +437,7 @@ func (p *parser) getOrCreatePlayer(entityID int, rp *common.PlayerInfo) (isNew b
428437
player.Name = rp.Name
429438
player.SteamID64 = rp.XUID
430439
player.IsBot = rp.IsFakePlayer || rp.GUID == "BOT"
431-
player.UserID = rp.UserID
440+
player.UserID = userID
432441

433442
p.gameState.indexPlayerBySteamID(player)
434443
}
@@ -446,7 +455,7 @@ func (p *parser) getOrCreatePlayer(entityID int, rp *common.PlayerInfo) (isNew b
446455
p.gameState.playersByEntityID[entityID] = player
447456

448457
if rp != nil {
449-
p.gameState.playersByUserID[rp.UserID] = player
458+
p.gameState.playersByUserID[userID] = player
450459
}
451460

452461
return isNew, player

0 commit comments

Comments
 (0)