diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-12 20:53:09 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:42 +0300 |
| commit | 82871ba1bac1d62f69e1933b66659e62d2e5e063 (patch) | |
| tree | a906310fba89b670bcfda9625a6d776553d482f6 /packets/classes | |
| parent | net/svc messages finally getting parsed correctly (diff) | |
| download | sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.gz sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.bz2 sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.zip | |
another rewrite, v1.0.0
Diffstat (limited to 'packets/classes')
| -rw-r--r-- | packets/classes/cmdinfo.go | 61 | ||||
| -rw-r--r-- | packets/classes/datatable.go | 66 | ||||
| -rw-r--r-- | packets/classes/stringtable.go | 51 | ||||
| -rw-r--r-- | packets/classes/usercmd.go | 80 |
4 files changed, 0 insertions, 258 deletions
diff --git a/packets/classes/cmdinfo.go b/packets/classes/cmdinfo.go deleted file mode 100644 index d11bebc..0000000 --- a/packets/classes/cmdinfo.go +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type CmdInfo struct { | ||
| 6 | Flags int32 | ||
| 7 | ViewOrigin []float32 | ||
| 8 | ViewAngles []float32 | ||
| 9 | LocalViewAngles []float32 | ||
| 10 | ViewOrigin2 []float32 | ||
| 11 | ViewAngles2 []float32 | ||
| 12 | LocalViewAngles2 []float32 | ||
| 13 | } | ||
| 14 | |||
| 15 | func ParseCmdInfo(reader *bitreader.ReaderType, MSSC int) []CmdInfo { | ||
| 16 | var out []CmdInfo | ||
| 17 | for i := 0; i < MSSC; i++ { | ||
| 18 | flags := int32(reader.TryReadInt32()) | ||
| 19 | viewOrigin := []float32{ | ||
| 20 | reader.TryReadFloat32(), | ||
| 21 | reader.TryReadFloat32(), | ||
| 22 | reader.TryReadFloat32(), | ||
| 23 | } | ||
| 24 | viewAngles := []float32{ | ||
| 25 | reader.TryReadFloat32(), | ||
| 26 | reader.TryReadFloat32(), | ||
| 27 | reader.TryReadFloat32(), | ||
| 28 | } | ||
| 29 | localViewAngles := []float32{ | ||
| 30 | reader.TryReadFloat32(), | ||
| 31 | reader.TryReadFloat32(), | ||
| 32 | reader.TryReadFloat32(), | ||
| 33 | } | ||
| 34 | viewOrigin2 := []float32{ | ||
| 35 | reader.TryReadFloat32(), | ||
| 36 | reader.TryReadFloat32(), | ||
| 37 | reader.TryReadFloat32(), | ||
| 38 | } | ||
| 39 | viewAngles2 := []float32{ | ||
| 40 | reader.TryReadFloat32(), | ||
| 41 | reader.TryReadFloat32(), | ||
| 42 | reader.TryReadFloat32(), | ||
| 43 | } | ||
| 44 | localViewAngles2 := []float32{ | ||
| 45 | reader.TryReadFloat32(), | ||
| 46 | reader.TryReadFloat32(), | ||
| 47 | reader.TryReadFloat32(), | ||
| 48 | } | ||
| 49 | cmdInfo := CmdInfo{ | ||
| 50 | Flags: flags, | ||
| 51 | ViewOrigin: viewOrigin, | ||
| 52 | ViewAngles: viewAngles, | ||
| 53 | LocalViewAngles: localViewAngles, | ||
| 54 | ViewOrigin2: viewOrigin2, | ||
| 55 | ViewAngles2: viewAngles2, | ||
| 56 | LocalViewAngles2: localViewAngles2, | ||
| 57 | } | ||
| 58 | out = append(out, cmdInfo) | ||
| 59 | } | ||
| 60 | return out | ||
| 61 | } | ||
diff --git a/packets/classes/datatable.go b/packets/classes/datatable.go deleted file mode 100644 index 405dae6..0000000 --- a/packets/classes/datatable.go +++ /dev/null | |||
| @@ -1,66 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | "fmt" | ||
| 6 | |||
| 7 | "github.com/pektezol/bitreader" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type DataTable struct { | ||
| 11 | SendTable []SendTable | ||
| 12 | ServerClassInfo []ServerClassInfo | ||
| 13 | } | ||
| 14 | |||
| 15 | type SendTable struct { | ||
| 16 | NeedsDecoder bool | ||
| 17 | NetTableName string | ||
| 18 | NumOfProps uint16 | ||
| 19 | SendPropType int8 | ||
| 20 | SendPropName string | ||
| 21 | SendPropFlags int16 | ||
| 22 | } | ||
| 23 | |||
| 24 | type ServerClassInfo struct { | ||
| 25 | ClassId int16 | ||
| 26 | ClassName string | ||
| 27 | DataTableName string | ||
| 28 | } | ||
| 29 | |||
| 30 | func ParseDataTable(data []byte) DataTable { | ||
| 31 | reader := bitreader.Reader(bytes.NewReader(data), true) | ||
| 32 | sendtable := parseSendTable(reader) | ||
| 33 | serverclassinfo := parseServerClassInfo(reader) | ||
| 34 | return DataTable{ | ||
| 35 | SendTable: sendtable, | ||
| 36 | ServerClassInfo: serverclassinfo, | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | func parseSendTable(reader *bitreader.ReaderType) []SendTable { | ||
| 41 | var sendtables []SendTable | ||
| 42 | for reader.TryReadBool() { | ||
| 43 | sendtables = append(sendtables, SendTable{ | ||
| 44 | NeedsDecoder: reader.TryReadBool(), | ||
| 45 | NetTableName: reader.TryReadString(), | ||
| 46 | NumOfProps: uint16(reader.TryReadBits(10)), | ||
| 47 | SendPropType: int8(reader.TryReadBits(5)), | ||
| 48 | SendPropName: reader.TryReadString(), | ||
| 49 | SendPropFlags: int16(reader.TryReadInt16()), | ||
| 50 | }) | ||
| 51 | } | ||
| 52 | return sendtables | ||
| 53 | } | ||
| 54 | func parseServerClassInfo(reader *bitreader.ReaderType) []ServerClassInfo { | ||
| 55 | var serverclassinfo []ServerClassInfo | ||
| 56 | numofclasses := reader.TryReadInt16() | ||
| 57 | fmt.Println(numofclasses) | ||
| 58 | for i := 0; i < int(numofclasses); i++ { | ||
| 59 | serverclassinfo = append(serverclassinfo, ServerClassInfo{ | ||
| 60 | ClassId: int16(reader.TryReadInt16()), | ||
| 61 | ClassName: reader.TryReadString(), | ||
| 62 | DataTableName: reader.TryReadString(), | ||
| 63 | }) | ||
| 64 | } | ||
| 65 | return serverclassinfo | ||
| 66 | } | ||
diff --git a/packets/classes/stringtable.go b/packets/classes/stringtable.go deleted file mode 100644 index a1432f9..0000000 --- a/packets/classes/stringtable.go +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type StringTable struct { | ||
| 10 | TableName string | ||
| 11 | NumOfEntries int16 | ||
| 12 | EntryName string | ||
| 13 | EntrySize int16 | ||
| 14 | EntryData []byte | ||
| 15 | NumOfClientEntries int16 | ||
| 16 | ClientEntryName string | ||
| 17 | ClientEntrySize int16 | ||
| 18 | ClientEntryData []byte | ||
| 19 | } | ||
| 20 | |||
| 21 | func ParseStringTable(data []byte) []StringTable { | ||
| 22 | reader := bitreader.Reader(bytes.NewReader(data), true) | ||
| 23 | var stringTables []StringTable | ||
| 24 | numOfTables := reader.TryReadInt8() | ||
| 25 | for i := 0; i < int(numOfTables); i++ { | ||
| 26 | var stringTable StringTable | ||
| 27 | stringTable.TableName = reader.TryReadString() | ||
| 28 | stringTable.NumOfEntries = int16(reader.TryReadInt16()) | ||
| 29 | stringTable.EntryName = reader.TryReadString() | ||
| 30 | if reader.TryReadBool() { | ||
| 31 | stringTable.EntrySize = int16(reader.TryReadInt16()) | ||
| 32 | } | ||
| 33 | if reader.TryReadBool() { | ||
| 34 | stringTable.EntryData = reader.TryReadBytesToSlice(int(stringTable.EntrySize)) | ||
| 35 | } | ||
| 36 | if reader.TryReadBool() { | ||
| 37 | stringTable.NumOfClientEntries = int16(reader.TryReadInt16()) | ||
| 38 | } | ||
| 39 | if reader.TryReadBool() { | ||
| 40 | stringTable.ClientEntryName = reader.TryReadString() | ||
| 41 | } | ||
| 42 | if reader.TryReadBool() { | ||
| 43 | stringTable.ClientEntrySize = int16(reader.TryReadInt16()) | ||
| 44 | } | ||
| 45 | if reader.TryReadBool() { | ||
| 46 | stringTable.ClientEntryData = reader.TryReadBytesToSlice(int(stringTable.ClientEntrySize)) | ||
| 47 | } | ||
| 48 | stringTables = append(stringTables, stringTable) | ||
| 49 | } | ||
| 50 | return stringTables | ||
| 51 | } | ||
diff --git a/packets/classes/usercmd.go b/packets/classes/usercmd.go deleted file mode 100644 index d3328fd..0000000 --- a/packets/classes/usercmd.go +++ /dev/null | |||
| @@ -1,80 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type UserCmdInfo struct { | ||
| 10 | CommandNumber int32 | ||
| 11 | TickCount int32 | ||
| 12 | ViewAnglesX float32 | ||
| 13 | ViewAnglesY float32 | ||
| 14 | ViewAnglesZ float32 | ||
| 15 | ForwardMove float32 | ||
| 16 | SideMove float32 | ||
| 17 | UpMove float32 | ||
| 18 | Buttons int32 | ||
| 19 | Impulse byte | ||
| 20 | WeaponSelect int | ||
| 21 | WeaponSubtype int | ||
| 22 | MouseDx int16 | ||
| 23 | MouseDy int16 | ||
| 24 | } | ||
| 25 | |||
| 26 | func ParseUserCmdInfo(data []byte) UserCmdInfo { | ||
| 27 | reader := bitreader.Reader(bytes.NewReader(data), true) | ||
| 28 | var userCmdInfo UserCmdInfo | ||
| 29 | if reader.TryReadBool() { | ||
| 30 | userCmdInfo.CommandNumber = int32(reader.TryReadInt32()) | ||
| 31 | } | ||
| 32 | if reader.TryReadBool() { | ||
| 33 | userCmdInfo.TickCount = int32(reader.TryReadInt32()) | ||
| 34 | } | ||
| 35 | if reader.TryReadBool() { | ||
| 36 | userCmdInfo.ViewAnglesX = reader.TryReadFloat32() | ||
| 37 | } | ||
| 38 | if reader.TryReadBool() { | ||
| 39 | userCmdInfo.ViewAnglesY = reader.TryReadFloat32() | ||
| 40 | } | ||
| 41 | if reader.TryReadBool() { | ||
| 42 | userCmdInfo.ViewAnglesZ = reader.TryReadFloat32() | ||
| 43 | } | ||
| 44 | if reader.TryReadBool() { | ||
| 45 | userCmdInfo.ForwardMove = reader.TryReadFloat32() | ||
| 46 | } | ||
| 47 | if reader.TryReadBool() { | ||
| 48 | userCmdInfo.SideMove = reader.TryReadFloat32() | ||
| 49 | } | ||
| 50 | if reader.TryReadBool() { | ||
| 51 | userCmdInfo.UpMove = reader.TryReadFloat32() | ||
| 52 | } | ||
| 53 | if reader.TryReadBool() { | ||
| 54 | userCmdInfo.Buttons = int32(reader.TryReadInt32()) | ||
| 55 | } | ||
| 56 | if reader.TryReadBool() { | ||
| 57 | userCmdInfo.Impulse = reader.TryReadInt8() | ||
| 58 | } | ||
| 59 | if reader.TryReadBool() { | ||
| 60 | value, err := reader.ReadBits(11) | ||
| 61 | if err != nil { | ||
| 62 | panic(err) | ||
| 63 | } | ||
| 64 | userCmdInfo.WeaponSelect = int(value) | ||
| 65 | if reader.TryReadBool() { | ||
| 66 | value, err := reader.ReadBits(6) | ||
| 67 | if err != nil { | ||
| 68 | panic(err) | ||
| 69 | } | ||
| 70 | userCmdInfo.WeaponSubtype = int(value) | ||
| 71 | } | ||
| 72 | } | ||
| 73 | if reader.TryReadBool() { | ||
| 74 | userCmdInfo.MouseDx = int16(reader.TryReadInt16()) | ||
| 75 | } | ||
| 76 | if reader.TryReadBool() { | ||
| 77 | userCmdInfo.MouseDy = int16(reader.TryReadInt16()) | ||
| 78 | } | ||
| 79 | return userCmdInfo | ||
| 80 | } | ||