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