Skip to content

Commit 5245396

Browse files
committed
fix: possible invalid pawn entity
1 parent a96cc7b commit 5245396

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/demoinfocs/common/player.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ type Player struct {
3737
}
3838

3939
func (p *Player) PlayerPawnEntity() st.Entity {
40+
pawn, exists := p.Entity.PropertyValue("m_hPawn")
41+
if !exists {
42+
return nil
43+
}
44+
45+
if pawn.Handle() == constants.InvalidEntityHandleSource2 {
46+
return nil
47+
}
48+
4049
playerPawn, exists := p.Entity.PropertyValue("m_hPlayerPawn")
4150
if !exists {
4251
return nil

pkg/demoinfocs/common/player_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ func TestPlayer_Velocity(t *testing.T) {
431431
func createPlayerForVelocityTest() *Player {
432432
controllerEntity := entityWithProperties([]fakeProp{
433433
{propName: "m_hPlayerPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
434+
{propName: "m_hPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
434435
})
435436
pawnEntity := new(stfake.Entity)
436437
position := r3.Vector{X: 20, Y: 300, Z: 100}

0 commit comments

Comments
 (0)