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
716 stars 95 forks source link

Error wrong bombsite new map grind #280

Closed Julien2313 closed 3 years ago

Julien2313 commented 3 years ago

Describe the bug When trying to parse this game on the new map Grind, I got an error panic: bomb not planted on bombsite A or B

To Reproduce

Links to download demos : http://replay272.valve.net/730/003479822691228189340_1757036846.dem.bz2 (available 1 month since now) http://replay187.valve.net/730/003480011012659216461_0088537034.dem.bz2

Code:

package main

import (
    "bufio"
    "bytes"
    "compress/bzip2"
    "compress/gzip"
    "fmt"
    "io"
    "io/ioutil"
    "os"
    "path/filepath"

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

func main() {
    demoFile, err := os.Open("path/to/demo")
    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()

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

    err = p.ParseToEnd()
    if err != nil {
        panic(err)
    }
}
de_grind
panic: bomb not planted on bombsite A or B

goroutine 1 [running]:
main.main()
        /home/julien/git/test-demoinfo/main.go:62 +0x83d
exit status 2

Expected behavior Not getting an error

Additional context The bomb in the round has never been planted anywhere in the round (occuring during the 5th for the first time) :( the only time it has been moved is when a player has been killed. nobody picked up the bomb again.

In previous round, someone (ok, it was me) died with the bomb, but the parser doesn't panic. Maybe the demo is a little bite corrupted ? Idk :x But it appends 11 times during the parsing, so it's a bug corruption ? Ha ha. I guess this is "just" bad event on this map ? I can't tell you if this is happening on others demos on this map or not as I only have 1 demo on this one :(

Their is no such errors on the other new map Mocha

Thank you for your help :)

markus-wa commented 3 years ago

Thanks for reporting this @Julien2313 !

Seems like this happens in round 4 when Player Xelf begins to plant the bomb.

For some reason bombsite B is not correctly set up: image

It's ID is 429, but the CBaseTrigger / bounding box corresponding to that ID has completely wrong boundaries.

Expected coordinates of the centre are X=-2770, Y=904, Z=-56 (which is around where Xelf was when he planted the bomb) but actual bounds according to CBaseTrigger are these image

No worries if that doesn't make any sense what I'm saying - it's mostly for myself when I look at this again in a few days. But basically: I've got no clue why this would happen ...

If you could get me another demo from that map that would be super useful to investigate further.

Julien2313 commented 3 years ago

No no, I digged in your code I understand it! Ha ha Is their a way to avoid it to stop parsing the demo ?

I'm waiting you to do a game on it ! Ha ha Yeah, I'll search another demo somewhere to check this

markus-wa commented 3 years ago

I'm afraid there's no way to prevent the crash as of now.

If it's critical for you I recommend temporarily forking the project and removing that panic - and hopefully I'll be able to get this sorted out properly by the end of next week and you can switch back to the official version.

Julien2313 commented 3 years ago

Yeah no worries, it's really not critical ;)

Julien2313 commented 3 years ago

Here is a new demo, same issue : http://replay187.valve.net/730/003480011012659216461_0088537034.dem.bz2

xiexiangchao commented 3 years ago

this demo can reproduce this problem http://replay234.wmsj.cn/730/003480539579251949579_0470276058.dem.bz2

markus-wa commented 3 years ago

thanks both for the additional samples.

tomorrow it's my first open-source Friday (:tada:), so should hopefully get around to it

markus-wa commented 3 years ago

I've removed the panic and replaced it with a ParserWarn event. So after go get -u github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs@v2.7.1 you should no longer see the panic.

However, this means BombEvent.Site may now be unknown/ undefined (meaning it's neither BombsiteA nor BombsiteB) - I'm not sure if this will be easily fixable

If you need bombsite information, I think a workaround for now is that you do the following in your code:

parser.RegisterEventHandler(func(planted events.BombPlanted) {
    if planted.Site != events.BombsiteA && planted.Site != events.BombsiteB && parser.Header().MapName == "de_grind" {
        planted.Site = events.BombsiteB
    }

    // handle event as usual
})

Hopefully I will be able to fix this properly at some point.

I have opened #284 to track the remaining issue of the missing bomb site information.

Julien2313 commented 3 years ago

Thank you for your fix ! :)