From 82871ba1bac1d62f69e1933b66659e62d2e5e063 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 12 Sep 2023 20:53:09 +0300 Subject: another rewrite, v1.0.0 --- pkg/packets/headers.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 pkg/packets/headers.go (limited to 'pkg/packets/headers.go') diff --git a/pkg/packets/headers.go b/pkg/packets/headers.go new file mode 100644 index 0000000..543476b --- /dev/null +++ b/pkg/packets/headers.go @@ -0,0 +1,48 @@ +package packets + +import ( + "fmt" + + "github.com/pektezol/bitreader" +) + +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.ReaderType) Headers { + headers := Headers{ + DemoFileStamp: reader.TryReadString(), + DemoProtocol: int32(reader.TryReadInt32()), + NetworkProtocol: int32(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: int32(reader.TryReadInt32()), + } + 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") + } + fmt.Printf("Headers: %+v\n", headers) + return headers +} -- cgit v1.2.3