|
|
@ -17,11 +17,14 @@ type parser struct {
|
|
|
|
|
|
|
|
|
|
|
|
dumpDatagrams bool
|
|
|
|
dumpDatagrams bool
|
|
|
|
dumpPackets bool
|
|
|
|
dumpPackets bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scratch []byte
|
|
|
|
|
|
|
|
pbuf *proto.Buffer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newParser(r io.Reader) *parser {
|
|
|
|
func newParser(r io.Reader) *parser {
|
|
|
|
br := bufio.NewReaderSize(r, 1<<16)
|
|
|
|
br := bufio.NewReaderSize(r, 1<<16)
|
|
|
|
return &parser{source: br}
|
|
|
|
return &parser{source: br, scratch: make([]byte, 1<<17), pbuf: new(proto.Buffer)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p *parser) start() error {
|
|
|
|
func (p *parser) start() error {
|
|
|
@ -57,7 +60,7 @@ func (p *parser) handleDataGram(d *dataGram) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
msg, err := d.Open(&messages)
|
|
|
|
msg, err := d.Open(&messages, p.pbuf)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("datagram open error: %v\n", err)
|
|
|
|
fmt.Printf("datagram open error: %v\n", err)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -75,8 +78,9 @@ func (p *parser) handleDemoPacket(packet *dota.CDemoPacket) error {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
t := entityType(br.ReadUBitVar())
|
|
|
|
t := entityType(br.ReadUBitVar())
|
|
|
|
s := br.ReadVarInt()
|
|
|
|
s := br.ReadVarInt()
|
|
|
|
b := make([]byte, s)
|
|
|
|
b := p.scratch[:s]
|
|
|
|
br.Read(b)
|
|
|
|
br.Read(b)
|
|
|
|
|
|
|
|
p.pbuf.SetBuf(b)
|
|
|
|
switch err := br.Err(); err {
|
|
|
|
switch err := br.Err(); err {
|
|
|
|
case nil:
|
|
|
|
case nil:
|
|
|
|
break
|
|
|
|
break
|
|
|
@ -93,7 +97,7 @@ func (p *parser) handleDemoPacket(packet *dota.CDemoPacket) error {
|
|
|
|
fmt.Printf("\tskipping entity of size %d, type %s: %v\n", len(b), t, err)
|
|
|
|
fmt.Printf("\tskipping entity of size %d, type %s: %v\n", len(b), t, err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := proto.Unmarshal(b, e); err != nil {
|
|
|
|
if err := p.pbuf.Unmarshal(e); err != nil {
|
|
|
|
fmt.Printf("entity unmarshal error: %v\n", err)
|
|
|
|
fmt.Printf("entity unmarshal error: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|