Ejemplo n.º 1
0
func (p *Parser) AnalyzePacket(callback func(*ParserBaseItem), fromEvent dota.EDemoCommands, tick int, data []byte) {
	reader := utils.NewBytesReader(data)
	for reader.CanRead() {
		iType := int(reader.ReadVarInt32())
		length := int(reader.ReadVarInt32())
		obj, err := p.AsBaseEventNETSVC(iType)
		if err != nil {
			spew.Println(err)
			reader.Skip(length)
		} else {
			item := &ParserItem{
				Sequence: p.Sequence,
				From:     fromEvent,
				Object:   obj,
				Tick:     tick,
				Data:     reader.Read(length),
			}
			p.Sequence++
			switch obj.(type) {
			case *dota.CSVCMsg_UserMessage:
				message := &dota.CSVCMsg_UserMessage{}
				ProtoUnmarshal(item.Data, message)
				um, err := p.AsBaseEventBUMDUM(int(message.GetMsgType()))
				if err == nil {
					item.Object = um
					item.Data = message.GetMsgData()
					callback(parseOne(item))
				}
			default:
				callback(parseOne(item))
			}
		}
	}
}
Ejemplo n.º 2
0
func NewParser(data []byte) *Parser {
	if len(data) < headerLength {
		panic("File too small.")
	}

	magic := ReadStringZ(data, 0)
	if magic != headerMagic {
		panic("demofilestamp doesn't match, was: " + spew.Sdump(magic))
	}

	totalLength := len(data) - headerLength
	if totalLength < 1 {
		panic("couldn't open file")
	}

	buffer := data[headerLength:(headerLength + totalLength)]
	return &Parser{reader: utils.NewBytesReader(buffer)}
}