diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-21 19:26:40 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-21 19:26:40 +0300 |
| commit | 44eefefe67a4a5f514faa4594370346fd1b54996 (patch) | |
| tree | a8853a8ecd49ddbb87c6cc19904ec6bb5419ee83 /pkg/classes/sendTable.go | |
| parent | add strings builder, customize ALL outputs (#6) (diff) | |
| download | sdp.go-44eefefe67a4a5f514faa4594370346fd1b54996.tar.gz sdp.go-44eefefe67a4a5f514faa4594370346fd1b54996.tar.bz2 sdp.go-44eefefe67a4a5f514faa4594370346fd1b54996.zip | |
organize packets and classes (#9)v1.1.1
Diffstat (limited to 'pkg/classes/sendTable.go')
| -rw-r--r-- | pkg/classes/sendTable.go | 194 |
1 files changed, 0 insertions, 194 deletions
diff --git a/pkg/classes/sendTable.go b/pkg/classes/sendTable.go deleted file mode 100644 index 927d967..0000000 --- a/pkg/classes/sendTable.go +++ /dev/null | |||
| @@ -1,194 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type SendTable struct { | ||
| 11 | NeedsDecoder bool | ||
| 12 | NetTableName string | ||
| 13 | NumOfProps int16 | ||
| 14 | Props []prop | ||
| 15 | } | ||
| 16 | |||
| 17 | type prop struct { | ||
| 18 | SendPropType sendPropType | ||
| 19 | SendPropName string | ||
| 20 | SendPropFlags uint32 | ||
| 21 | Priority uint8 | ||
| 22 | ExcludeDtName string | ||
| 23 | LowValue float32 | ||
| 24 | HighValue float32 | ||
| 25 | NumBits int32 | ||
| 26 | NumElements int32 | ||
| 27 | } | ||
| 28 | |||
| 29 | type sendPropType int | ||
| 30 | |||
| 31 | const ( | ||
| 32 | ESendPropTypeInt sendPropType = iota | ||
| 33 | ESendPropTypeFloat | ||
| 34 | ESendPropTypeVector3 | ||
| 35 | ESendPropTypeVector2 | ||
| 36 | ESendPropTypeString | ||
| 37 | ESendPropTypeArray | ||
| 38 | ESendPropTypeDataTable | ||
| 39 | ) | ||
| 40 | |||
| 41 | const ( | ||
| 42 | ESendPropFlagUnsigned string = "Unsigned" | ||
| 43 | ESendPropFlagCoord string = "Coord" | ||
| 44 | ESendPropFlagNoScale string = "NoScale" | ||
| 45 | ESendPropFlagRoundDown string = "RoundDown" | ||
| 46 | ESendPropFlagRoundUp string = "RoundUp" | ||
| 47 | ESendPropFlagNormal string = "Normal" | ||
| 48 | ESendPropFlagExclude string = "Exclude" | ||
| 49 | ESendPropFlagXyze string = "Xyze" | ||
| 50 | ESendPropFlagInsideArray string = "InsideArray" | ||
| 51 | ESendPropFlagProxyAlwaysYes string = "ProxyAlwaysYes" | ||
| 52 | ESendPropFlagIsVectorElem string = "IsVectorElem" | ||
| 53 | ESendPropFlagCollapsible string = "Collapsible" | ||
| 54 | ESendPropFlagCoordMp string = "CoordMp" | ||
| 55 | ESendPropFlagCoordMpLp string = "CoordMpLp" | ||
| 56 | ESendPropFlagCoordMpInt string = "CoordMpInt" | ||
| 57 | ESendPropFlagCellCoord string = "CellCoord" | ||
| 58 | ESendPropFlagCellCoordLp string = "CellCoordLp" | ||
| 59 | ESendPropFlagCellCoordInt string = "CellCoordInt" | ||
| 60 | ESendPropFlagChangesOften string = "ChangesOften" | ||
| 61 | ) | ||
| 62 | |||
| 63 | func (prop prop) GetFlags() []string { | ||
| 64 | flags := []string{} | ||
| 65 | if checkBit(prop.SendPropFlags, 0) { | ||
| 66 | flags = append(flags, ESendPropFlagUnsigned) | ||
| 67 | } | ||
| 68 | if checkBit(prop.SendPropFlags, 1) { | ||
| 69 | flags = append(flags, ESendPropFlagCoord) | ||
| 70 | } | ||
| 71 | if checkBit(prop.SendPropFlags, 2) { | ||
| 72 | flags = append(flags, ESendPropFlagNoScale) | ||
| 73 | } | ||
| 74 | if checkBit(prop.SendPropFlags, 3) { | ||
| 75 | flags = append(flags, ESendPropFlagRoundDown) | ||
| 76 | } | ||
| 77 | if checkBit(prop.SendPropFlags, 4) { | ||
| 78 | flags = append(flags, ESendPropFlagRoundUp) | ||
| 79 | } | ||
| 80 | if checkBit(prop.SendPropFlags, 5) { | ||
| 81 | flags = append(flags, ESendPropFlagNormal) | ||
| 82 | } | ||
| 83 | if checkBit(prop.SendPropFlags, 6) { | ||
| 84 | flags = append(flags, ESendPropFlagExclude) | ||
| 85 | } | ||
| 86 | if checkBit(prop.SendPropFlags, 7) { | ||
| 87 | flags = append(flags, ESendPropFlagXyze) | ||
| 88 | } | ||
| 89 | if checkBit(prop.SendPropFlags, 8) { | ||
| 90 | flags = append(flags, ESendPropFlagInsideArray) | ||
| 91 | } | ||
| 92 | if checkBit(prop.SendPropFlags, 9) { | ||
| 93 | flags = append(flags, ESendPropFlagProxyAlwaysYes) | ||
| 94 | } | ||
| 95 | if checkBit(prop.SendPropFlags, 10) { | ||
| 96 | flags = append(flags, ESendPropFlagIsVectorElem) | ||
| 97 | } | ||
| 98 | if checkBit(prop.SendPropFlags, 11) { | ||
| 99 | flags = append(flags, ESendPropFlagCollapsible) | ||
| 100 | } | ||
| 101 | if checkBit(prop.SendPropFlags, 12) { | ||
| 102 | flags = append(flags, ESendPropFlagCoordMp) | ||
| 103 | } | ||
| 104 | if checkBit(prop.SendPropFlags, 13) { | ||
| 105 | flags = append(flags, ESendPropFlagCoordMpLp) | ||
| 106 | } | ||
| 107 | if checkBit(prop.SendPropFlags, 14) { | ||
| 108 | flags = append(flags, ESendPropFlagCoordMpInt) | ||
| 109 | } | ||
| 110 | if checkBit(prop.SendPropFlags, 15) { | ||
| 111 | flags = append(flags, ESendPropFlagCellCoord) | ||
| 112 | } | ||
| 113 | if checkBit(prop.SendPropFlags, 16) { | ||
| 114 | flags = append(flags, ESendPropFlagCellCoordLp) | ||
| 115 | } | ||
| 116 | if checkBit(prop.SendPropFlags, 17) { | ||
| 117 | flags = append(flags, ESendPropFlagCellCoordInt) | ||
| 118 | } | ||
| 119 | if checkBit(prop.SendPropFlags, 18) { | ||
| 120 | flags = append(flags, ESendPropFlagChangesOften) | ||
| 121 | } | ||
| 122 | return flags | ||
| 123 | } | ||
| 124 | |||
| 125 | func (sendPropType sendPropType) String() string { | ||
| 126 | switch sendPropType { | ||
| 127 | case ESendPropTypeInt: | ||
| 128 | return "Int" | ||
| 129 | case ESendPropTypeFloat: | ||
| 130 | return "Float" | ||
| 131 | case ESendPropTypeVector3: | ||
| 132 | return "Vector3" | ||
| 133 | case ESendPropTypeVector2: | ||
| 134 | return "Vector2" | ||
| 135 | case ESendPropTypeString: | ||
| 136 | return "String" | ||
| 137 | case ESendPropTypeArray: | ||
| 138 | return "Array" | ||
| 139 | case ESendPropTypeDataTable: | ||
| 140 | return "DataTable" | ||
| 141 | default: | ||
| 142 | return fmt.Sprintf("%d", int(sendPropType)) | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | func ParseSendTable(reader *bitreader.Reader) SendTable { | ||
| 147 | sendTable := SendTable{ | ||
| 148 | NeedsDecoder: reader.TryReadBool(), | ||
| 149 | NetTableName: reader.TryReadString(), | ||
| 150 | NumOfProps: int16(reader.TryReadBits(10)), | ||
| 151 | } | ||
| 152 | if sendTable.NumOfProps < 0 { | ||
| 153 | return sendTable | ||
| 154 | } | ||
| 155 | writer.TempAppendLine("\t\t%s (%d Props):", sendTable.NetTableName, sendTable.NumOfProps) | ||
| 156 | for count := 0; count < int(sendTable.NumOfProps); count++ { | ||
| 157 | propType := int8(reader.TryReadBits(5)) | ||
| 158 | if propType >= int8(7) { | ||
| 159 | return sendTable | ||
| 160 | } | ||
| 161 | prop := prop{ | ||
| 162 | SendPropType: sendPropType(propType), | ||
| 163 | SendPropName: reader.TryReadString(), | ||
| 164 | SendPropFlags: uint32(reader.TryReadBits(19)), | ||
| 165 | Priority: reader.TryReadUInt8(), | ||
| 166 | } | ||
| 167 | writer.TempAppend("\t\t\t%s\t", prop.SendPropType) | ||
| 168 | if propType == int8(ESendPropTypeDataTable) || checkBit(prop.SendPropFlags, 6) { | ||
| 169 | prop.ExcludeDtName = reader.TryReadString() | ||
| 170 | writer.TempAppend(":\t%s\t", prop.ExcludeDtName) | ||
| 171 | } else { | ||
| 172 | switch propType { | ||
| 173 | case int8(ESendPropTypeString), int8(ESendPropTypeInt), int8(ESendPropTypeFloat), int8(ESendPropTypeVector3), int8(ESendPropTypeVector2): | ||
| 174 | prop.LowValue = reader.TryReadFloat32() | ||
| 175 | prop.HighValue = reader.TryReadFloat32() | ||
| 176 | prop.NumBits = int32(reader.TryReadBits(7)) | ||
| 177 | writer.TempAppend("Low: %f\tHigh: %f\t%d bits\t", prop.LowValue, prop.HighValue, prop.NumBits) | ||
| 178 | case int8(ESendPropTypeArray): | ||
| 179 | prop.NumElements = int32(reader.TryReadBits(10)) | ||
| 180 | writer.TempAppend("Elements: %d\t", prop.NumElements) | ||
| 181 | default: | ||
| 182 | writer.TempAppend("Unknown Prop Type: %v\t", propType) | ||
| 183 | return sendTable | ||
| 184 | } | ||
| 185 | } | ||
| 186 | writer.TempAppend("Flags: %v\tPriority: %d\n", prop.GetFlags(), prop.Priority) | ||
| 187 | sendTable.Props = append(sendTable.Props, prop) | ||
| 188 | } | ||
| 189 | return sendTable | ||
| 190 | } | ||
| 191 | |||
| 192 | func checkBit(val uint32, bit int) bool { | ||
| 193 | return (val & (uint32(1) << bit)) != 0 | ||
| 194 | } | ||