blob: d92b22df152e748397abcc386324208531e57e25 (
plain) (
blame)
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
46
47
|
package packets
import (
"github.com/pektezol/bitreader"
"github.com/pektezol/demoparser/pkg/writer"
)
type Headers struct {
DemoFileStamp string
DemoProtocol int32
NetworkProtocol int32
ServerName string
ClientName string
MapName string
GameDirectory string
PlaybackTime float32
PlaybackTicks int32
PlaybackFrames int32
SignOnLength int32
}
func ParseHeaders(reader *bitreader.Reader) Headers {
headers := Headers{
DemoFileStamp: reader.TryReadString(),
DemoProtocol: int32(reader.TryReadSInt32()),
NetworkProtocol: int32(reader.TryReadSInt32()),
ServerName: reader.TryReadStringLength(260),
ClientName: reader.TryReadStringLength(260),
MapName: reader.TryReadStringLength(260),
GameDirectory: reader.TryReadStringLength(260),
PlaybackTime: reader.TryReadFloat32(),
PlaybackTicks: int32(reader.TryReadSInt32()),
PlaybackFrames: int32(reader.TryReadSInt32()),
SignOnLength: int32(reader.TryReadSInt32()),
}
if headers.DemoFileStamp != "HL2DEMO" {
panic("invalid demo file stamp")
}
if headers.DemoProtocol != 4 {
panic("this parser only supports demos from new engine")
}
if headers.NetworkProtocol != 2001 {
panic("this parser only supports demos from portal 2")
}
writer.AppendLine("Headers: %+v", headers)
return headers
}
|