コード例 #1
0
ファイル: parser.go プロジェクト: NicoAriel/yasha
func (p *Parser) onCDemoClassInfo(cdci *dota.CDemoClassInfo) {
	for _, class := range cdci.GetClasses() {
		id, name := int(class.GetClassId()), class.GetTableName()
		p.ClassInfosIdMapping[name] = id
		p.ClassInfosNameMapping[id] = name

		props := p.Sth.LoadSendTable(name)
		multiples := map[string]int{}
		for _, prop := range props {
			key := prop.DtName + "." + prop.VarName
			multiples[key] += 1
		}
		p.Multiples[id] = multiples
		p.Mapping[id] = props

		if p.OnTablename != nil {
			p.OnTablename(name)
		}
	}

	p.Stsh.ClassInfosNameMapping = p.ClassInfosNameMapping
	p.Stsh.Mapping = p.Mapping
	p.Stsh.Multiples = p.Multiples
}
コード例 #2
0
func NewParser(items parser.ParserBaseItems) {
	p := Parser{
		entities: make([]*PacketEntity, 0, 2048),
	}

	var serverInfo *dota.CSVCMsg_ServerInfo
	packets := parser.ParserBaseItems{}
	for _, item := range items {
		switch value := item.Object.(type) {
		case *dota.CSVCMsg_ServerInfo:
			serverInfo = value
		case *dota.CSVCMsg_PacketEntities:
			if item.From == dota.EDemoCommands_DEM_Packet {
				packets = append(packets, item)
			}
		}
	}
	sort.Sort(packets)
	p.packets = packets

	p.classIdNumBits = int(math.Log(float64(serverInfo.GetMaxClasses()))/math.Log(2)) + 1

	var classInfos *dota.CDemoClassInfo
	var instanceBaseline *dota.CDemoStringTablesTableT
	sendTables := map[string]*dota.CSVCMsg_SendTable{}

	for _, item := range items {
		switch value := item.Object.(type) {
		case *dota.CDemoClassInfo:
			if classInfos == nil {
				classInfos = value
			}
		case *dota.CSVCMsg_SendTable:
			sendTables[value.GetNetTableName()] = value
		case *dota.CDemoStringTables:
			for _, table := range value.GetTables() {
				if table.GetTableName() == "instancebaseline" {
					instanceBaseline = table
				}
			}
		}
	}

	for _, info := range classInfos.GetClasses() {
		id, name := int(info.GetClassId()), info.GetTableName()
		p.classInfosNameMapping[id] = name
		p.classInfosIdMapping[name] = id
		props := p.sendTablesHelper.LoadSendTable(name)
		p.mapping[id] = props

		m := map[string]int{}
		for _, prop := range props {
			m[prop.DtName+"."+prop.VarName] += 1
		}
		p.multiples[id] = m
	}

	for _, item := range instanceBaseline.GetItems() {
		classId, err := strconv.Atoi(item.GetStr())
		if err != nil {
			panic(err)
		}
		br := utils.NewBitReader(item.GetData())
		indices := br.ReadPropertiesIndex()
		p.baseline[classId] = br.ReadPropertiesValues(
			p.mapping[classId],
			p.multiples[classId],
			indices,
		)
	}
}