Skip to content

Commit 83c839a

Browse files
committed
fix: SmokeStart wrong UniqueID2()
backport of 097b925
1 parent d4feac5 commit 83c839a

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

pkg/demoinfocs/game_events.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (geh gameEventHandler) clearGrenadeProjectiles() {
324324
}
325325

326326
// Thrown grenades could not be deleted at the end of the round (if they are thrown at the very end, they never get destroyed)
327-
geh.gameState().thrownGrenades = make(map[*common.Player][]*common.Equipment)
327+
geh.gameState().thrownGrenades = make(map[*common.Player]map[common.EquipmentType]*common.Equipment)
328328
geh.gameState().flyingFlashbangs = make([]*FlyingFlashbang, 0)
329329
}
330330

@@ -1021,7 +1021,11 @@ func (geh gameEventHandler) addThrownGrenade(p *common.Player, wep *common.Equip
10211021
}
10221022

10231023
gameState := geh.gameState()
1024-
gameState.thrownGrenades[p] = append(gameState.thrownGrenades[p], wep)
1024+
if gameState.thrownGrenades[p] == nil {
1025+
gameState.thrownGrenades[p] = make(map[common.EquipmentType]*common.Equipment)
1026+
}
1027+
1028+
gameState.thrownGrenades[p][wep.Type] = wep
10251029
}
10261030

10271031
func (geh gameEventHandler) getThrownGrenade(p *common.Player, wepType common.EquipmentType) *common.Equipment {
@@ -1030,14 +1034,11 @@ func (geh gameEventHandler) getThrownGrenade(p *common.Player, wepType common.Eq
10301034
return nil
10311035
}
10321036

1033-
// Get the first weapon we found for this player with this weapon type
1034-
for _, thrownGrenade := range geh.gameState().thrownGrenades[p] {
1035-
if isSameEquipmentElement(thrownGrenade.Type, wepType) {
1036-
return thrownGrenade
1037-
}
1037+
if geh.gameState().thrownGrenades[p] == nil {
1038+
return nil
10381039
}
10391040

1040-
return nil
1041+
return geh.gameState().thrownGrenades[p][wepType]
10411042
}
10421043

10431044
func (geh gameEventHandler) deleteThrownGrenade(p *common.Player, wepType common.EquipmentType) {
@@ -1046,17 +1047,8 @@ func (geh gameEventHandler) deleteThrownGrenade(p *common.Player, wepType common
10461047
return
10471048
}
10481049

1049-
gameState := geh.gameState()
1050+
delete(geh.gameState().thrownGrenades[p], wepType)
10501051

1051-
// Delete the first weapon we found with this weapon type
1052-
for i, weapon := range gameState.thrownGrenades[p] {
1053-
// If same weapon type
1054-
// OR if it's an EqIncendiary we must check for EqMolotov too because of geh.infernoExpire() handling ?
1055-
if isSameEquipmentElement(wepType, weapon.Type) {
1056-
gameState.thrownGrenades[p] = append(gameState.thrownGrenades[p][:i], gameState.thrownGrenades[p][i+1:]...)
1057-
return
1058-
}
1059-
}
10601052
}
10611053

10621054
func (geh gameEventHandler) attackerWeaponType(wepType common.EquipmentType, victimUserID int32) common.EquipmentType {

pkg/demoinfocs/game_events_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestAddThrownGrenade(t *testing.T) {
115115

116116
assert.NotEmpty(t, p.gameState.thrownGrenades)
117117
assert.NotEmpty(t, p.gameState.thrownGrenades[pl])
118-
assert.Equal(t, p.gameState.thrownGrenades[pl][0], he)
118+
assert.Equal(t, p.gameState.thrownGrenades[pl][common.EqHE], he)
119119
}
120120

121121
func TestGetThrownGrenade_NilPlayer(t *testing.T) {

pkg/demoinfocs/game_state.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ type gameState struct {
3737
isFreezetime bool
3838
isMatchStarted bool
3939
overtimeCount int
40-
lastFlash lastFlash // Information about the last flash that exploded, used to find the attacker and projectile for player_blind events
41-
currentDefuser *common.Player // Player currently defusing the bomb, if any
42-
currentPlanter *common.Player // Player currently planting the bomb, if any
43-
thrownGrenades map[*common.Player][]*common.Equipment // Information about every player's thrown grenades (from the moment they are thrown to the moment their effect is ended)
40+
lastFlash lastFlash // Information about the last flash that exploded, used to find the attacker and projectile for player_blind events
41+
currentDefuser *common.Player // Player currently defusing the bomb, if any
42+
currentPlanter *common.Player // Player currently planting the bomb, if any
43+
thrownGrenades map[*common.Player]map[common.EquipmentType]*common.Equipment // Information about every player's thrown grenades (from the moment they are thrown to the moment their effect is ended)
4444
rules gameRules
4545
demoInfo demoInfoProvider
4646
lastRoundStartEvent *events.RoundStart // Used to dispatch this event after a possible MatchStartedChanged event
@@ -249,7 +249,7 @@ func newGameState(demoInfo demoInfoProvider) *gameState {
249249
weapons: make(map[int]*common.Equipment),
250250
hostages: make(map[int]*common.Hostage),
251251
entities: make(map[int]st.Entity),
252-
thrownGrenades: make(map[*common.Player][]*common.Equipment),
252+
thrownGrenades: make(map[*common.Player]map[common.EquipmentType]*common.Equipment),
253253
flyingFlashbangs: make([]*FlyingFlashbang, 0),
254254
lastFlash: lastFlash{
255255
projectileByPlayer: make(map[*common.Player]*common.GrenadeProjectile),

test/default.golden

95 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)