Skip to content

Commit c836d1f

Browse files
committed
fix PlayerFlashed.Projectile.Owner being incorrect in some cases
1 parent 78ee7d9 commit c836d1f

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

datatables.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ func (p *Parser) nadeProjectileDestroyed(proj *common.GrenadeProjectile) {
432432

433433
delete(p.gameState.grenadeProjectiles, proj.EntityID)
434434

435-
p.gameState.lastFlash.projectile = proj
435+
if proj.Weapon == common.EqFlash {
436+
p.gameState.lastFlash.projectileByPlayer[proj.Owner] = proj
437+
}
436438
}
437439

438440
func (p *Parser) bindWeapon(entity *st.Entity, wepType common.EquipmentElement) {

demoinfocs_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ func TestDemoInfoCs(t *testing.T) {
138138
}
139139
})
140140

141+
// PlayerFlashed checks
142+
p.RegisterEventHandler(func(flashed events.PlayerFlashed) {
143+
if flashed.Projectile.Owner != flashed.Attacker {
144+
t.Errorf("PlayerFlashed projectile.Owner != Attacker. tick=%d, owner=%s, attacker=%s\n", p.GameState().IngameTick(), flashed.Projectile.Owner, flashed.Attacker)
145+
}
146+
})
147+
141148
// Check some things at match start
142149
p.RegisterEventHandler(func(events.MatchStart) {
143150
participants := gs.Participants()
@@ -304,7 +311,7 @@ func TestDemoSet(t *testing.T) {
304311
defer mustClose(t, f)
305312

306313
defer func() {
307-
assert.Nil(t, recover(), "parsing of '%s/%s' paniced", demSetPath, name)
314+
assert.Nil(t, recover(), "parsing of '%s/%s' panicked", demSetPath, name)
308315
}()
309316

310317
p := dem.NewParser(f)

game_events.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,11 @@ func (geh gameEventHandler) playerHurt(data map[string]*msg.CSVCMsg_GameEventKey
324324
}
325325

326326
func (geh gameEventHandler) playerBlind(data map[string]*msg.CSVCMsg_GameEventKeyT) {
327+
attacker := geh.gameState().lastFlash.player
327328
geh.dispatch(events.PlayerFlashed{
328329
Player: geh.playerByUserID32(data["userid"].GetValShort()),
329-
Attacker: geh.gameState().lastFlash.player,
330-
Projectile: geh.gameState().lastFlash.projectile,
330+
Attacker: attacker,
331+
Projectile: geh.gameState().lastFlash.projectileByPlayer[attacker],
331332
})
332333
}
333334

game_state.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ type GameState struct {
2424
gamePhase common.GamePhase
2525
isWarmupPeriod bool
2626
isMatchStarted bool
27-
lastFlash lastFlasher // Information about the last flash that exploded, used to find the attacker and projectile for player_blind events
27+
lastFlash lastFlash // Information about the last flash that exploded, used to find the attacker and projectile for player_blind events
2828
currentDefuser *common.Player // Player currently defusing the bomb, if any
2929
currentPlanter *common.Player // Player currently planting the bomb, if any
3030
}
3131

32-
type lastFlasher struct {
33-
player *common.Player
34-
projectile *common.GrenadeProjectile
32+
type lastFlash struct {
33+
player *common.Player
34+
projectileByPlayer map[*common.Player]*common.GrenadeProjectile
3535
}
3636

3737
type ingameTickNumber int
@@ -143,6 +143,9 @@ func newGameState() *GameState {
143143
infernos: make(map[int]*common.Inferno),
144144
entities: make(map[int]*st.Entity),
145145
conVars: make(map[string]string),
146+
lastFlash: lastFlash{
147+
projectileByPlayer: make(map[*common.Player]*common.GrenadeProjectile),
148+
},
146149
}
147150

148151
gs.tState = common.NewTeamState(common.TeamTerrorists, gs.Participants().TeamMembers)

stringtables.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"strings"
99

1010
bit "github.com/markus-wa/demoinfocs-golang/bitread"
11-
common "github.com/markus-wa/demoinfocs-golang/common"
12-
events "github.com/markus-wa/demoinfocs-golang/events"
13-
msg "github.com/markus-wa/demoinfocs-golang/msg"
11+
"github.com/markus-wa/demoinfocs-golang/common"
12+
"github.com/markus-wa/demoinfocs-golang/events"
13+
"github.com/markus-wa/demoinfocs-golang/msg"
1414
)
1515

1616
const (
@@ -250,12 +250,12 @@ func parsePlayerInfo(reader io.Reader) *playerInfo {
250250
}
251251

252252
var modelPreCacheSubstringToEq = map[string]common.EquipmentElement{
253-
"flashbang_dropped": common.EqFlash,
254-
"fraggrenade_dropped": common.EqHE,
255-
"smokegrenade_thrown": common.EqSmoke,
256-
"molotov_dropped": common.EqMolotov,
257-
"incendiarygrenade_dropped": common.EqIncendiary,
258-
"decoy_dropped": common.EqDecoy,
253+
"flashbang": common.EqFlash,
254+
"fraggrenade": common.EqHE,
255+
"smokegrenade": common.EqSmoke,
256+
"molotov": common.EqMolotov,
257+
"incendiarygrenade": common.EqIncendiary,
258+
"decoy": common.EqDecoy,
259259
// @micvbang TODO: add all other weapons too.
260260
}
261261

0 commit comments

Comments
 (0)