aboutsummaryrefslogtreecommitdiff
path: root/pkg/packets/headers.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/packets/headers.go')
-rw-r--r--pkg/packets/headers.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/pkg/packets/headers.go b/pkg/packets/headers.go
new file mode 100644
index 0000000..543476b
--- /dev/null
+++ b/pkg/packets/headers.go
@@ -0,0 +1,48 @@
1package packets
2
3import (
4 "fmt"
5
6 "github.com/pektezol/bitreader"
7)
8
9type Headers struct {
10 DemoFileStamp string
11 DemoProtocol int32
12 NetworkProtocol int32
13 ServerName string
14 ClientName string
15 MapName string
16 GameDirectory string
17 PlaybackTime float32
18 PlaybackTicks int32
19 PlaybackFrames int32
20 SignOnLength int32
21}
22
23func ParseHeaders(reader *bitreader.ReaderType) Headers {
24 headers := Headers{
25 DemoFileStamp: reader.TryReadString(),
26 DemoProtocol: int32(reader.TryReadInt32()),
27 NetworkProtocol: int32(reader.TryReadInt32()),
28 ServerName: reader.TryReadStringLen(260),
29 ClientName: reader.TryReadStringLen(260),
30 MapName: reader.TryReadStringLen(260),
31 GameDirectory: reader.TryReadStringLen(260),
32 PlaybackTime: reader.TryReadFloat32(),
33 PlaybackTicks: int32(reader.TryReadInt32()),
34 PlaybackFrames: int32(reader.TryReadInt32()),
35 SignOnLength: int32(reader.TryReadInt32()),
36 }
37 if headers.DemoFileStamp != "HL2DEMO" {
38 panic("invalid demo file stamp")
39 }
40 if headers.DemoProtocol != 4 {
41 panic("this parser only supports demos from new engine")
42 }
43 if headers.NetworkProtocol != 2001 {
44 panic("this parser only supports demos from portal 2")
45 }
46 fmt.Printf("Headers: %+v\n", headers)
47 return headers
48}