Skip to content

Commit

Permalink
fix: hostage leader possibly nil
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed May 16, 2024
1 parent a58c851 commit d639511
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/demoinfocs/common/hostage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"github.com/golang/geo/r3"

"github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/constants"
st "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/sendtables"
)

Expand Down Expand Up @@ -54,7 +55,12 @@ func (hostage *Hostage) Health() int {
// Returns nil if the hostage is not following a player.
func (hostage *Hostage) Leader() *Player {
if hostage.demoInfoProvider.IsSource2() {
return hostage.demoInfoProvider.FindPlayerByPawnHandle(getUInt64(hostage.Entity, "m_leader"))
leaderHandle := getUInt64(hostage.Entity, "m_leader")
if leaderHandle != constants.InvalidEntityHandleSource2 {
return hostage.demoInfoProvider.FindPlayerByPawnHandle(leaderHandle)
}

return hostage.demoInfoProvider.FindPlayerByPawnHandle(getUInt64(hostage.Entity, "m_hHostageGrabber"))
}

return hostage.demoInfoProvider.FindPlayerByHandle(uint64(getInt(hostage.Entity, "m_leader")))
Expand Down

0 comments on commit d639511

Please sign in to comment.