diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-11-07 16:09:44 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:37 +0300 |
| commit | a77cf8169b42a4394e62f7a381ca546b27d0f723 (patch) | |
| tree | 2dd8d4f51c5841b806e9b5ed6fe9054bce06e2e0 /packets | |
| parent | changed github username + other stuff that i don't remember (diff) | |
| download | sdp.go-a77cf8169b42a4394e62f7a381ca546b27d0f723.tar.gz sdp.go-a77cf8169b42a4394e62f7a381ca546b27d0f723.tar.bz2 sdp.go-a77cf8169b42a4394e62f7a381ca546b27d0f723.zip | |
starting fresh for the third time
Diffstat (limited to 'packets')
| -rw-r--r-- | packets/header.go | 33 | ||||
| -rw-r--r-- | packets/message.go | 64 | ||||
| -rw-r--r-- | packets/types.go | 64 |
3 files changed, 161 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 | } | ||
diff --git a/packets/message.go b/packets/message.go new file mode 100644 index 0000000..a8e830d --- /dev/null +++ b/packets/message.go | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | package packets | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | func ParseMessage(reader *bitreader.ReaderType) (status int) { | ||
| 10 | messageType := reader.TryReadInt8() | ||
| 11 | messageTick := reader.TryReadInt32() | ||
| 12 | messageSlot := reader.TryReadInt8() | ||
| 13 | //fmt.Println(messageType, messageTick, messageSlot) | ||
| 14 | switch messageType { | ||
| 15 | case 0x01: | ||
| 16 | //signOn := SignOn{} | ||
| 17 | reader.SkipBytes(76*2 + 8) | ||
| 18 | val := reader.TryReadInt32() | ||
| 19 | reader.SkipBytes(int(val)) | ||
| 20 | fmt.Printf("[%d] (%d) {%d} SignOn: \n", messageTick, messageType, messageSlot) | ||
| 21 | return 1 | ||
| 22 | case 0x02: | ||
| 23 | reader.SkipBytes(76*2 + 8) | ||
| 24 | val := reader.TryReadInt32() | ||
| 25 | reader.SkipBytes(int(val)) | ||
| 26 | // fmt.Printf("[%d] (%d) Packet: \n", messageTick, messageType) | ||
| 27 | return 2 | ||
| 28 | case 0x03: | ||
| 29 | fmt.Printf("[%d] (%d) SyncTick: \n", messageTick, messageType) | ||
| 30 | return 3 | ||
| 31 | case 0x04: | ||
| 32 | val := reader.TryReadInt32() | ||
| 33 | reader.SkipBytes(int(val)) | ||
| 34 | // fmt.Printf("[%d] (%d) ConsoleCmd: \n", messageTick, messageType) | ||
| 35 | return 4 | ||
| 36 | case 0x05: | ||
| 37 | reader.SkipBytes(4) | ||
| 38 | val := reader.TryReadInt32() | ||
| 39 | reader.SkipBytes(int(val)) | ||
| 40 | // fmt.Printf("[%d] (%d) UserCmd: \n", messageTick, messageType) | ||
| 41 | return 5 | ||
| 42 | case 0x06: | ||
| 43 | val := reader.TryReadInt32() | ||
| 44 | reader.SkipBytes(int(val)) | ||
| 45 | // fmt.Printf("[%d] (%d) DataTables: \n", messageTick, messageType) | ||
| 46 | return 6 | ||
| 47 | case 0x07: | ||
| 48 | fmt.Printf("[%d] (%d) Stop: \n", messageTick, messageType) | ||
| 49 | return 7 | ||
| 50 | case 0x08: | ||
| 51 | reader.SkipBytes(4) | ||
| 52 | val := reader.TryReadInt32() | ||
| 53 | reader.SkipBytes(int(val)) | ||
| 54 | // fmt.Printf("[%d] (%d) CustomData: \n", messageTick, messageType) | ||
| 55 | return 8 | ||
| 56 | case 0x09: | ||
| 57 | val := reader.TryReadInt32() | ||
| 58 | reader.SkipBytes(int(val)) | ||
| 59 | // fmt.Printf("[%d] (%d) StringTables: \n", messageTick, messageType) | ||
| 60 | return 9 | ||
| 61 | default: | ||
| 62 | return 0 | ||
| 63 | } | ||
| 64 | } | ||
diff --git a/packets/types.go b/packets/types.go new file mode 100644 index 0000000..5f7a29b --- /dev/null +++ b/packets/types.go | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | package packets | ||
| 2 | |||
| 3 | type Header struct { | ||
| 4 | DemoFileStamp string | ||
| 5 | DemoProtocol uint | ||
| 6 | NetworkProtocol uint | ||
| 7 | ServerName string | ||
| 8 | ClientName string | ||
| 9 | MapName string | ||
| 10 | GameDirectory string | ||
| 11 | PlaybackTime float32 | ||
| 12 | PlaybackTicks int | ||
| 13 | PlaybackFrames int | ||
| 14 | SignOnLength uint | ||
| 15 | } | ||
| 16 | |||
| 17 | type SignOn struct { | ||
| 18 | PacketInfo []byte | ||
| 19 | InSequence int32 | ||
| 20 | OutSequence int32 | ||
| 21 | Size int32 | ||
| 22 | Data []byte | ||
| 23 | } | ||
| 24 | |||
| 25 | type Packet struct { | ||
| 26 | PacketInfo []byte | ||
| 27 | InSequence int32 | ||
| 28 | OutSequence int32 | ||
| 29 | Size int32 | ||
| 30 | Data []byte | ||
| 31 | } | ||
| 32 | |||
| 33 | type SyncTick struct{} | ||
| 34 | |||
| 35 | type ConsoleCmd struct { | ||
| 36 | Size int32 | ||
| 37 | Data string | ||
| 38 | } | ||
| 39 | |||
| 40 | type UserCmd struct { | ||
| 41 | Cmd int32 | ||
| 42 | Size int32 | ||
| 43 | Data []byte | ||
| 44 | } | ||
| 45 | |||
| 46 | type DataTables struct { | ||
| 47 | Size int32 | ||
| 48 | Data []byte | ||
| 49 | } | ||
| 50 | |||
| 51 | type Stop struct { | ||
| 52 | RemainingData []byte | ||
| 53 | } | ||
| 54 | |||
| 55 | type CustomData struct { | ||
| 56 | Unknown int32 | ||
| 57 | Size int32 | ||
| 58 | Data []byte | ||
| 59 | } | ||
| 60 | |||
| 61 | type StringTables struct { | ||
| 62 | Size int32 | ||
| 63 | Data []byte | ||
| 64 | } | ||