Skip to content

Commit

Permalink
fix: possible panic due to incorrect weapon's owner
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed Dec 29, 2023
1 parent d0cce14 commit a02634f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/demoinfocs/datatables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,20 +1015,18 @@ func (p *parser) bindWeaponS2(entity st.Entity) {
// - The player is inside the buy zone
// - The player's money has increased AND the weapon entity is destroyed at the same tick (unfortunately the money is updated first)
var (
owner *common.Player
oldOwnerMoney int
lastMoneyUpdateTick int
lastMoneyIncreased bool
)

entity.Property("m_hOwnerEntity").OnUpdate(func(val st.PropertyValue) {
weaponOwner := p.GameState().Participants().FindByPawnHandle(val.Handle())
if weaponOwner == nil {
owner := p.GameState().Participants().FindByPawnHandle(val.Handle())
if owner == nil {
equipment.Owner = nil
return
}

owner = weaponOwner
oldOwnerMoney = owner.Money()

owner.Entity.Property("m_pInGameMoneyServices.m_iAccount").OnUpdate(func(val st.PropertyValue) {
Expand All @@ -1040,6 +1038,7 @@ func (p *parser) bindWeaponS2(entity st.Entity) {
})

entity.OnDestroy(func() {
owner := p.GameState().Participants().FindByPawnHandle(entity.PropertyValueMust("m_hOwnerEntity").Handle())
if owner != nil && owner.IsInBuyZone() && p.GameState().IngameTick() == lastMoneyUpdateTick && lastMoneyIncreased {
p.eventDispatcher.Dispatch(events.ItemRefund{
Player: owner,
Expand Down

0 comments on commit a02634f

Please sign in to comment.