Skip to content

Commit

Permalink
feat: game event list based on network protocol
Browse files Browse the repository at this point in the history
fix #566
  • Loading branch information
akiver committed Dec 2, 2024
1 parent ae3c7a2 commit adad9a2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/demoinfocs/demoinfocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestS2(t *testing.T) {

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

Expand Down
Binary file added pkg/demoinfocs/event-list-dump/13990.bin
Binary file not shown.
File renamed without changes.
Binary file added pkg/demoinfocs/event-list-dump/14023.bin
Binary file not shown.
8 changes: 0 additions & 8 deletions pkg/demoinfocs/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,6 @@ var DefaultParserConfig = ParserConfig{
MsgQueueBufferSize: -1,
}

//go:embed s2_CMsgSource1LegacyGameEventList.pb.bin
var defaultSource2FallbackGameEventListBin []byte

// NewParserWithConfig returns a new Parser with a custom configuration.
//
// See also: NewParser() & ParserConfig
Expand All @@ -399,11 +396,6 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) Parser {
p.recordingPlayerSlot = -1
p.disableMimicSource1GameEvents = config.DisableMimicSource1Events
p.source2FallbackGameEventListBin = config.Source2FallbackGameEventListBin

if p.source2FallbackGameEventListBin == nil {
p.source2FallbackGameEventListBin = defaultSource2FallbackGameEventListBin
}

p.ignorePacketEntitiesPanic = config.IgnorePacketEntitiesPanic

dispatcherCfg := dp.Config{
Expand Down
27 changes: 26 additions & 1 deletion pkg/demoinfocs/s2_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package demoinfocs

import (
"bytes"
"embed"
"fmt"
"sort"
"time"
Expand Down Expand Up @@ -372,12 +373,36 @@ func (p *parser) handleFileInfo(msg *msgs2.CDemoFileInfo) {
p.header.PlaybackTime = time.Duration(*msg.PlaybackTime) * time.Second
}

//go:embed event-list-dump/*.bin
var eventListFolder embed.FS

func getGameEventListBinForProtocol(networkProtocol int) ([]byte, error) {
switch {
case networkProtocol < 13992:
return eventListFolder.ReadFile("event-list-dump/13990.bin")
case networkProtocol >= 13992 && networkProtocol < 14023:
return eventListFolder.ReadFile("event-list-dump/13992.bin")
default:
return eventListFolder.ReadFile("event-list-dump/14023.bin")
}
}

func (p *parser) handleDemoFileHeader(msg *msgs2.CDemoFileHeader) {
p.header.ClientName = msg.GetClientName()
p.header.ServerName = msg.GetServerName()
p.header.GameDirectory = msg.GetGameDirectory()
p.header.MapName = msg.GetMapName()
p.header.NetworkProtocol = int(msg.GetNetworkProtocol())
networkProtocol := int(msg.GetNetworkProtocol())
p.header.NetworkProtocol = networkProtocol

if p.source2FallbackGameEventListBin == nil {
gameEventListBin, err := getGameEventListBinForProtocol(networkProtocol)
if err != nil {
panic(fmt.Sprintf("failed to load game event list for protocol %d: %v", networkProtocol, err))
}

p.source2FallbackGameEventListBin = gameEventListBin
}
}

func (p *parser) updatePlayersPreviousFramePosition() {
Expand Down

0 comments on commit adad9a2

Please sign in to comment.