-
Notifications
You must be signed in to change notification settings - Fork 95
/
netmessages.go
45 lines (36 loc) · 1.06 KB
/
netmessages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"os"
"google.golang.org/protobuf/proto"
ex "github.com/markus-wa/demoinfocs-golang/v4/examples"
demoinfocs "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs"
msg "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/msg"
)
// Run like this: go run netmessages.go -demo /path/to/demo.dem > out.png
func main() {
f, err := os.Open(ex.DemoPathFromArgs())
checkError(err)
defer f.Close()
// Configure parsing of BSPDecal net-message
cfg := demoinfocs.DefaultParserConfig
cfg.AdditionalNetMessageCreators = map[int]demoinfocs.NetMessageCreator{
int(msg.SVC_Messages_svc_BSPDecal): func() proto.Message {
return new(msg.CSVCMsg_BSPDecal)
},
}
p := demoinfocs.NewParserWithConfig(f, cfg)
defer p.Close()
// Register handler for BSPDecal messages
p.RegisterNetMessageHandler(func(m *msg.CSVCMsg_BSPDecal) {
fmt.Printf("bullet decal at x=%f y=%f z=%f\n", m.Pos.GetX(), m.Pos.GetY(), m.Pos.GetZ())
})
// Parse to end
err = p.ParseToEnd()
checkError(err)
}
func checkError(err error) {
if err != nil {
panic(err)
}
}