diff options
Diffstat (limited to 'packets/header.go')
| -rw-r--r-- | packets/header.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/packets/header.go b/packets/header.go new file mode 100644 index 0000000..60cd146 --- /dev/null +++ b/packets/header.go | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | package packets | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | func ParseHeader(reader *bitreader.ReaderType) { | ||
| 10 | header := Header{ | ||
| 11 | DemoFileStamp: reader.TryReadStringLen(8), | ||
| 12 | DemoProtocol: uint(reader.TryReadInt32()), | ||
| 13 | NetworkProtocol: uint(reader.TryReadInt32()), | ||
| 14 | ServerName: reader.TryReadStringLen(260), | ||
| 15 | ClientName: reader.TryReadStringLen(260), | ||
| 16 | MapName: reader.TryReadStringLen(260), | ||
| 17 | GameDirectory: reader.TryReadStringLen(260), | ||
| 18 | PlaybackTime: reader.TryReadFloat32(), | ||
| 19 | PlaybackTicks: int(reader.TryReadInt32()), | ||
| 20 | PlaybackFrames: int(reader.TryReadInt32()), | ||
| 21 | SignOnLength: uint(reader.TryReadInt32()), | ||
| 22 | } | ||
| 23 | if header.DemoFileStamp != "HL2DEMO" { | ||
| 24 | panic("Invalid demo file stamp. Make sure a valid demo file is given.") | ||
| 25 | } | ||
| 26 | if header.DemoProtocol != 4 { | ||
| 27 | panic("Given demo is from old engine. This parser is only supported for new engine.") | ||
| 28 | } | ||
| 29 | if header.NetworkProtocol != 2001 { | ||
| 30 | panic("Given demo is not from Portal2. This parser currently only supports Portal 2.") | ||
| 31 | } | ||
| 32 | fmt.Println(header) | ||
| 33 | } | ||