aboutsummaryrefslogtreecommitdiff
path: root/pkg/packets
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-11-06 18:37:11 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-11-06 18:37:11 +0300
commit2f8c92f261586f68a976efce0cfcdd0401f402e0 (patch)
tree33189cc48987789dff4e7fba0a74d2b2326f0a04 /pkg/packets
parentconvert cm ticks correctly (diff)
downloadsdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.tar.gz
sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.tar.bz2
sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.zip
dont try to understand it, feel itlp-parser
Diffstat (limited to 'pkg/packets')
-rw-r--r--pkg/packets/headers.go45
-rw-r--r--pkg/packets/packets.go54
2 files changed, 0 insertions, 99 deletions
diff --git a/pkg/packets/headers.go b/pkg/packets/headers.go
deleted file mode 100644
index ba5482b..0000000
--- a/pkg/packets/headers.go
+++ /dev/null
@@ -1,45 +0,0 @@
1package packets
2
3import (
4 "github.com/pektezol/bitreader"
5)
6
7type Headers struct {
8 DemoFileStamp string
9 DemoProtocol int32
10 NetworkProtocol int32
11 ServerName string
12 ClientName string
13 MapName string
14 GameDirectory string
15 PlaybackTime float32
16 PlaybackTicks int32
17 PlaybackFrames int32
18 SignOnLength int32
19}
20
21func ParseHeaders(reader *bitreader.Reader) Headers {
22 headers := Headers{
23 DemoFileStamp: reader.TryReadString(),
24 DemoProtocol: int32(reader.TryReadSInt32()),
25 NetworkProtocol: int32(reader.TryReadSInt32()),
26 ServerName: reader.TryReadStringLength(260),
27 ClientName: reader.TryReadStringLength(260),
28 MapName: reader.TryReadStringLength(260),
29 GameDirectory: reader.TryReadStringLength(260),
30 PlaybackTime: reader.TryReadFloat32(),
31 PlaybackTicks: int32(reader.TryReadSInt32()),
32 PlaybackFrames: int32(reader.TryReadSInt32()),
33 SignOnLength: int32(reader.TryReadSInt32()),
34 }
35 if headers.DemoFileStamp != "HL2DEMO" {
36 panic("invalid demo file stamp")
37 }
38 if headers.DemoProtocol != 4 {
39 panic("this parser only supports demos from new engine")
40 }
41 if headers.NetworkProtocol != 2001 {
42 panic("this parser only supports demos from portal 2")
43 }
44 return headers
45}
diff --git a/pkg/packets/packets.go b/pkg/packets/packets.go
deleted file mode 100644
index 02ad806..0000000
--- a/pkg/packets/packets.go
+++ /dev/null
@@ -1,54 +0,0 @@
1package packets
2
3import (
4 "github.com/pektezol/bitreader"
5 "github.com/pektezol/demoparser/pkg/classes"
6)
7
8type PacketMessageInfo struct {
9 PacketType uint8
10 TickNumber int32
11 SlotNumber uint8
12}
13
14func ParsePackets(reader *bitreader.Reader) PacketMessageInfo {
15 packetType := reader.TryReadUInt8()
16 tickNumber := reader.TryReadSInt32()
17 slotNumber := reader.TryReadUInt8()
18 switch packetType {
19 case 1: // SignOn
20 signOn := classes.SignOn{}
21 signOn.ParseSignOn(reader)
22 case 2: // Packet
23 packet := classes.Packet{}
24 packet.ParsePacket(reader)
25 case 3: // SyncTick
26 syncTick := classes.SyncTick{}
27 syncTick.ParseSyncTick()
28 case 4: // ConsoleCmd
29 consoleCmd := classes.ConsoleCmd{}
30 consoleCmd.ParseConsoleCmd(reader)
31 case 5: // UserCmd
32 userCmd := classes.UserCmd{}
33 userCmd.ParseUserCmd(reader)
34 case 6: // DataTables
35 dataTables := classes.DataTables{}
36 dataTables.ParseDataTables(reader)
37 case 7: // Stop
38 stop := classes.Stop{}
39 stop.ParseStop(reader)
40 case 8: // CustomData TODO: not sar data
41 customData := classes.CustomData{}
42 customData.ParseCustomData(reader, tickNumber, packetType)
43 case 9: // StringTables TODO: parsing string table data
44 stringTables := classes.StringTables{}
45 stringTables.ParseStringTables(reader)
46 default: // Invalid
47 panic("invalid packet type")
48 }
49 return PacketMessageInfo{
50 PacketType: packetType,
51 TickNumber: tickNumber,
52 SlotNumber: slotNumber,
53 }
54}