55 "strings"
66
77 "github.com/golang/geo/r3"
8+ "github.com/markus-wa/go-unassert"
89
910 "github.com/markus-wa/demoinfocs-golang/common"
1011 "github.com/markus-wa/demoinfocs-golang/events"
@@ -379,7 +380,17 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
379380 proj .EntityID = entityID
380381 p .gameState .grenadeProjectiles [entityID ] = proj
381382
383+ var wep common.EquipmentElement
382384 entity .OnCreateFinished (func () {
385+ // copy the weapon so it doesn't get overwritten by a new entity in Parser.weapons
386+ wepCopy := * (getPlayerWeapon (proj .Thrower , wep ))
387+ proj .WeaponInstance = & wepCopy
388+
389+ unassert .NotNilf (proj .WeaponInstance , "couldn't find grenade instance for player" )
390+ if proj .WeaponInstance != nil {
391+ unassert .NotNilf (proj .WeaponInstance .Owner , "getPlayerWeapon() returned weapon instance with Owner=nil" )
392+ }
393+
383394 p .gameEventHandler .addThrownGrenade (proj .Thrower , proj .WeaponInstance )
384395
385396 p .eventDispatcher .Dispatch (events.GrenadeProjectileThrow {
@@ -393,9 +404,7 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
393404
394405 entity .FindPropertyI ("m_nModelIndex" ).OnUpdate (func (val st.PropertyValue ) {
395406 proj .Weapon = p .grenadeModelIndices [val .IntVal ]
396-
397- equipment := common .NewEquipment (p .grenadeModelIndices [val .IntVal ])
398- proj .WeaponInstance = & equipment
407+ wep = p .grenadeModelIndices [val .IntVal ]
399408 })
400409
401410 // @micvbang: not quite sure what the difference between Thrower and Owner is.
0 commit comments