Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
markus-wa opened this issue May 14, 2021 · 0 comments
Open

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

markus-wa opened this issue May 14, 2021 · 0 comments

Comments

@markus-wa
Copy link
Owner

markus-wa commented May 14, 2021

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 markus-wa changed the title BombEvent.Site not set for bombsite B on de_grind de_grind: BombEvent.Site not set for bombsite B May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant