Skip to content

Commit a02634f

Browse files
committed
fix: possible panic due to incorrect weapon's owner
1 parent d0cce14 commit a02634f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,20 +1015,18 @@ func (p *parser) bindWeaponS2(entity st.Entity) {
10151015
// - The player is inside the buy zone
10161016
// - The player's money has increased AND the weapon entity is destroyed at the same tick (unfortunately the money is updated first)
10171017
var (
1018-
owner *common.Player
10191018
oldOwnerMoney int
10201019
lastMoneyUpdateTick int
10211020
lastMoneyIncreased bool
10221021
)
10231022

10241023
entity.Property("m_hOwnerEntity").OnUpdate(func(val st.PropertyValue) {
1025-
weaponOwner := p.GameState().Participants().FindByPawnHandle(val.Handle())
1026-
if weaponOwner == nil {
1024+
owner := p.GameState().Participants().FindByPawnHandle(val.Handle())
1025+
if owner == nil {
10271026
equipment.Owner = nil
10281027
return
10291028
}
10301029

1031-
owner = weaponOwner
10321030
oldOwnerMoney = owner.Money()
10331031

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

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

0 commit comments

Comments
 (0)