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 '')
| -rw-r--r-- | packets/header.go | 33 | ||||
| -rw-r--r-- | packets/message.go | 64 | ||||
| -rw-r--r-- | packets/types.go (renamed from messages/types.go) | 36 |
3 files changed, 121 insertions, 12 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/messages/types.go b/packets/types.go index 9c92c54..5f7a29b 100644 --- a/messages/types.go +++ b/packets/types.go | |||
| @@ -1,29 +1,37 @@ | |||
| 1 | package messages | 1 | package packets |
| 2 | |||
| 3 | import "github.com/pektezol/demoparser/classes" | ||
| 4 | 2 | ||
| 5 | type Header struct { | 3 | type Header struct { |
| 6 | DemoFileStamp string | 4 | DemoFileStamp string |
| 7 | DemoProtocol int32 | 5 | DemoProtocol uint |
| 8 | NetworkProtocol int32 | 6 | NetworkProtocol uint |
| 9 | ServerName string | 7 | ServerName string |
| 10 | ClientName string | 8 | ClientName string |
| 11 | MapName string | 9 | MapName string |
| 12 | GameDirectory string | 10 | GameDirectory string |
| 13 | PlaybackTime float32 | 11 | PlaybackTime float32 |
| 14 | PlaybackTicks int32 | 12 | PlaybackTicks int |
| 15 | PlaybackFrames int32 | 13 | PlaybackFrames int |
| 16 | SignOnLength int32 | 14 | SignOnLength uint |
| 15 | } | ||
| 16 | |||
| 17 | type SignOn struct { | ||
| 18 | PacketInfo []byte | ||
| 19 | InSequence int32 | ||
| 20 | OutSequence int32 | ||
| 21 | Size int32 | ||
| 22 | Data []byte | ||
| 17 | } | 23 | } |
| 18 | 24 | ||
| 19 | type Packet struct { | 25 | type Packet struct { |
| 20 | PacketInfo []classes.CmdInfo | 26 | PacketInfo []byte |
| 21 | InSequence int32 | 27 | InSequence int32 |
| 22 | OutSequence int32 | 28 | OutSequence int32 |
| 23 | Size int32 | 29 | Size int32 |
| 24 | Data []byte | 30 | Data []byte |
| 25 | } | 31 | } |
| 26 | 32 | ||
| 33 | type SyncTick struct{} | ||
| 34 | |||
| 27 | type ConsoleCmd struct { | 35 | type ConsoleCmd struct { |
| 28 | Size int32 | 36 | Size int32 |
| 29 | Data string | 37 | Data string |
| @@ -32,12 +40,16 @@ type ConsoleCmd struct { | |||
| 32 | type UserCmd struct { | 40 | type UserCmd struct { |
| 33 | Cmd int32 | 41 | Cmd int32 |
| 34 | Size int32 | 42 | Size int32 |
| 35 | Data classes.UserCmdInfo | 43 | Data []byte |
| 36 | } | 44 | } |
| 37 | 45 | ||
| 38 | type DataTables struct { | 46 | type DataTables struct { |
| 39 | Size int32 | 47 | Size int32 |
| 40 | Data classes.DataTables | 48 | Data []byte |
| 49 | } | ||
| 50 | |||
| 51 | type Stop struct { | ||
| 52 | RemainingData []byte | ||
| 41 | } | 53 | } |
| 42 | 54 | ||
| 43 | type CustomData struct { | 55 | type CustomData struct { |
| @@ -48,5 +60,5 @@ type CustomData struct { | |||
| 48 | 60 | ||
| 49 | type StringTables struct { | 61 | type StringTables struct { |
| 50 | Size int32 | 62 | Size int32 |
| 51 | Data []classes.StringTable | 63 | Data []byte |
| 52 | } | 64 | } |