diff options
Diffstat (limited to 'pkg/classes/sendTable.go')
| -rw-r--r-- | pkg/classes/sendTable.go | 174 |
1 files changed, 131 insertions, 43 deletions
diff --git a/pkg/classes/sendTable.go b/pkg/classes/sendTable.go index bc36d75..927d967 100644 --- a/pkg/classes/sendTable.go +++ b/pkg/classes/sendTable.go | |||
| @@ -1,7 +1,10 @@ | |||
| 1 | package classes | 1 | package classes |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | ||
| 5 | |||
| 4 | "github.com/pektezol/bitreader" | 6 | "github.com/pektezol/bitreader" |
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 5 | ) | 8 | ) |
| 6 | 9 | ||
| 7 | type SendTable struct { | 10 | type SendTable struct { |
| @@ -12,10 +15,10 @@ type SendTable struct { | |||
| 12 | } | 15 | } |
| 13 | 16 | ||
| 14 | type prop struct { | 17 | type prop struct { |
| 15 | SendPropType int8 | 18 | SendPropType sendPropType |
| 16 | SendPropName string | 19 | SendPropName string |
| 17 | SendPropFlags int32 | 20 | SendPropFlags uint32 |
| 18 | Priority int8 | 21 | Priority uint8 |
| 19 | ExcludeDtName string | 22 | ExcludeDtName string |
| 20 | LowValue float32 | 23 | LowValue float32 |
| 21 | HighValue float32 | 24 | HighValue float32 |
| @@ -23,84 +26,169 @@ type prop struct { | |||
| 23 | NumElements int32 | 26 | NumElements int32 |
| 24 | } | 27 | } |
| 25 | 28 | ||
| 26 | type sendPropFlag int | 29 | type sendPropType int |
| 27 | 30 | ||
| 28 | const ( | 31 | const ( |
| 29 | Unsigned sendPropFlag = iota | 32 | ESendPropTypeInt sendPropType = iota |
| 30 | Coord | 33 | ESendPropTypeFloat |
| 31 | NoScale | 34 | ESendPropTypeVector3 |
| 32 | RoundDown | 35 | ESendPropTypeVector2 |
| 33 | RoundUp | 36 | ESendPropTypeString |
| 34 | Normal | 37 | ESendPropTypeArray |
| 35 | Exclude | 38 | ESendPropTypeDataTable |
| 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 | ) | 39 | ) |
| 49 | 40 | ||
| 50 | type sendPropType int | ||
| 51 | |||
| 52 | const ( | 41 | const ( |
| 53 | Int sendPropType = iota | 42 | ESendPropFlagUnsigned string = "Unsigned" |
| 54 | Float | 43 | ESendPropFlagCoord string = "Coord" |
| 55 | Vector3 | 44 | ESendPropFlagNoScale string = "NoScale" |
| 56 | Vector2 | 45 | ESendPropFlagRoundDown string = "RoundDown" |
| 57 | String | 46 | ESendPropFlagRoundUp string = "RoundUp" |
| 58 | Array | 47 | ESendPropFlagNormal string = "Normal" |
| 59 | DataTable | 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" | ||
| 60 | ) | 61 | ) |
| 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 | |||
| 62 | func ParseSendTable(reader *bitreader.Reader) SendTable { | 146 | func ParseSendTable(reader *bitreader.Reader) SendTable { |
| 63 | sendTable := SendTable{ | 147 | sendTable := SendTable{ |
| 64 | NeedsDecoder: reader.TryReadBool(), | 148 | NeedsDecoder: reader.TryReadBool(), |
| 65 | NetTableName: reader.TryReadString(), | 149 | NetTableName: reader.TryReadString(), |
| 66 | NumOfProps: int16(reader.TryReadBits(10)), | 150 | NumOfProps: int16(reader.TryReadBits(10)), |
| 67 | // SendPropType: int8(reader.TryReadBits(5)), | ||
| 68 | // SendPropName: reader.TryReadString(), | ||
| 69 | // SendPropFlags: int16(reader.TryReadBits(16)), | ||
| 70 | } | 151 | } |
| 71 | if sendTable.NumOfProps < 0 { | 152 | if sendTable.NumOfProps < 0 { |
| 72 | return sendTable | 153 | return sendTable |
| 73 | } | 154 | } |
| 155 | writer.TempAppendLine("\t\t%s (%d Props):", sendTable.NetTableName, sendTable.NumOfProps) | ||
| 74 | for count := 0; count < int(sendTable.NumOfProps); count++ { | 156 | for count := 0; count < int(sendTable.NumOfProps); count++ { |
| 75 | propType := int8(reader.TryReadBits(5)) | 157 | propType := int8(reader.TryReadBits(5)) |
| 76 | if propType >= int8(7) { | 158 | if propType >= int8(7) { |
| 77 | return sendTable | 159 | return sendTable |
| 78 | } | 160 | } |
| 79 | prop := prop{ | 161 | prop := prop{ |
| 80 | SendPropType: propType, | 162 | SendPropType: sendPropType(propType), |
| 81 | SendPropName: reader.TryReadString(), | 163 | SendPropName: reader.TryReadString(), |
| 82 | SendPropFlags: int32(reader.TryReadBits(19)), | 164 | SendPropFlags: uint32(reader.TryReadBits(19)), |
| 83 | Priority: int8(reader.TryReadBits(8)), | 165 | Priority: reader.TryReadUInt8(), |
| 84 | } | 166 | } |
| 85 | if propType == int8(DataTable) || CheckBit(int64(prop.SendPropFlags), int(Exclude)) { | 167 | writer.TempAppend("\t\t\t%s\t", prop.SendPropType) |
| 168 | if propType == int8(ESendPropTypeDataTable) || checkBit(prop.SendPropFlags, 6) { | ||
| 86 | prop.ExcludeDtName = reader.TryReadString() | 169 | prop.ExcludeDtName = reader.TryReadString() |
| 170 | writer.TempAppend(":\t%s\t", prop.ExcludeDtName) | ||
| 87 | } else { | 171 | } else { |
| 88 | switch propType { | 172 | switch propType { |
| 89 | case int8(String), int8(Int), int8(Float), int8(Vector3), int8(Vector2): | 173 | case int8(ESendPropTypeString), int8(ESendPropTypeInt), int8(ESendPropTypeFloat), int8(ESendPropTypeVector3), int8(ESendPropTypeVector2): |
| 90 | prop.LowValue = reader.TryReadFloat32() | 174 | prop.LowValue = reader.TryReadFloat32() |
| 91 | prop.HighValue = reader.TryReadFloat32() | 175 | prop.HighValue = reader.TryReadFloat32() |
| 92 | prop.NumBits = int32(reader.TryReadBits(7)) | 176 | prop.NumBits = int32(reader.TryReadBits(7)) |
| 93 | case int8(Array): | 177 | writer.TempAppend("Low: %f\tHigh: %f\t%d bits\t", prop.LowValue, prop.HighValue, prop.NumBits) |
| 178 | case int8(ESendPropTypeArray): | ||
| 94 | prop.NumElements = int32(reader.TryReadBits(10)) | 179 | prop.NumElements = int32(reader.TryReadBits(10)) |
| 180 | writer.TempAppend("Elements: %d\t", prop.NumElements) | ||
| 95 | default: | 181 | default: |
| 182 | writer.TempAppend("Unknown Prop Type: %v\t", propType) | ||
| 96 | return sendTable | 183 | return sendTable |
| 97 | } | 184 | } |
| 98 | } | 185 | } |
| 186 | writer.TempAppend("Flags: %v\tPriority: %d\n", prop.GetFlags(), prop.Priority) | ||
| 99 | sendTable.Props = append(sendTable.Props, prop) | 187 | sendTable.Props = append(sendTable.Props, prop) |
| 100 | } | 188 | } |
| 101 | return sendTable | 189 | return sendTable |
| 102 | } | 190 | } |
| 103 | 191 | ||
| 104 | func CheckBit(val int64, bit int) bool { | 192 | func checkBit(val uint32, bit int) bool { |
| 105 | return (val & (int64(1) << bit)) != 0 | 193 | return (val & (uint32(1) << bit)) != 0 |
| 106 | } | 194 | } |