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

Demo Parser Terminates Early When It Doesn't Find Bombsite In Version 2.11.1 #314

Closed David-Durst closed 3 years ago

David-Durst commented 3 years ago

Describe the bug Retakes demos seem to lack some information on bomb plants. In version 2.5.0, the demo parser was able to complete processing demos, even if the bomb plants information was invalid. In version 2.11.1, the demo parser terminates early with the error message "bombsite with index 0 was not found" from https://github.com/markus-wa/demoinfocs-golang/blob/b2c45b12fb7816f1762374691e12ec1e0056afd1/pkg/demoinfocs/game_events.go#L657. Can the parser continue parsing and print non-fatal errors if the bomb plant information is invalid?

To Reproduce Download link to an affected demo: https://drive.google.com/file/d/1_Rae00HJMhPmD-7Wpy_ufRKO3074ERzv/view?usp=sharing

This is a retakes game I played on a listenserver with friends connected over the internet.

Code:

package main

import (
    "fmt"
    "os"

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

func main() {
    f, err := os.Open("../demo_parser/demos/merrick_kingston_matt_gabe_rory_durst_9_20_21_wallhacks_2.dem")
    if err != nil {
        panic(err)
    }
    defer f.Close()

    p := dem.NewParser(f)
    defer p.Close()

    // Register handler on kill events
    p.RegisterEventHandler(func(e events.Kill) {
        var hs string
        if e.IsHeadshot {
            hs = " (HS)"
        }
        var wallBang string
        if e.PenetratedObjects > 0 {
            wallBang = " (WB)"
        }
        fmt.Printf("%s <%v%s%s> %s\n", e.Killer, e.Weapon, hs, wallBang, e.Victim)
    })

    // Parse to end
    err = p.ParseToEnd()
    if err != nil {
        fmt.Printf("Error in parsing. T score %d, CT score %d, progress: %f, error:\n %s\n",
            p.GameState().TeamTerrorists().Score(), p.GameState().TeamCounterTerrorists().Score(), p.Progress(), err.Error())

        panic(err)
    }
}

Expected behavior The parser processes the entire game.

Observed behavior The parser terminates early with the following message

Error in parsing. T score 5, CT score 2, progress: 0.563881, error:
 bombsite with index 0 not found
panic: bombsite with index 0 not found

Library version e.g. v2.11.1

Additional context I'm using Ubuntu 21.04.

markus-wa commented 3 years ago

Hi @David-Durst - thanks for the report

Could you have a look at #315 to see if this change works for you? you will need to use the new flag IgnoreErrBombsiteIndexNotFound, more details on the PR

Cheers

David-Durst commented 3 years ago

Works for me. Confirmed with https://github.com/David-Durst/csknow/blob/1c0f0942de698e69794e325decdad46918076d23/test_parser/main.go#L18-L19.

Thanks!