blob: c4172d9d0516c9a4094a3e983b07af0fdcfe14e9 (
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
|
package packets
import (
"fmt"
"github.com/pektezol/bitreader"
)
func ParseHeader(reader *bitreader.ReaderType) {
header := Header{
DemoFileStamp: reader.TryReadStringLen(8),
DemoProtocol: uint32(reader.TryReadInt32()),
NetworkProtocol: uint32(reader.TryReadInt32()),
ServerName: reader.TryReadStringLen(260),
ClientName: reader.TryReadStringLen(260),
MapName: reader.TryReadStringLen(260),
GameDirectory: reader.TryReadStringLen(260),
PlaybackTime: reader.TryReadFloat32(),
PlaybackTicks: int32(reader.TryReadInt32()),
PlaybackFrames: int32(reader.TryReadInt32()),
SignOnLength: uint32(reader.TryReadInt32()),
}
if header.DemoFileStamp != "HL2DEMO" {
panic("Invalid demo file stamp. Make sure a valid demo file is given.")
}
if header.DemoProtocol != 4 {
panic("Given demo is from old engine. This parser is only supported for new engine.")
}
if header.NetworkProtocol != 2001 {
panic("Given demo is not from Portal2. This parser currently only supports Portal 2.")
}
fmt.Println(header)
}
|