diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-11-06 18:37:11 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-11-06 18:37:11 +0300 |
| commit | 2f8c92f261586f68a976efce0cfcdd0401f402e0 (patch) | |
| tree | 33189cc48987789dff4e7fba0a74d2b2326f0a04 /pkg/classes/dataTables.go | |
| parent | convert cm ticks correctly (diff) | |
| download | sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.tar.gz sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.tar.bz2 sdp.go-2f8c92f261586f68a976efce0cfcdd0401f402e0.zip | |
dont try to understand it, feel itlp-parser
Diffstat (limited to 'pkg/classes/dataTables.go')
| -rw-r--r-- | pkg/classes/dataTables.go | 232 |
1 files changed, 0 insertions, 232 deletions
diff --git a/pkg/classes/dataTables.go b/pkg/classes/dataTables.go deleted file mode 100644 index c17e5f6..0000000 --- a/pkg/classes/dataTables.go +++ /dev/null | |||
| @@ -1,232 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type DataTables struct { | ||
| 10 | Size int32 | ||
| 11 | SendTable []SendTable | ||
| 12 | ServerClassInfo []ServerClassInfo | ||
| 13 | } | ||
| 14 | |||
| 15 | type SendTable struct { | ||
| 16 | NeedsDecoder bool | ||
| 17 | NetTableName string | ||
| 18 | NumOfProps int16 | ||
| 19 | Props []prop | ||
| 20 | } | ||
| 21 | |||
| 22 | type ServerClassInfo struct { | ||
| 23 | ClassId uint16 | ||
| 24 | ClassName string | ||
| 25 | DataTableName string | ||
| 26 | } | ||
| 27 | |||
| 28 | type prop struct { | ||
| 29 | SendPropType sendPropType | ||
| 30 | SendPropName string | ||
| 31 | SendPropFlags uint32 | ||
| 32 | Priority uint8 | ||
| 33 | ExcludeDtName string | ||
| 34 | LowValue float32 | ||
| 35 | HighValue float32 | ||
| 36 | NumBits int32 | ||
| 37 | NumElements int32 | ||
| 38 | } | ||
| 39 | |||
| 40 | func (dataTables *DataTables) ParseDataTables(reader *bitreader.Reader) { | ||
| 41 | dataTables.Size = int32(reader.TryReadSInt32()) | ||
| 42 | dataTableReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(dataTables.Size)), true) | ||
| 43 | count := 0 | ||
| 44 | for dataTableReader.TryReadBool() { | ||
| 45 | count++ | ||
| 46 | dataTables.SendTable = append(dataTables.SendTable, ParseSendTable(dataTableReader)) | ||
| 47 | } | ||
| 48 | numOfClasses := dataTableReader.TryReadBits(16) | ||
| 49 | for count = 0; count < int(numOfClasses); count++ { | ||
| 50 | dataTables.ServerClassInfo = append(dataTables.ServerClassInfo, ParseServerClassInfo(dataTableReader, count, int(numOfClasses))) | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | func ParseSendTable(reader *bitreader.Reader) SendTable { | ||
| 55 | sendTable := SendTable{ | ||
| 56 | NeedsDecoder: reader.TryReadBool(), | ||
| 57 | NetTableName: reader.TryReadString(), | ||
| 58 | NumOfProps: int16(reader.TryReadBits(10)), | ||
| 59 | } | ||
| 60 | if sendTable.NumOfProps < 0 { | ||
| 61 | return sendTable | ||
| 62 | } | ||
| 63 | for count := 0; count < int(sendTable.NumOfProps); count++ { | ||
| 64 | propType := int8(reader.TryReadBits(5)) | ||
| 65 | if propType >= int8(7) { | ||
| 66 | return sendTable | ||
| 67 | } | ||
| 68 | prop := prop{ | ||
| 69 | SendPropType: sendPropType(propType), | ||
| 70 | SendPropName: reader.TryReadString(), | ||
| 71 | SendPropFlags: uint32(reader.TryReadBits(19)), | ||
| 72 | Priority: reader.TryReadUInt8(), | ||
| 73 | } | ||
| 74 | if propType == int8(ESendPropTypeDataTable) || checkBit(prop.SendPropFlags, 6) { | ||
| 75 | prop.ExcludeDtName = reader.TryReadString() | ||
| 76 | } else { | ||
| 77 | switch propType { | ||
| 78 | case int8(ESendPropTypeString), int8(ESendPropTypeInt), int8(ESendPropTypeFloat), int8(ESendPropTypeVector3), int8(ESendPropTypeVector2): | ||
| 79 | prop.LowValue = reader.TryReadFloat32() | ||
| 80 | prop.HighValue = reader.TryReadFloat32() | ||
| 81 | prop.NumBits = int32(reader.TryReadBits(7)) | ||
| 82 | case int8(ESendPropTypeArray): | ||
| 83 | prop.NumElements = int32(reader.TryReadBits(10)) | ||
| 84 | default: | ||
| 85 | return sendTable | ||
| 86 | } | ||
| 87 | } | ||
| 88 | sendTable.Props = append(sendTable.Props, prop) | ||
| 89 | } | ||
| 90 | return sendTable | ||
| 91 | } | ||
| 92 | |||
| 93 | func ParseServerClassInfo(reader *bitreader.Reader, count int, numOfClasses int) ServerClassInfo { | ||
| 94 | serverClassInfo := ServerClassInfo{ | ||
| 95 | ClassId: reader.TryReadUInt16(), | ||
| 96 | ClassName: reader.TryReadString(), | ||
| 97 | DataTableName: reader.TryReadString(), | ||
| 98 | } | ||
| 99 | return serverClassInfo | ||
| 100 | } | ||
| 101 | |||
| 102 | // func serverClassBits(numOfClasses int) int { | ||
| 103 | // return highestBitIndex(uint(numOfClasses)) + 1 | ||
| 104 | // } | ||
| 105 | |||
| 106 | // func highestBitIndex(i uint) int { | ||
| 107 | // var j int | ||
| 108 | // for j = 31; j >= 0 && (i&(1<<j)) == 0; j-- { | ||
| 109 | // } | ||
| 110 | // return j | ||
| 111 | // } | ||
| 112 | |||
| 113 | func checkBit(val uint32, bit int) bool { | ||
| 114 | return (val & (uint32(1) << bit)) != 0 | ||
| 115 | } | ||
| 116 | |||
| 117 | type sendPropType int | ||
| 118 | |||
| 119 | const ( | ||
| 120 | ESendPropTypeInt sendPropType = iota | ||
| 121 | ESendPropTypeFloat | ||
| 122 | ESendPropTypeVector3 | ||
| 123 | ESendPropTypeVector2 | ||
| 124 | ESendPropTypeString | ||
| 125 | ESendPropTypeArray | ||
| 126 | ESendPropTypeDataTable | ||
| 127 | ) | ||
| 128 | |||
| 129 | const ( | ||
| 130 | ESendPropFlagUnsigned string = "Unsigned" | ||
| 131 | ESendPropFlagCoord string = "Coord" | ||
| 132 | ESendPropFlagNoScale string = "NoScale" | ||
| 133 | ESendPropFlagRoundDown string = "RoundDown" | ||
| 134 | ESendPropFlagRoundUp string = "RoundUp" | ||
| 135 | ESendPropFlagNormal string = "Normal" | ||
| 136 | ESendPropFlagExclude string = "Exclude" | ||
| 137 | ESendPropFlagXyze string = "Xyze" | ||
| 138 | ESendPropFlagInsideArray string = "InsideArray" | ||
| 139 | ESendPropFlagProxyAlwaysYes string = "ProxyAlwaysYes" | ||
| 140 | ESendPropFlagIsVectorElem string = "IsVectorElem" | ||
| 141 | ESendPropFlagCollapsible string = "Collapsible" | ||
| 142 | ESendPropFlagCoordMp string = "CoordMp" | ||
| 143 | ESendPropFlagCoordMpLp string = "CoordMpLp" | ||
| 144 | ESendPropFlagCoordMpInt string = "CoordMpInt" | ||
| 145 | ESendPropFlagCellCoord string = "CellCoord" | ||
| 146 | ESendPropFlagCellCoordLp string = "CellCoordLp" | ||
| 147 | ESendPropFlagCellCoordInt string = "CellCoordInt" | ||
| 148 | ESendPropFlagChangesOften string = "ChangesOften" | ||
| 149 | ) | ||
| 150 | |||
| 151 | func (prop prop) GetFlags() []string { | ||
| 152 | flags := []string{} | ||
| 153 | if checkBit(prop.SendPropFlags, 0) { | ||
| 154 | flags = append(flags, ESendPropFlagUnsigned) | ||
| 155 | } | ||
| 156 | if checkBit(prop.SendPropFlags, 1) { | ||
| 157 | flags = append(flags, ESendPropFlagCoord) | ||
| 158 | } | ||
| 159 | if checkBit(prop.SendPropFlags, 2) { | ||
| 160 | flags = append(flags, ESendPropFlagNoScale) | ||
| 161 | } | ||
| 162 | if checkBit(prop.SendPropFlags, 3) { | ||
| 163 | flags = append(flags, ESendPropFlagRoundDown) | ||
| 164 | } | ||
| 165 | if checkBit(prop.SendPropFlags, 4) { | ||
| 166 | flags = append(flags, ESendPropFlagRoundUp) | ||
| 167 | } | ||
| 168 | if checkBit(prop.SendPropFlags, 5) { | ||
| 169 | flags = append(flags, ESendPropFlagNormal) | ||
| 170 | } | ||
| 171 | if checkBit(prop.SendPropFlags, 6) { | ||
| 172 | flags = append(flags, ESendPropFlagExclude) | ||
| 173 | } | ||
| 174 | if checkBit(prop.SendPropFlags, 7) { | ||
| 175 | flags = append(flags, ESendPropFlagXyze) | ||
| 176 | } | ||
| 177 | if checkBit(prop.SendPropFlags, 8) { | ||
| 178 | flags = append(flags, ESendPropFlagInsideArray) | ||
| 179 | } | ||
| 180 | if checkBit(prop.SendPropFlags, 9) { | ||
| 181 | flags = append(flags, ESendPropFlagProxyAlwaysYes) | ||
| 182 | } | ||
| 183 | if checkBit(prop.SendPropFlags, 10) { | ||
| 184 | flags = append(flags, ESendPropFlagIsVectorElem) | ||
| 185 | } | ||
| 186 | if checkBit(prop.SendPropFlags, 11) { | ||
| 187 | flags = append(flags, ESendPropFlagCollapsible) | ||
| 188 | } | ||
| 189 | if checkBit(prop.SendPropFlags, 12) { | ||
| 190 | flags = append(flags, ESendPropFlagCoordMp) | ||
| 191 | } | ||
| 192 | if checkBit(prop.SendPropFlags, 13) { | ||
| 193 | flags = append(flags, ESendPropFlagCoordMpLp) | ||
| 194 | } | ||
| 195 | if checkBit(prop.SendPropFlags, 14) { | ||
| 196 | flags = append(flags, ESendPropFlagCoordMpInt) | ||
| 197 | } | ||
| 198 | if checkBit(prop.SendPropFlags, 15) { | ||
| 199 | flags = append(flags, ESendPropFlagCellCoord) | ||
| 200 | } | ||
| 201 | if checkBit(prop.SendPropFlags, 16) { | ||
| 202 | flags = append(flags, ESendPropFlagCellCoordLp) | ||
| 203 | } | ||
| 204 | if checkBit(prop.SendPropFlags, 17) { | ||
| 205 | flags = append(flags, ESendPropFlagCellCoordInt) | ||
| 206 | } | ||
| 207 | if checkBit(prop.SendPropFlags, 18) { | ||
| 208 | flags = append(flags, ESendPropFlagChangesOften) | ||
| 209 | } | ||
| 210 | return flags | ||
| 211 | } | ||
| 212 | |||
| 213 | func (sendPropType sendPropType) String() string { | ||
| 214 | switch sendPropType { | ||
| 215 | case ESendPropTypeInt: | ||
| 216 | return "Int" | ||
| 217 | case ESendPropTypeFloat: | ||
| 218 | return "Float" | ||
| 219 | case ESendPropTypeVector3: | ||
| 220 | return "Vector3" | ||
| 221 | case ESendPropTypeVector2: | ||
| 222 | return "Vector2" | ||
| 223 | case ESendPropTypeString: | ||
| 224 | return "String" | ||
| 225 | case ESendPropTypeArray: | ||
| 226 | return "Array" | ||
| 227 | case ESendPropTypeDataTable: | ||
| 228 | return "DataTable" | ||
| 229 | default: | ||
| 230 | return fmt.Sprintf("%d", int(sendPropType)) | ||
| 231 | } | ||
| 232 | } | ||