blob: 60cd14657654fc41f45e2e2b137ce238c685714b (
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: uint(reader.TryReadInt32()),
NetworkProtocol: uint(reader.TryReadInt32()),
ServerName: reader.TryReadStringLen(260),
ClientName: reader.TryReadStringLen(260),
MapName: reader.TryReadStringLen(260),
GameDirectory: reader.TryReadStringLen(260),
PlaybackTime: reader.TryReadFloat32(),
PlaybackTicks: int(reader.TryReadInt32()),
PlaybackFrames: int(reader.TryReadInt32()),
SignOnLength: uint(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)
}
|