-
Notifications
You must be signed in to change notification settings - Fork 104
/
class.go
104 lines (84 loc) · 2.47 KB
/
class.go
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
package manta
import (
"fmt"
"math"
"regexp"
"strconv"
"strings"
"github.com/dotabuff/manta/dota"
)
var gameBuildRegexp = regexp.MustCompile(`/dota_v(\d+)/`)
type class struct {
classId int32
name string
serializer *serializer
}
func (c *class) getNameForFieldPath(fp *fieldPath) string {
return strings.Join(c.serializer.getNameForFieldPath(fp, 0), ".")
}
func (c *class) getTypeForFieldPath(fp *fieldPath) *fieldType {
return c.serializer.getTypeForFieldPath(fp, 0)
}
func (c *class) getDecoderForFieldPath(fp *fieldPath) fieldDecoder {
return c.serializer.getDecoderForFieldPath(fp, 0)
}
func (c *class) getFieldPathForName(fp *fieldPath, name string) bool {
return c.serializer.getFieldPathForName(fp, name)
}
func (c *class) getFieldPaths(fp *fieldPath, state *fieldState) []*fieldPath {
return c.serializer.getFieldPaths(fp, state)
}
// Internal callback for OnCSVCMsg_ServerInfo.
func (p *Parser) onCSVCMsg_ServerInfo(m *dota.CSVCMsg_ServerInfo) error {
// This may be needed to parse PacketEntities.
p.classIdSize = uint32(math.Log(float64(m.GetMaxClasses()))/math.Log(2)) + 1
// Extract the build from the game dir.
matches := gameBuildRegexp.FindStringSubmatch(m.GetGameDir())
if len(matches) < 2 {
return fmt.Errorf("unable to determine game build from '%s'", m.GetGameDir())
}
build, err := strconv.ParseUint(matches[1], 10, 32)
if err != nil {
return err
}
p.GameBuild = uint32(build)
return nil
}
// Internal callback for OnCDemoClassInfo.
func (p *Parser) onCDemoClassInfo(m *dota.CDemoClassInfo) error {
for _, c := range m.GetClasses() {
classId := c.GetClassId()
networkName := c.GetNetworkName()
class := &class{
classId: classId,
name: networkName,
serializer: p.serializers[networkName],
}
p.classesById[class.classId] = class
p.classesByName[class.name] = class
}
p.classInfo = true
p.updateInstanceBaseline()
return nil
}
func (p *Parser) updateInstanceBaseline() {
// We can't update the instancebaseline until we have class info.
if !p.classInfo {
return
}
stringTable, ok := p.stringTables.GetTableByName("instancebaseline")
if !ok {
if v(1) {
_debugf("skipping updateInstanceBaseline: no instancebaseline string table")
}
return
}
// Iterate through instancebaseline table items
for _, item := range stringTable.Items {
classId, err := atoi32(item.Key)
if err != nil {
_panicf("invalid instancebaseline key '%s': %s", item.Key, err)
}
p.classBaselines[classId] = item.Value
}
}