From ae3c7a2fb4937b161401622a03d0dd24e2100d5c Mon Sep 17 00:00:00 2001
From: Markus Walther <mark@saiko.tech>
Date: Mon, 2 Dec 2024 01:58:58 +0000
Subject: [PATCH] simplify Parser.parseFrameS2

---
 pkg/demoinfocs/parser.go       |  5 +++++
 pkg/demoinfocs/parsing.go      | 19 ++++---------------
 pkg/demoinfocs/s2_commands.go  |  4 ----
 pkg/demoinfocs/stringtables.go |  2 --
 4 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/pkg/demoinfocs/parser.go b/pkg/demoinfocs/parser.go
index 855f0409..9c7d8e52 100644
--- a/pkg/demoinfocs/parser.go
+++ b/pkg/demoinfocs/parser.go
@@ -437,6 +437,11 @@ func NewParserWithConfig(demostream io.Reader, config ParserConfig) Parser {
 	p.msgDispatcher.RegisterHandler(p.handleServerRankUpdate)
 	p.msgDispatcher.RegisterHandler(p.handleMessageSayText)
 	p.msgDispatcher.RegisterHandler(p.handleMessageSayText2)
+	p.msgDispatcher.RegisterHandler(p.handleSendTables)
+	p.msgDispatcher.RegisterHandler(p.handleFileInfo)
+	p.msgDispatcher.RegisterHandler(p.handleDemoFileHeader)
+	p.msgDispatcher.RegisterHandler(p.handleClassInfo)
+	p.msgDispatcher.RegisterHandler(p.handleStringTables)
 
 	if config.MsgQueueBufferSize >= 0 {
 		p.initMsgQueue(config.MsgQueueBufferSize)
diff --git a/pkg/demoinfocs/parsing.go b/pkg/demoinfocs/parsing.go
index 739ad644..2f4d8a45 100644
--- a/pkg/demoinfocs/parsing.go
+++ b/pkg/demoinfocs/parsing.go
@@ -393,26 +393,15 @@ func (p *parser) parseFrameS2() bool {
 	p.msgQueue <- msg
 
 	switch m := msg.(type) {
-	case *msgs2.CDemoFileHeader:
-		p.handleDemoFileHeader(m)
-
 	case *msgs2.CDemoPacket:
 		p.handleDemoPacket(m)
 
 	case *msgs2.CDemoFullPacket:
-		p.handleFullPacket(m)
-
-	case *msgs2.CDemoSendTables:
-		p.handleSendTables(m)
-
-	case *msgs2.CDemoClassInfo:
-		p.handleClassInfo(m)
+		p.msgQueue <- m.StringTable
 
-	case *msgs2.CDemoStringTables:
-		p.handleStringTables(m)
-
-	case *msgs2.CDemoFileInfo:
-		p.handleFileInfo(m)
+		if m.Packet.GetData() != nil {
+			p.handleDemoPacket(m.Packet)
+		}
 	}
 
 	// Queue up some post processing
diff --git a/pkg/demoinfocs/s2_commands.go b/pkg/demoinfocs/s2_commands.go
index e6e338a5..79cc683c 100644
--- a/pkg/demoinfocs/s2_commands.go
+++ b/pkg/demoinfocs/s2_commands.go
@@ -15,8 +15,6 @@ import (
 )
 
 func (p *parser) handleSendTables(msg *msgs2.CDemoSendTables) {
-	p.msgDispatcher.SyncAllQueues()
-
 	err := p.stParser.ParsePacket(msg.Data)
 	if err != nil {
 		panic(errors.Wrap(err, "failed to unmarshal flattened serializer"))
@@ -24,8 +22,6 @@ func (p *parser) handleSendTables(msg *msgs2.CDemoSendTables) {
 }
 
 func (p *parser) handleClassInfo(msg *msgs2.CDemoClassInfo) {
-	p.msgDispatcher.SyncAllQueues()
-
 	err := p.stParser.OnDemoClassInfo(msg)
 	if err != nil {
 		panic(err)
diff --git a/pkg/demoinfocs/stringtables.go b/pkg/demoinfocs/stringtables.go
index 9fdf761f..d7228c0f 100644
--- a/pkg/demoinfocs/stringtables.go
+++ b/pkg/demoinfocs/stringtables.go
@@ -544,8 +544,6 @@ func (p *parser) processModelPreCacheUpdate() {
 // XXX TODO: decide if we want to at all integrate these updates,
 // or trust create/update entirely. Let's ignore them for now.
 func (p *parser) handleStringTables(msg *msgs2.CDemoStringTables) {
-	p.msgDispatcher.SyncAllQueues()
-
 	for _, tab := range msg.GetTables() {
 		if tab.GetTableName() == stNameInstanceBaseline {
 			for _, item := range tab.GetItems() {