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/classes | |
| 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/classes')
| -rw-r--r-- | packets/classes/stringtable.go | 36 | ||||
| -rw-r--r-- | packets/classes/types.go | 18 | ||||
| -rw-r--r-- | packets/classes/usercmd.go | 45 |
3 files changed, 57 insertions, 42 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 | } |