Skip to content

Commit 7fefd38

Browse files
committed
PlayerHurt: fixed nil WeaponInstance for some cases (#171)
1 parent 5880e3e commit 7fefd38

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

datatables.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
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.

game_events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func newGameEventHandler(parser *Parser) gameEventHandler {
117117
"cs_round_start_beep": nil, // Round start beeps
118118
"cs_win_panel_match": geh.csWinPanelMatch, // Not sure, maybe match end event???
119119
"cs_win_panel_round": nil, // Win panel, (==end of match?)
120-
"decoy_detonate": geh.decoyDetonate, // Decoy exploded/expired
120+
"decoy_detonate": delay(geh.decoyDetonate), // Decoy exploded/expired. Delayed so deleteThrownGrenade() isn't called before player_hurt
121121
"decoy_started": delay(geh.decoyStarted), // Decoy started. Delayed because projectile entity is not yet created
122122
"endmatch_cmm_start_reveal_items": nil, // Drops
123123
"entity_visible": nil, // Dunno, only in locally recorded demo

test/default.golden

15 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)