Skip to content

Commit f6a5b79

Browse files
committed
cs2 weapons handling: fix nil pointer deref panic
1 parent 4d7029c commit f6a5b79

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,12 @@ func (p *parser) bindPlayerWeapons(playerEntity st.Entity, pl *common.Player) {
690690
func (p *parser) bindPlayerWeaponsS2(pawnEntity st.Entity, pl *common.Player) {
691691
const inventoryCapacity = 64
692692
var inventorySize uint64 = 64
693-
playerInventory := make(map[int]*common.Equipment)
693+
694+
type eq struct {
695+
*common.Equipment
696+
entityID int
697+
}
698+
playerInventory := make(map[int]eq)
694699

695700
getWep := func(wepSlotPropertyValue st.PropertyValue) (uint64, *common.Equipment) {
696701
entityID := wepSlotPropertyValue.S2UInt64() & constants.EntityHandleIndexMaskSource2
@@ -739,10 +744,14 @@ func (p *parser) bindPlayerWeaponsS2(pawnEntity st.Entity, pl *common.Player) {
739744
if entityWasCreated {
740745
existingWeapon, exists := playerInventory[i]
741746
if exists {
742-
delete(pl.Inventory, existingWeapon.Entity.ID())
747+
delete(pl.Inventory, existingWeapon.entityID)
743748
}
749+
744750
pl.Inventory[int(entityID)] = wep
745-
playerInventory[i] = wep
751+
playerInventory[i] = eq{
752+
Equipment: wep,
753+
entityID: int(entityID),
754+
}
746755
} else {
747756
delete(pl.Inventory, int(entityID))
748757
}

0 commit comments

Comments
 (0)