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 /pkg/classes/sendTable.go | |
| 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 'pkg/classes/sendTable.go')
| -rw-r--r-- | pkg/classes/sendTable.go | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/pkg/classes/sendTable.go b/pkg/classes/sendTable.go new file mode 100644 index 0000000..4521464 --- /dev/null +++ b/pkg/classes/sendTable.go | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | ) | ||
| 6 | |||
| 7 | type SendTable struct { | ||
| 8 | NeedsDecoder bool | ||
| 9 | NetTableName string | ||
| 10 | NumOfProps int16 | ||
| 11 | Props []prop | ||
| 12 | } | ||
| 13 | |||
| 14 | type prop struct { | ||
| 15 | SendPropType int8 | ||
| 16 | SendPropName string | ||
| 17 | SendPropFlags int32 | ||
| 18 | Priority int8 | ||
| 19 | ExcludeDtName string | ||
| 20 | LowValue float32 | ||
| 21 | HighValue float32 | ||
| 22 | NumBits int32 | ||
| 23 | NumElements int32 | ||
| 24 | } | ||
| 25 | |||
| 26 | type sendPropFlag int | ||
| 27 | |||
| 28 | const ( | ||
| 29 | Unsigned sendPropFlag = iota | ||
| 30 | Coord | ||
| 31 | NoScale | ||
| 32 | RoundDown | ||
| 33 | RoundUp | ||
| 34 | Normal | ||
| 35 | Exclude | ||
| 36 | Xyze | ||
| 37 | InsideArray | ||
| 38 | ProxyAlwaysYes | ||
| 39 | IsVectorElem | ||
| 40 | Collapsible | ||
| 41 | CoordMp | ||
| 42 | CoordMpLp // low precision | ||
| 43 | CoordMpInt | ||
| 44 | CellCoord | ||
| 45 | CellCoordLp | ||
| 46 | CellCoordInt | ||
| 47 | ChangesOften | ||
| 48 | ) | ||
| 49 | |||
| 50 | type sendPropType int | ||
| 51 | |||
| 52 | const ( | ||
| 53 | Int sendPropType = iota | ||
| 54 | Float | ||
| 55 | Vector3 | ||
| 56 | Vector2 | ||
| 57 | String | ||
| 58 | Array | ||
| 59 | DataTable | ||
| 60 | ) | ||
| 61 | |||
| 62 | func ParseSendTable(reader *bitreader.ReaderType) SendTable { | ||
| 63 | sendTable := SendTable{ | ||
| 64 | NeedsDecoder: reader.TryReadBool(), | ||
| 65 | NetTableName: reader.TryReadString(), | ||
| 66 | NumOfProps: int16(reader.TryReadBits(10)), | ||
| 67 | // SendPropType: int8(reader.TryReadBits(5)), | ||
| 68 | // SendPropName: reader.TryReadString(), | ||
| 69 | // SendPropFlags: int16(reader.TryReadBits(16)), | ||
| 70 | } | ||
| 71 | if sendTable.NumOfProps < 0 { | ||
| 72 | return sendTable | ||
| 73 | } | ||
| 74 | for count := 0; count < int(sendTable.NumOfProps); count++ { | ||
| 75 | propType := int8(reader.TryReadBits(5)) | ||
| 76 | if propType >= int8(7) { | ||
| 77 | return sendTable | ||
| 78 | } | ||
| 79 | prop := prop{ | ||
| 80 | SendPropType: propType, | ||
| 81 | SendPropName: reader.TryReadString(), | ||
| 82 | SendPropFlags: int32(reader.TryReadBits(19)), | ||
| 83 | Priority: int8(reader.TryReadBits(8)), | ||
| 84 | } | ||
| 85 | if propType == int8(DataTable) || CheckBit(int64(prop.SendPropFlags), int(Exclude)) { | ||
| 86 | prop.ExcludeDtName = reader.TryReadString() | ||
| 87 | } else { | ||
| 88 | switch propType { | ||
| 89 | case int8(String), int8(Int), int8(Float), int8(Vector3), int8(Vector2): | ||
| 90 | prop.LowValue = reader.TryReadFloat32() | ||
| 91 | prop.HighValue = reader.TryReadFloat32() | ||
| 92 | prop.NumBits = int32(reader.TryReadBits(7)) | ||
| 93 | case int8(Array): | ||
| 94 | prop.NumElements = int32(reader.TryReadBits(10)) | ||
| 95 | default: | ||
| 96 | return sendTable | ||
| 97 | } | ||
| 98 | } | ||
| 99 | sendTable.Props = append(sendTable.Props, prop) | ||
| 100 | } | ||
| 101 | return sendTable | ||
| 102 | } | ||
| 103 | |||
| 104 | func CheckBit(val int64, bit int) bool { | ||
| 105 | return (val & (int64(1) << bit)) != 0 | ||
| 106 | } | ||