diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-11-07 18:42:28 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:38 +0300 |
| commit | 8352bfc1d8deedd4d6a0a5b0698fe1f8b9a06e88 (patch) | |
| tree | 69fd0825f69ff70fe0c8ae597cfe20a91af2d961 /packets | |
| parent | starting stringtable (diff) | |
| download | sdp.go-8352bfc1d8deedd4d6a0a5b0698fe1f8b9a06e88.tar.gz sdp.go-8352bfc1d8deedd4d6a0a5b0698fe1f8b9a06e88.tar.bz2 sdp.go-8352bfc1d8deedd4d6a0a5b0698fe1f8b9a06e88.zip | |
stringtable done, can't see data properly
Diffstat (limited to 'packets')
| -rw-r--r-- | packets/classes/stringtable.go | 36 | ||||
| -rw-r--r-- | packets/classes/types.go | 18 | ||||
| -rw-r--r-- | packets/classes/usercmd.go | 45 | ||||
| -rw-r--r-- | packets/message.go | 17 | ||||
| -rw-r--r-- | packets/types.go | 2 |
5 files changed, 67 insertions, 51 deletions
diff --git a/packets/classes/stringtable.go b/packets/classes/stringtable.go index df8e840..64e8496 100644 --- a/packets/classes/stringtable.go +++ b/packets/classes/stringtable.go | |||
| @@ -1,5 +1,39 @@ | |||
| 1 | package classes | 1 | package classes |
| 2 | 2 | ||
| 3 | func ParseStringTable() { | 3 | import ( |
| 4 | "bytes" | ||
| 4 | 5 | ||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | func ParseStringTable(data []byte) []StringTable { | ||
| 10 | reader := bitreader.Reader(bytes.NewReader(data), true) | ||
| 11 | var stringTables []StringTable | ||
| 12 | numOfTables := reader.TryReadInt8() | ||
| 13 | for i := 0; i < int(numOfTables); i++ { | ||
| 14 | var stringTable StringTable | ||
| 15 | stringTable.TableName = reader.TryReadString() | ||
| 16 | stringTable.NumOfEntries = int16(reader.TryReadInt16()) | ||
| 17 | stringTable.EntryName = reader.TryReadString() | ||
| 18 | if reader.TryReadBool() { | ||
| 19 | stringTable.EntrySize = int16(reader.TryReadInt16()) | ||
| 20 | } | ||
| 21 | if reader.TryReadBool() { | ||
| 22 | stringTable.EntryData = reader.TryReadBytesToSlice(int(stringTable.EntrySize)) | ||
| 23 | } | ||
| 24 | if reader.TryReadBool() { | ||
| 25 | stringTable.NumOfClientEntries = int16(reader.TryReadInt16()) | ||
| 26 | } | ||
| 27 | if reader.TryReadBool() { | ||
| 28 | stringTable.ClientEntryName = reader.TryReadString() | ||
| 29 | } | ||
| 30 | if reader.TryReadBool() { | ||
| 31 | stringTable.ClientEntrySize = int16(reader.TryReadInt16()) | ||
| 32 | } | ||
| 33 | if reader.TryReadBool() { | ||
| 34 | stringTable.ClientEntryData = reader.TryReadBytesToSlice(int(stringTable.ClientEntrySize)) | ||
| 35 | } | ||
| 36 | stringTables = append(stringTables, stringTable) | ||
| 37 | } | ||
| 38 | return stringTables | ||
| 5 | } | 39 | } |
diff --git a/packets/classes/types.go b/packets/classes/types.go index 8e630b6..a1a281e 100644 --- a/packets/classes/types.go +++ b/packets/classes/types.go | |||
| @@ -11,18 +11,30 @@ type CmdInfo struct { | |||
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | type UserCmdInfo struct { | 13 | type UserCmdInfo struct { |
| 14 | CommandNumber int | 14 | CommandNumber int32 |
| 15 | TickCount int | 15 | TickCount int32 |
| 16 | ViewAnglesX float32 | 16 | ViewAnglesX float32 |
| 17 | ViewAnglesY float32 | 17 | ViewAnglesY float32 |
| 18 | ViewAnglesZ float32 | 18 | ViewAnglesZ float32 |
| 19 | ForwardMove float32 | 19 | ForwardMove float32 |
| 20 | SideMove float32 | 20 | SideMove float32 |
| 21 | UpMove float32 | 21 | UpMove float32 |
| 22 | Buttons int | 22 | Buttons int32 |
| 23 | Impulse byte | 23 | Impulse byte |
| 24 | WeaponSelect int | 24 | WeaponSelect int |
| 25 | WeaponSubtype int | 25 | WeaponSubtype int |
| 26 | MouseDx int16 | 26 | MouseDx int16 |
| 27 | MouseDy int16 | 27 | MouseDy int16 |
| 28 | } | 28 | } |
| 29 | |||
| 30 | type StringTable struct { | ||
| 31 | TableName string | ||
| 32 | NumOfEntries int16 | ||
| 33 | EntryName string | ||
| 34 | EntrySize int16 | ||
| 35 | EntryData []byte | ||
| 36 | NumOfClientEntries int16 | ||
| 37 | ClientEntryName string | ||
| 38 | ClientEntrySize int16 | ||
| 39 | ClientEntryData []byte | ||
| 40 | } | ||
diff --git a/packets/classes/usercmd.go b/packets/classes/usercmd.go index a3183b6..78e9c58 100644 --- a/packets/classes/usercmd.go +++ b/packets/classes/usercmd.go | |||
| @@ -1,94 +1,63 @@ | |||
| 1 | package classes | 1 | package classes |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "bytes" | ||
| 5 | |||
| 4 | "github.com/pektezol/bitreader" | 6 | "github.com/pektezol/bitreader" |
| 5 | ) | 7 | ) |
| 6 | 8 | ||
| 7 | func ParseUserCmdInfo(reader *bitreader.ReaderType, size int) UserCmdInfo { | 9 | func ParseUserCmdInfo(data []byte) UserCmdInfo { |
| 8 | var bitCount int | 10 | reader := bitreader.Reader(bytes.NewReader(data), true) |
| 9 | var userCmdInfo UserCmdInfo | 11 | var userCmdInfo UserCmdInfo |
| 10 | if reader.TryReadBool() { | 12 | if reader.TryReadBool() { |
| 11 | userCmdInfo.CommandNumber = int(reader.TryReadInt32()) | 13 | userCmdInfo.CommandNumber = int32(reader.TryReadInt32()) |
| 12 | bitCount += 32 | ||
| 13 | } | 14 | } |
| 14 | bitCount++ | ||
| 15 | if reader.TryReadBool() { | 15 | if reader.TryReadBool() { |
| 16 | userCmdInfo.TickCount = int(reader.TryReadInt32()) | 16 | userCmdInfo.TickCount = int32(reader.TryReadInt32()) |
| 17 | bitCount += 32 | ||
| 18 | } | 17 | } |
| 19 | bitCount++ | ||
| 20 | if reader.TryReadBool() { | 18 | if reader.TryReadBool() { |
| 21 | userCmdInfo.ViewAnglesX = reader.TryReadFloat32() | 19 | userCmdInfo.ViewAnglesX = reader.TryReadFloat32() |
| 22 | bitCount += 32 | ||
| 23 | } | 20 | } |
| 24 | bitCount++ | ||
| 25 | if reader.TryReadBool() { | 21 | if reader.TryReadBool() { |
| 26 | userCmdInfo.ViewAnglesY = reader.TryReadFloat32() | 22 | userCmdInfo.ViewAnglesY = reader.TryReadFloat32() |
| 27 | bitCount += 32 | ||
| 28 | } | 23 | } |
| 29 | bitCount++ | ||
| 30 | if reader.TryReadBool() { | 24 | if reader.TryReadBool() { |
| 31 | userCmdInfo.ViewAnglesZ = reader.TryReadFloat32() | 25 | userCmdInfo.ViewAnglesZ = reader.TryReadFloat32() |
| 32 | bitCount += 32 | ||
| 33 | } | 26 | } |
| 34 | bitCount++ | ||
| 35 | if reader.TryReadBool() { | 27 | if reader.TryReadBool() { |
| 36 | userCmdInfo.ForwardMove = reader.TryReadFloat32() | 28 | userCmdInfo.ForwardMove = reader.TryReadFloat32() |
| 37 | bitCount += 32 | ||
| 38 | } | 29 | } |
| 39 | bitCount++ | ||
| 40 | if reader.TryReadBool() { | 30 | if reader.TryReadBool() { |
| 41 | userCmdInfo.SideMove = reader.TryReadFloat32() | 31 | userCmdInfo.SideMove = reader.TryReadFloat32() |
| 42 | bitCount += 32 | ||
| 43 | } | 32 | } |
| 44 | bitCount++ | ||
| 45 | if reader.TryReadBool() { | 33 | if reader.TryReadBool() { |
| 46 | userCmdInfo.UpMove = reader.TryReadFloat32() | 34 | userCmdInfo.UpMove = reader.TryReadFloat32() |
| 47 | bitCount += 32 | ||
| 48 | } | 35 | } |
| 49 | bitCount++ | ||
| 50 | if reader.TryReadBool() { | 36 | if reader.TryReadBool() { |
| 51 | userCmdInfo.Buttons = int(reader.TryReadInt32()) | 37 | userCmdInfo.Buttons = int32(reader.TryReadInt32()) |
| 52 | bitCount += 32 | ||
| 53 | } | 38 | } |
| 54 | bitCount++ | ||
| 55 | if reader.TryReadBool() { | 39 | if reader.TryReadBool() { |
| 56 | userCmdInfo.Impulse = reader.TryReadInt8() | 40 | userCmdInfo.Impulse = reader.TryReadInt8() |
| 57 | bitCount += 8 | ||
| 58 | } | 41 | } |
| 59 | bitCount++ | ||
| 60 | if reader.TryReadBool() { | 42 | if reader.TryReadBool() { |
| 61 | value, err := reader.ReadBits(11) | 43 | value, err := reader.ReadBits(11) |
| 62 | if err != nil { | 44 | if err != nil { |
| 63 | panic(err) | 45 | panic(err) |
| 64 | } | 46 | } |
| 65 | userCmdInfo.WeaponSelect = int(value) | 47 | userCmdInfo.WeaponSelect = int(value) |
| 66 | bitCount += 11 | ||
| 67 | if reader.TryReadBool() { | 48 | if reader.TryReadBool() { |
| 68 | value, err := reader.ReadBits(6) | 49 | value, err := reader.ReadBits(6) |
| 69 | if err != nil { | 50 | if err != nil { |
| 70 | panic(err) | 51 | panic(err) |
| 71 | } | 52 | } |
| 72 | userCmdInfo.WeaponSubtype = int(value) | 53 | userCmdInfo.WeaponSubtype = int(value) |
| 73 | bitCount += 6 | ||
| 74 | } | 54 | } |
| 75 | bitCount++ | ||
| 76 | } | 55 | } |
| 77 | bitCount++ | ||
| 78 | if reader.TryReadBool() { | 56 | if reader.TryReadBool() { |
| 79 | userCmdInfo.MouseDx = int16(reader.TryReadInt16()) | 57 | userCmdInfo.MouseDx = int16(reader.TryReadInt16()) |
| 80 | bitCount += 16 | ||
| 81 | } | 58 | } |
| 82 | bitCount++ | ||
| 83 | if reader.TryReadBool() { | 59 | if reader.TryReadBool() { |
| 84 | userCmdInfo.MouseDy = int16(reader.TryReadInt16()) | 60 | userCmdInfo.MouseDy = int16(reader.TryReadInt16()) |
| 85 | bitCount += 16 | ||
| 86 | } | 61 | } |
| 87 | bitCount++ | ||
| 88 | /*if bitCount > size*8 { | ||
| 89 | //reader.SkipBits(size * 8) | ||
| 90 | return userCmdInfo | ||
| 91 | }*/ | ||
| 92 | reader.SkipBits(size*8 - bitCount) | ||
| 93 | return userCmdInfo | 62 | return userCmdInfo |
| 94 | } | 63 | } |
diff --git a/packets/message.go b/packets/message.go index 3688ff9..922f918 100644 --- a/packets/message.go +++ b/packets/message.go | |||
| @@ -31,7 +31,6 @@ func ParseMessage(reader *bitreader.ReaderType) (status int) { | |||
| 31 | OutSequence: int32(reader.TryReadInt32()), | 31 | OutSequence: int32(reader.TryReadInt32()), |
| 32 | Size: int32(reader.TryReadInt32()), | 32 | Size: int32(reader.TryReadInt32()), |
| 33 | } | 33 | } |
| 34 | //classes.ParseUserCmdInfo(reader, packet.Size) | ||
| 35 | reader.SkipBytes(int(packet.Size)) | 34 | reader.SkipBytes(int(packet.Size)) |
| 36 | //fmt.Printf("[%d] (%d) Packet: %v\n", messageTick, messageType, packet) | 35 | //fmt.Printf("[%d] (%d) Packet: %v\n", messageTick, messageType, packet) |
| 37 | return 2 | 36 | return 2 |
| @@ -51,15 +50,15 @@ func ParseMessage(reader *bitreader.ReaderType) (status int) { | |||
| 51 | Cmd: int32(reader.TryReadInt32()), | 50 | Cmd: int32(reader.TryReadInt32()), |
| 52 | Size: int32(reader.TryReadInt32()), | 51 | Size: int32(reader.TryReadInt32()), |
| 53 | } | 52 | } |
| 54 | userCmd.Data = classes.ParseUserCmdInfo(reader, int(userCmd.Size)) | 53 | userCmd.Data = classes.ParseUserCmdInfo(reader.TryReadBytesToSlice(int(userCmd.Size))) |
| 55 | fmt.Printf("[%d] (%d) UserCmd: %v\n", messageTick, messageType, userCmd) | 54 | // fmt.Printf("[%d] (%d) UserCmd: %v\n", messageTick, messageType, userCmd) |
| 56 | return 5 | 55 | return 5 |
| 57 | case 0x06: // TODO: DataTables | 56 | case 0x06: // TODO: DataTables |
| 58 | val := reader.TryReadInt32() | 57 | val := reader.TryReadInt32() |
| 59 | reader.SkipBytes(int(val)) | 58 | reader.SkipBytes(int(val)) |
| 60 | // fmt.Printf("[%d] (%d) DataTables: \n", messageTick, messageType) | 59 | // fmt.Printf("[%d] (%d) DataTables: \n", messageTick, messageType) |
| 61 | return 6 | 60 | return 6 |
| 62 | case 0x07: // TODO: Stop - RemainingData | 61 | case 0x07: |
| 63 | stop := Stop{ | 62 | stop := Stop{ |
| 64 | RemainingData: nil, | 63 | RemainingData: nil, |
| 65 | } | 64 | } |
| @@ -71,10 +70,12 @@ func ParseMessage(reader *bitreader.ReaderType) (status int) { | |||
| 71 | reader.SkipBytes(int(val)) | 70 | reader.SkipBytes(int(val)) |
| 72 | // fmt.Printf("[%d] (%d) CustomData: \n", messageTick, messageType) | 71 | // fmt.Printf("[%d] (%d) CustomData: \n", messageTick, messageType) |
| 73 | return 8 | 72 | return 8 |
| 74 | case 0x09: // TODO: StringTables | 73 | case 0x09: // TODO: StringTables - Data |
| 75 | val := reader.TryReadInt32() | 74 | stringTables := StringTables{ |
| 76 | reader.SkipBytes(int(val)) | 75 | Size: int32(reader.TryReadInt32()), |
| 77 | // fmt.Printf("[%d] (%d) StringTables: \n", messageTick, messageType) | 76 | } |
| 77 | stringTables.Data = classes.ParseStringTable(reader.TryReadBytesToSlice(int(stringTables.Size))) | ||
| 78 | // fmt.Printf("[%d] (%d) StringTables: %v\n", messageTick, messageType, stringTables) | ||
| 78 | return 9 | 79 | return 9 |
| 79 | default: | 80 | default: |
| 80 | return 0 | 81 | return 0 |
diff --git a/packets/types.go b/packets/types.go index 5e75643..2a4cf4b 100644 --- a/packets/types.go +++ b/packets/types.go | |||
| @@ -62,5 +62,5 @@ type CustomData struct { | |||
| 62 | 62 | ||
| 63 | type StringTables struct { | 63 | type StringTables struct { |
| 64 | Size int32 | 64 | Size int32 |
| 65 | Data []byte | 65 | Data []classes.StringTable |
| 66 | } | 66 | } |