markus-wa / demoinfocs-golang

A Counter-Strike 2 & CS:GO demo parser for Go (demoinfo)
https://pkg.go.dev/github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs?tab=doc
MIT License
714 stars 95 forks source link

de_grind: BombEvent.Site not set for bombsite B #284

Closed markus-wa closed 1 month ago

markus-wa commented 3 years ago

Describe the bug Due to #280, BombEvent.Site may not be set for some bomb sites. Currently the only known case is Bombsite B on de_grind.

To Reproduce two sample demos are here: https://drive.google.com/drive/folders/1KptOTNbFlfQVdaz-i78Z0J7DnXhBs7GE?usp=sharing

Code:

package main

import (
    "fmt"
    "os"

    "bufio"
    "bytes"
    "compress/bzip2"
    "compress/gzip"
    "io"
    "io/ioutil"
    "path/filepath"

    demoinfocs "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
    "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
)

func main() {
    demoFile, err := os.Open("/home/mark/Downloads/003480011012659216461_0088537034.dem.bz2")
    if err != nil {
        panic(err)
    }
    defer demoFile.Close()

    var demoUnzippedReader io.Reader
    switch filepath.Ext(demoFile.Name()) {
    case ".bz2":
        demoUnzippedReader = bzip2.NewReader(bufio.NewReader(demoFile))
    case ".gz":
        demoZippedReader, err := gzip.NewReader(demoFile)
        if err != nil {
            panic(err)
        }

        t, err := ioutil.ReadAll(demoZippedReader)
        if err != nil {
            panic(err)
        }
        demoUnzippedReader = bytes.NewReader(t)
    case ".dem":
        demoUnzippedReader = bufio.NewReader(demoFile)
    default:
        panic(err)
    }

    demoUnzippedBytes, err := ioutil.ReadAll(demoUnzippedReader)
    if err != nil {
        panic(err)
    }

    r := bytes.NewReader(demoUnzippedBytes)
    p := demoinfocs.NewParser(r)
    defer p.Close()

    p.RegisterEventHandler(func(planted events.BombPlanted) {
        if planted.Site != events.BombsiteA && planted.Site != events.BombsiteB {
            fmt.Println("oh no! unknown bomb site")
        }

        // handle event as usual
    })

    demoHerader, err := p.ParseHeader()
    if err != nil {
        panic(err)
    }
    fmt.Println(demoHerader.MapName)

    err = p.ParseToEnd()
    if err != nil {
        panic(err)
    }
}

Expected behavior It never prints oh no! unknown bomb site for any bomb event

Actual behaviour For de_grind games, it prints oh no! unknown bomb site

Workaround The following code works around the issue as it seems like the only case of this happening is bomb site B on de_grind.

if planted.Site != events.BombsiteA && planted.Site != events.BombsiteB && p.Header().MapName == "de_grind" {
    planted.Site = events.BombsiteB
}

Library version v2.7.1

Additional context

markus-wa commented 1 month ago

Closing as this was for CS:GO