Skip to content

Commit

Permalink
fix: possible invalid pawn entity
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed Dec 30, 2023
1 parent a96cc7b commit 5245396
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/demoinfocs/common/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ type Player struct {
}

func (p *Player) PlayerPawnEntity() st.Entity {
pawn, exists := p.Entity.PropertyValue("m_hPawn")
if !exists {
return nil

Check warning on line 42 in pkg/demoinfocs/common/player.go

View check run for this annotation

Codecov / codecov/patch

pkg/demoinfocs/common/player.go#L42

Added line #L42 was not covered by tests
}

if pawn.Handle() == constants.InvalidEntityHandleSource2 {
return nil
}

playerPawn, exists := p.Entity.PropertyValue("m_hPlayerPawn")
if !exists {
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/demoinfocs/common/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ func TestPlayer_Velocity(t *testing.T) {
func createPlayerForVelocityTest() *Player {
controllerEntity := entityWithProperties([]fakeProp{
{propName: "m_hPlayerPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
{propName: "m_hPawn", value: st.PropertyValue{Any: uint64(1), S2: true}},
})
pawnEntity := new(stfake.Entity)
position := r3.Vector{X: 20, Y: 300, Z: 100}
Expand Down

0 comments on commit 5245396

Please sign in to comment.