Skip to content

Commit 0af7d16

Browse files
committed
Add option to debug server-classes
1 parent 37444c4 commit 0af7d16

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ go test
151151
You can use the build tag `debugdemoinfocs` (i.e. `go test -tags debugdemoinfocs -v`) to print out debugging information - such as game events or unhandled demo-messages - during the parsing process.<br>
152152
Side-note: The tag isn't called `debug` to avoid naming conflicts with other libs (and underscores in tags don't work, apparently).
153153

154-
To change the default debugging behavior Go's `ldflags` paramter can be used. Example for additionally printing out the ingame-tick-numbers: `-ldflags '-X github.com/markus-wa/demoinfocs-golang.debugIngameTicks=YES'`
154+
To change the default debugging behavior Go's `ldflags` paramter can be used. Example for additionally printing out all server-classes with their properties: `-ldflags '-X github.com/markus-wa/demoinfocs-golang.debugServerClasses=YES'`
155155

156156
Check out `debug_on.go` for any other settings that can be changed.
157157

debug_off.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package demoinfocs
66

77
import (
88
msg "github.com/markus-wa/demoinfocs-golang/msg"
9+
st "github.com/markus-wa/demoinfocs-golang/sendtables"
910
)
1011

1112
const isDebug = false
@@ -25,3 +26,7 @@ func debugIngameTick(tickNr int) {
2526
func debugDemoCommand(cmd demoCommand) {
2627
// NOP
2728
}
29+
30+
func debugAllServerClasses(classes st.ServerClasses) {
31+
// NOP
32+
}

debug_on.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99

1010
msg "github.com/markus-wa/demoinfocs-golang/msg"
11+
st "github.com/markus-wa/demoinfocs-golang/sendtables"
1112
)
1213

1314
const isDebug = true
@@ -23,6 +24,7 @@ var debugGameEvents = yes
2324
var debugUnhandledMessages = yes
2425
var debugIngameTicks = no
2526
var debugDemoCommands = yes
27+
var debugServerClasses = no
2628

2729
func debugGameEvent(d *msg.CSVCMsg_GameEventListDescriptorT, ge *msg.CSVCMsg_GameEvent) {
2830
if debugGameEvents == yes {
@@ -92,3 +94,12 @@ func debugDemoCommand(cmd demoCommand) {
9294
fmt.Println("Demo-Command:", cmd)
9395
}
9496
}
97+
98+
func debugAllServerClasses(classes st.ServerClasses) {
99+
if debugServerClasses == yes {
100+
for _, sc := range classes {
101+
fmt.Println(sc)
102+
fmt.Println()
103+
}
104+
}
105+
}

parsing.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ func (p *Parser) parseFrame() bool {
198198
p.stParser.ParsePacket(p.bitReader)
199199
p.bitReader.EndChunk()
200200

201+
debugAllServerClasses(p.ServerClasses())
202+
201203
p.mapEquipment()
202204
p.bindEntities()
203205

sendtables/sendtables.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package sendtables
33

44
import (
55
"bytes"
6+
"fmt"
7+
"strings"
68

79
bit "github.com/markus-wa/demoinfocs-golang/bitread"
810
)
@@ -47,6 +49,13 @@ type ServerClass struct {
4749
preprocessedBaseline map[int]PropertyValue // Preprocessed baseline
4850
}
4951

52+
// Stores meta information about a property of an Entity.
53+
type flattenedPropEntry struct {
54+
prop *sendTableProperty
55+
arrayElementProp *sendTableProperty
56+
name string
57+
}
58+
5059
// ID returns the server-class's ID.
5160
func (sc *ServerClass) ID() int {
5261
return sc.id
@@ -131,12 +140,26 @@ func (sc *ServerClass) OnEntityCreated(handler EntityCreatedHandler) {
131140
sc.createdHandlers = append(sc.createdHandlers, handler)
132141
}
133142

134-
// Stores meta information about a property of an Entity.
135-
type flattenedPropEntry struct {
136-
prop *sendTableProperty
137-
arrayElementProp *sendTableProperty
138-
name string
139-
}
140-
141143
// EntityCreatedHandler is the interface for handlers that are interested in EntityCreatedEvents.
142144
type EntityCreatedHandler func(*Entity)
145+
146+
var serverClassStringFormat = `ServerClass: id=%d name=%s
147+
dataTableId=%d
148+
dataTableName=%s
149+
baseClasses:
150+
%s
151+
props:
152+
%s`
153+
154+
func (sc *ServerClass) String() string {
155+
baseClasses := make([]string, len(sc.baseClasses))
156+
for i, bc := range sc.baseClasses {
157+
baseClasses[i] = bc.name
158+
}
159+
160+
props := make([]string, len(sc.flattenedProps))
161+
for i, fProp := range sc.flattenedProps {
162+
props[i] = fProp.name
163+
}
164+
return fmt.Sprintf(serverClassStringFormat, sc.id, sc.name, sc.dataTableID, sc.dataTableName, strings.Join(baseClasses, "\n\t\t"), strings.Join(props, "\n\t\t"))
165+
}

0 commit comments

Comments
 (0)