Skip to content

Commit

Permalink
Merge pull request #427 from markus-wa/fix-freezetime-events
Browse files Browse the repository at this point in the history
fix: dispatch freezetime events after round start events
  • Loading branch information
markus-wa authored Oct 2, 2023
2 parents f780c66 + f0898a3 commit b70c827
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
15 changes: 13 additions & 2 deletions pkg/demoinfocs/datatables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,21 @@ func (p *parser) bindGameRules() {

entity.Property(grPrefix("m_bFreezePeriod")).OnUpdate(func(val st.PropertyValue) {
newIsFreezetime := val.BoolVal()
p.eventDispatcher.Dispatch(events.RoundFreezetimeChanged{
freezetimeEvent := events.RoundFreezetimeChanged{
OldIsFreezetime: p.gameState.isFreezetime,
NewIsFreezetime: newIsFreezetime,
})
}

if p.isSource2() {
if p.disableMimicSource1GameEvents {
p.eventDispatcher.Dispatch(freezetimeEvent)
} else {
p.gameState.lastFreezeTimeChangedEvent = &freezetimeEvent
}
} else {
p.eventDispatcher.Dispatch(freezetimeEvent)
}

p.gameState.isFreezetime = newIsFreezetime
})

Expand Down
11 changes: 9 additions & 2 deletions pkg/demoinfocs/game_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,15 +1023,22 @@ func (p *parser) dispatchMatchStartedEventIfNecessary() {
// Dispatch round progress events in the following order:
// 1. MatchStartedChanged
// 2. RoundStart
// 3. RoundEnd
// 4. MatchStartedChanged
// 3. FreezeTimeStart
// 4. FreezetimeEnd
// 5. RoundEnd
// 6. MatchStartedChanged
func (p *parser) processRoundProgressEvents() {
if p.gameState.lastRoundStartEvent != nil {
p.dispatchMatchStartedEventIfNecessary()
p.gameEventHandler.dispatch(*p.gameState.lastRoundStartEvent)
p.gameState.lastRoundStartEvent = nil
}

if p.gameState.lastFreezeTimeChangedEvent != nil {
p.gameEventHandler.dispatch(*p.gameState.lastFreezeTimeChangedEvent)
p.gameState.lastFreezeTimeChangedEvent = nil
}

if p.gameState.lastRoundEndEvent != nil {
p.gameEventHandler.dispatch(*p.gameState.lastRoundEndEvent)
p.gameState.lastRoundEndEvent = nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/demoinfocs/game_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type gameState struct {
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)
rules gameRules
demoInfo demoInfoProvider
lastRoundStartEvent *events.RoundStart // Used to dispatch this event after a possible MatchStartedChanged event
lastRoundEndEvent *events.RoundEnd // Used to dispatch this event before a possible MatchStartedChanged event
lastMatchStartedChangedEvent *events.MatchStartedChanged // Used to dispatch this event before a possible RoundStart event and after a possible RoundEnd event
lastRoundStartEvent *events.RoundStart // Used to dispatch this event after a possible MatchStartedChanged event
lastFreezeTimeChangedEvent *events.RoundFreezetimeChanged // Used to dispatch this event after a possible RoundStart event
lastRoundEndEvent *events.RoundEnd // Used to dispatch this event before a possible RoundFreezetimeChanged event
lastMatchStartedChangedEvent *events.MatchStartedChanged // Used to dispatch this event before a possible RoundStart event and after a possible RoundEnd event
// Used to mimic missing player_blind events for CS2 demos.
//
// When a player throws a flashbang the following happens:
Expand Down

0 comments on commit b70c827

Please sign in to comment.