GitHub - markus-wa/demoinfocs-golang: High performance CS:GO demo parser for Go
source link: https://github.com/markus-wa/demoinfocs-golang
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
demoinfocs-golang - A CS:GO Demo Parser
Is a Go library for super fast parsing and analysing of Counter Strike: Global Offensive (CS:GO) demos (aka replays). It is based on Valve's demoinfogo and SatsHelix's demoinfo.
Discussions / Chat
You can use gitter to ask questions and discuss ideas about this project.
Requirements
This library is intended to be used with go 1.11
or higher as it is built using Go modules.
It's recommended to use modules for consumers as well if possible. If you are unfamiliar with Go modules there's a list of recommended resources in the wiki.
Go Get
go get -u github.com/markus-wa/demoinfocs-golang
If you are using a older (v0.x
) version of the library, check out the v0.5
branch. However, it's highly recommended to switch to master (v1.0.0), which contains many new features and improvements. It also promises compatibility with new relases for the foreseeable future.
Example
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.
package main import ( "fmt" "os" dem "github.com/markus-wa/demoinfocs-golang" events "github.com/markus-wa/demoinfocs-golang/events" ) // Run like this: go run print_kills.go func main() { f, err := os.Open("/path/to/demo.dem") if err != nil { panic(err) } defer f.Close() p := dem.NewParser(f) // 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.Name, e.Weapon.Weapon, hs, wallBang, e.Victim.Name) }) // Parse to end err = p.ParseToEnd() if err != nil { panic(err) } }
Sample output
Running the code above will print something like this:
xms <AK-47 (HS)> crisby
tiziaN <USP-S (HS)> Ex6TenZ
tiziaN <USP-S> mistou
tiziaN <USP-S (HS)> ALEX
xms <Glock-18 (HS)> tiziaN
...
keev <AWP (HS) (WB)> to1nou
...
More examples
Check out the examples folder for more examples, like how to generate heatmaps like this one:
Features
- Game events (kills, shots, round starts/ends, footsteps etc.) - docs / example
- Tracking of game-state (players, teams, grenades etc.) - docs
- Grenade projectiles / trajectories - docs / example
- Access to entities, server-classes & data-tables - docs / example
- Access to all net-messages - docs / example
- Chat & console messages 1 - docs / example
- Easy debugging via build-flags
- Built with performance & concurrency in mind
- Only for some demos; in MM demos the chat is encrypted for example.
Performance / Benchmarks
Two of the top priorities of this parser are performance and concurrency.
Here are some benchmark results from a system with a Intel i7 2600k CPU and SSD disk running Windows 10 and a demo with 85'000 frames.
Overview
Benchmark Description Average Duration SpeedBenchmarkConcurrent
Read and parse 8 demos concurrently
2.90 s (per 8 demos)
~234'000 ticks / s
BenchmarkDemoInfoCs
Read demo from drive and parse
1.39 s
~61'000 ticks / s
BenchmarkInMemory
Read demo from memory and parse
1.38 s
~61'000 ticks / s
Raw output
$ go test -run _NONE_ -bench . -benchtime 30s -benchmem -concurrentdemos 8
goos: windows
goarch: amd64
pkg: github.com/markus-wa/demoinfocs-golang
BenchmarkDemoInfoCs-8 30 1397398190 ns/op 162254528 B/op 839779 allocs/op
BenchmarkInMemory-8 30 1384877250 ns/op 162109924 B/op 839628 allocs/op
BenchmarkConcurrent-8 20 2902574295 ns/op 1297042534 B/op 6717163 allocs/op
--- BENCH: BenchmarkConcurrent-8
demoinfocs_test.go:425: Running concurrency benchmark with 8 demos
demoinfocs_test.go:425: Running concurrency benchmark with 8 demos
PASS
ok github.com/markus-wa/demoinfocs-golang 147.800s
Versioning
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.
It's recommended to use some kind of dependency management system such as dep to ensure reproducible builds.
Projects using demoinfocs-golang
- noesis.gg - A suite of explorative tools to help you analyze and improve your CS:GO performance.
If your project is using this library feel free to submit a PR or send a message in Gitter to be included in the list.
Development
Running tests
To run tests Git LFS is required.
git submodule init git submodule update pushd cs-demos && git lfs pull -I '*' && popd go test
Here's a cool gist of a pre-commit hook to run tests before each commit. You can put this inside the .git/hooks
directory to avoid committing/pushing code with build errors or failing tests.
Debugging
You can use the build tag debugdemoinfocs
(i.e. go test -tags debugdemoinfocs -v
) to print out debugging information - such as game events or unhandled demo-messages - during the parsing process.
Side-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.debugServerClasses=YES'
Check out debug_on.go
for any other settings that can be changed.
Generating protobuf code
Should you need to re-generate the protobuf generated code in the msg
package, you will need the following tools:
-
The latest protobuf generator (
protoc
) from your package manager or https://github.com/google/protobuf/releases -
And
protoc-gen-gogofaster
from gogoprotobuf to generate code for go.go get -u github.com/gogo/protobuf/protoc-gen-gogofaster
Make sure both are inside your PATH
variable.
After installing these use go generate ./msg
to generate the protobuf code.
License
This project is licensed under the MIT license.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK