discard skipped entities

master
Jordan Orelli 8 years ago
parent 944cad072d
commit f9926cbbda

@ -49,6 +49,11 @@ func (r *Reader) ReadBits(bits uint) (n uint64) {
return return
} }
// discards up to bits bits. returns a bool indicating wheter any errors occured.
func (r *Reader) DiscardBits(n int) {
r.ReadBits(uint(n))
}
// ReadByte reads a single byte, regardless of alignment. // ReadByte reads a single byte, regardless of alignment.
func (r *Reader) ReadByte() (byte, error) { func (r *Reader) ReadByte() (byte, error) {
if r.bits == 0 { if r.bits == 0 {
@ -73,6 +78,17 @@ func (r *Reader) Read(buf []byte) (int, error) {
return len(buf), nil return len(buf), nil
} }
// discards N byte of data on the reader or until EOF
func (r *Reader) DiscardBytes(n int) {
for i := 0; i < n; i++ {
_, err := r.ReadByte()
if err != nil {
r.err = err
return
}
}
}
// ReadUbitVar reads a prefixed uint value. A prefix is 2 bits wide, followed // ReadUbitVar reads a prefixed uint value. A prefix is 2 bits wide, followed
// by the 4 least-significant bits, then a variable number of most-significant // by the 4 least-significant bits, then a variable number of most-significant
// bits based on the prefix. // bits based on the prefix.

@ -9,7 +9,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"reflect" // "reflect"
"runtime/pprof" "runtime/pprof"
"strings" "strings"
) )
@ -123,12 +123,15 @@ func main() {
c := make(chan maybe, 32) c := make(chan maybe, 32)
p := newParser(r) p := newParser(r)
delete(p.ewl, EBaseGameEvents_GE_SosStartSoundEvent)
delete(p.ewl, EDotaUserMessages_DOTA_UM_SpectatorPlayerUnitOrders)
delete(p.ewl, EDotaUserMessages_DOTA_UM_SpectatorPlayerClick)
go p.run(c) go p.run(c)
for m := range c { for m := range c {
if m.error != nil { if m.error != nil {
fmt.Fprintln(os.Stderr, m.error) fmt.Fprintln(os.Stderr, m.error)
} else { } else {
fmt.Println(reflect.TypeOf(m.Message)) // fmt.Println(reflect.TypeOf(m.Message))
} }
} }
if p.err != nil { if p.err != nil {

@ -72,8 +72,13 @@ func (p *parser) emitChildren(pkt *dota.CDemoPacket, c chan maybe) {
for { for {
t := entityType(br.ReadUBitVar()) t := entityType(br.ReadUBitVar())
s := br.ReadVarInt() s := br.ReadVarInt()
b := p.scratch[:s]
br.Read(b) if p.ewl[t] {
br.Read(p.scratch[:s])
} else {
br.DiscardBytes(int(s))
continue
}
switch err := br.Err(); err { switch err := br.Err(); err {
case nil: case nil:
@ -85,14 +90,10 @@ func (p *parser) emitChildren(pkt *dota.CDemoPacket, c chan maybe) {
return return
} }
if !p.ewl[t] { p.pbuf.SetBuf(p.scratch[:s])
continue
}
p.pbuf.SetBuf(b)
e, err := messages.BuildEntity(t) e, err := messages.BuildEntity(t)
if err != nil { if err != nil {
c <- maybe{error: wrap(err, "skipping entity of size %d, type %s", len(b), t)} c <- maybe{error: wrap(err, "skipping entity of size %d, type %s", s, t)}
continue continue
} }
if err := p.pbuf.Unmarshal(e); err != nil { if err := p.pbuf.Unmarshal(e); err != nil {

Loading…
Cancel
Save