From a77cf8169b42a4394e62f7a381ca546b27d0f723 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Mon, 7 Nov 2022 16:09:44 +0300 Subject: starting fresh for the third time --- packets/header.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 packets/header.go (limited to 'packets/header.go') 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 @@ +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) +} -- cgit v1.2.3