A Counter-Strike 2 Demo Parser for Go (demoinfo)
A Counter-Strike 2 Demo Parser for Go (demoinfo)
A blazing fast, feature complete and production ready Go library for parsing and analysing of Counter-Strike 2 and Counter-Strike: Global Offensive (CS:GO) demos (aka replays).
You can use Discord or GitHub Discussions to ask questions and discuss ideas about this project.
For business inquiries please use the contact information found on the GitHub profile.
go get -u github.com/markus-wa/demoinfocs-golang/v5/pkg/demoinfocsSee broadcast example for live CSTV+ parsing
go get -u github.com/markus-wa/demoinfocs-golang/v3/pkg/demoinfocsThis library requires at least go 1.27 to run.
You can download the latest version of Go here.
Download and install the latest version of Go from golang.org or via your favourite package manager
Create a new Go Modules project
mkdir my-project
cd my-project
go mod init my-project
go get -u github.com/markus-wa/demoinfocs-golang/v5/pkg/demoinfocsCreate a main.go file with the example below
Run go run main.go
This is a simple example on how to handle game events using this library.
It prints all kills in a given demo (killer, weapon, victim, was it a wallbang/headshot?) by registering a handler for events.Kill.
Check out the godoc of the events package for some information about the other available events and their purpose.
…Running the code above will print something like this:
xms crisby
tiziaN Ex6TenZ
tiziaN mistou
tiziaN ALEX
xms tiziaN
...
keev to1nou
...Check out the examples folder for more examples, like how to generate heatmaps like this one:
The full API documentation is available here on pkg.go.dev.
Two of the top priorities of this parser are performance and concurrency.
Here are some benchmark results from a system with an Intel i7 6700k CPU and a SSD disk running Windows 10 and a demo with 85'000 frames.
| Benchmark | Description | Average Duration | Speed |
|---|---|---|---|
BenchmarkConcurrent |
Read and parse 8 demos concurrently | 2.06 s (per 8 demos) | ~ 1 h 25 min of gameplay per second |
BenchmarkDemoInfoCs |
Read demo from drive and parse | 0.89 s | ~ 25 min of gameplay per second |
BenchmarkInMemory |
Read demo from memory and parse | 0.88 s | ~ 25 min of gameplay per second |
…We use SemVer for versioning. For the versions available, see the tags on this repository. There is one caveat however: Beta features - which are marked as such via comments and in release notes - may change in minor releases.
If your project is using this library feel free to submit a PR or send a message via Discord to be included in the list.
You can use the build tag debugdemoinfocs to print out debugging information - such as game events or unhandled demo-messages - during the parsing process.
e.g.
go run -tags debugdemoinfocs examples/print-events/print_events.go -demo example.demSide-note: The tag isn't called debug to avoid naming conflicts with other libs (and underscores in tags don't work, apparently).
To change the default debugging behavior, Go's ldflags parameter can be used. Example for additionally printing out all server-classes with their properties: -ldflags="-X 'github.com/markus-wa/demoinfocs-golang/v5/pkg/demoinfocs.debugServerClasses=YES'".
e.g.
go run -tags debugdemoinfocs -ldflags="-X 'github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs.debugServerClasses=YES'" examples/print-events/print_events.go -demo example.demCheck out debug_on.go for any other settings that can be changed.
For any new features, Test Driven Development should be practiced where possible. However, due to some design flaws in some parts of the code it's currently not always practical to do so.
Running unit tests:
scripts/unit-tests.sh
# or (identical)
go test -short ./...For the full regression suite you will need to download the test demo-set.
Prerequisites:
7z must be in your PATH environment variable (p7zip or p7zip-full package on most Linux distros)Downloading demos + running regression tests:
scripts/regression-tests.shdefault.golden FileThe file test/default.golden file contains a serialized output of all expected game events in test/cs-demos/s2/s2.dem.
If there is a change to ga
No open issues yet, or sync has not completed.