Skip to content

Commit 949bb3f

Browse files
authored
Merge pull request #569 from markus-wa/game-event-list
feat: game event list based on network protocol
2 parents 5a61323 + adad9a2 commit 949bb3f

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

pkg/demoinfocs/demoinfocs_test.go

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

220220
if *update {
221221
p.RegisterNetMessageHandler(func(gel *msgs2.CMsgSource1LegacyGameEventList) {
222-
lo.Must0(os.WriteFile("s2_CMsgSource1LegacyGameEventList.pb.bin", lo.Must(proto.Marshal(gel)), 0600))
222+
lo.Must0(os.WriteFile("event-list-dump/s2_CMsgSource1LegacyGameEventList.pb.bin", lo.Must(proto.Marshal(gel)), 0600))
223223
})
224224
}
225225

15 KB
Binary file not shown.
15 KB
Binary file not shown.

pkg/demoinfocs/parser.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,6 @@ var DefaultParserConfig = ParserConfig{
373373
MsgQueueBufferSize: -1,
374374
}
375375

376-
//go:embed s2_CMsgSource1LegacyGameEventList.pb.bin
377-
var defaultSource2FallbackGameEventListBin []byte
378-
379376
// NewParserWithConfig returns a new Parser with a custom configuration.
380377
//
381378
// See also: NewParser() & ParserConfig
@@ -399,11 +396,6 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) Parser {
399396
p.recordingPlayerSlot = -1
400397
p.disableMimicSource1GameEvents = config.DisableMimicSource1Events
401398
p.source2FallbackGameEventListBin = config.Source2FallbackGameEventListBin
402-
403-
if p.source2FallbackGameEventListBin == nil {
404-
p.source2FallbackGameEventListBin = defaultSource2FallbackGameEventListBin
405-
}
406-
407399
p.ignorePacketEntitiesPanic = config.IgnorePacketEntitiesPanic
408400

409401
dispatcherCfg := dp.Config{

pkg/demoinfocs/s2_commands.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package demoinfocs
22

33
import (
44
"bytes"
5+
"embed"
56
"fmt"
67
"sort"
78
"time"
@@ -372,12 +373,36 @@ func (p *parser) handleFileInfo(msg *msgs2.CDemoFileInfo) {
372373
p.header.PlaybackTime = time.Duration(*msg.PlaybackTime) * time.Second
373374
}
374375

376+
//go:embed event-list-dump/*.bin
377+
var eventListFolder embed.FS
378+
379+
func getGameEventListBinForProtocol(networkProtocol int) ([]byte, error) {
380+
switch {
381+
case networkProtocol < 13992:
382+
return eventListFolder.ReadFile("event-list-dump/13990.bin")
383+
case networkProtocol >= 13992 && networkProtocol < 14023:
384+
return eventListFolder.ReadFile("event-list-dump/13992.bin")
385+
default:
386+
return eventListFolder.ReadFile("event-list-dump/14023.bin")
387+
}
388+
}
389+
375390
func (p *parser) handleDemoFileHeader(msg *msgs2.CDemoFileHeader) {
376391
p.header.ClientName = msg.GetClientName()
377392
p.header.ServerName = msg.GetServerName()
378393
p.header.GameDirectory = msg.GetGameDirectory()
379394
p.header.MapName = msg.GetMapName()
380-
p.header.NetworkProtocol = int(msg.GetNetworkProtocol())
395+
networkProtocol := int(msg.GetNetworkProtocol())
396+
p.header.NetworkProtocol = networkProtocol
397+
398+
if p.source2FallbackGameEventListBin == nil {
399+
gameEventListBin, err := getGameEventListBinForProtocol(networkProtocol)
400+
if err != nil {
401+
panic(fmt.Sprintf("failed to load game event list for protocol %d: %v", networkProtocol, err))
402+
}
403+
404+
p.source2FallbackGameEventListBin = gameEventListBin
405+
}
381406
}
382407

383408
func (p *parser) updatePlayersPreviousFramePosition() {

0 commit comments

Comments
 (0)