Skip to content

Commit 00d3541

Browse files
committed
Merge remote-tracking branch 'origin/master' into v3
2 parents 7dbdaaa + c691036 commit 00d3541

31 files changed

+480
-168
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ jobs:
3737
sudo apt-get install -y p7zip-full
3838
3939
# Install interface generator
40-
GO111MODULE=off go get github.com/vburenin/ifacemaker
40+
go install github.com/vburenin/ifacemaker@v1.1.0
4141
4242
# Fetch refs for linter
4343
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
4444
git fetch
4545
4646
# Install golangci-lint
47-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.32.2
47+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
4848
4949
- name: Build
5050
run: scripts/build.sh

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: "CodeQL"
22

33
on:
44
push:
5-
branches: [master, v0.5, v1]
5+
branches: [master, v3]
66
pull_request:
77
# The branches below must be a subset of the branches above
8-
branches: [master]
8+
branches: [master, v3]
99
schedule:
1010
- cron: '0 1 * * 4'
1111

@@ -22,33 +22,11 @@ jobs:
2222
# a pull request then we can checkout the head.
2323
fetch-depth: 2
2424

25-
# If this run was triggered by a pull request event, then checkout
26-
# the head of the pull request instead of the merge commit.
27-
- run: git checkout HEAD^2
28-
if: ${{ github.event_name == 'pull_request' }}
29-
30-
# Initializes the CodeQL tools for scanning.
3125
- name: Initialize CodeQL
3226
uses: github/codeql-action/init@v1
33-
# Override language selection by uncommenting this and choosing your languages
34-
# with:
35-
# languages: go, javascript, csharp, python, cpp, java
3627

37-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
38-
# If this step fails, then you should remove it and run the build manually (see below)
3928
- name: Autobuild
4029
uses: github/codeql-action/autobuild@v1
4130

42-
# ℹ️ Command-line programs to run using the OS shell.
43-
# 📚 https://git.io/JvXDl
44-
45-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
46-
# and modify them (or add more) to build your code if your project
47-
# uses a compiled language
48-
49-
#- run: |
50-
# make bootstrap
51-
# make release
52-
5331
- name: Perform CodeQL Analysis
5432
uses: github/codeql-action/analyze@v1

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# demoinfocs-golang - CS:GO Demo Parser
22

3-
A blazing fast, feature complete and production ready Go library for parsing and analysing of Counter Strike: Global Offensive (CS:GO) demos (aka replays). It is based on <a href="https://github.com/ValveSoftware/csgo-demoinfo" rel="external">Valve's demoinfogo</a> and <a href="https://github.com/StatsHelix/demoinfo" rel="external">SatsHelix's demoinfo</a> but provides many improvements.
3+
A blazing fast, feature complete and production ready Go library for parsing and analysing of Counter Strike: Global Offensive (CS:GO) demos (aka replays).
44

55
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://vshymanskyy.github.io/StandWithUkraine)
66

@@ -85,6 +85,7 @@ package main
8585

8686
import (
8787
"fmt"
88+
"log"
8889
"os"
8990

9091
dem "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
@@ -94,7 +95,7 @@ import (
9495
func main() {
9596
f, err := os.Open("/path/to/demo.dem")
9697
if err != nil {
97-
panic(err)
98+
log.Panic("failed to open demo file: ", err)
9899
}
99100
defer f.Close()
100101

@@ -117,7 +118,7 @@ func main() {
117118
// Parse to end
118119
err = p.ParseToEnd()
119120
if err != nil {
120-
panic(err)
121+
log.Panic("failed to parse demo: ", err)
121122
}
122123
}
123124
```
@@ -219,7 +220,7 @@ There is one caveat however: Beta features - which are marked as such via commen
219220
- [megaclan3000](https://github.com/megaclan3000/megaclan3000) - A CS:GO stats page for clans with recent matches and player statistics
220221
- [csgo Python library](https://github.com/pnxenopoulos/csgo) - A wrapper for the Golang parser in Python
221222

222-
If your project is using this library feel free to submit a PR or send a message in [Gitter](https://gitter.im/csgodemos/demoinfo-lib) to be included in the list.
223+
If your project is using this library feel free to submit a PR or send a message via [Discord](https://discord.gg/eTVBgKeHnh) to be included in the list.
223224

224225
## Development
225226

@@ -304,6 +305,8 @@ To install some (optional, but quite handy) `pre-commit` and `pre-push` hooks, y
304305

305306
## Acknowledgements
306307

308+
This library was originally based on <a href="https://github.com/ValveSoftware/csgo-demoinfo" rel="external">Valve's demoinfogo</a> and <a href="https://github.com/StatsHelix/demoinfo" rel="external">SatsHelix's demoinfo</a> (although today it shares little resemblence with these two).
309+
307310
Thanks to [@JetBrains](https://github.com/JetBrains) for sponsoring a license of their awesome [GoLand](https://www.jetbrains.com/go/) IDE for this project - go check it out!
308311

309312
And a very special thanks goes out to all the [⭐contributors⭐](https://github.com/markus-wa/demoinfocs-golang/graphs/contributors)️, be it in the form of PRs, issues or anything else.

examples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
Here you can find a overview of examples on how to use demoinfocs-golang.
44

5+
:information_source: Example code may not be production ready - specifically error handling and such is done in a simplified way and should not be used in critical systems as-is.
6+
57
|Example|Description
68
|-|-|
79
|[heatmap](heatmap)|Creating a heatmap from positions where players fired shots from|
810
|[nade-trajectories](nade-trajectories)|Map overview with grenade trajectories|
911
|[entities](entities)|Using unhandled data from entities (`Parser.ServerClasses()`)|
1012
|[net-messages](net-messages)|Parsing and handling custom net-messages|
13+
|[encrypted-net-messages](encrypted-net-messages)|Parsing and handling encrypted net-messages (e.g. text chat in MM demos)|
1114
|[print-events](print-events)|Printing kills, scores & chat messages|
1215
|[mocking](mocking)|Using the `fake` package to write unit tests for your code|
1316
|[web-assembly](web-assembly)|Using the library from JavaScript (browser/node) with [WebAssembly](https://webassembly.org/)|

examples/common.go

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package examples
22

33
import (
4+
"encoding/json"
45
"flag"
6+
"fmt"
7+
"image"
58
"io"
69
"io/ioutil"
10+
"net/http"
711
"os"
12+
13+
"github.com/golang/geo/r2"
14+
"github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/metadata"
815
)
916

1017
// DemoPathFromArgs returns the value of the -demo command line flag.
@@ -24,15 +31,20 @@ func DemoPathFromArgs() string {
2431
return demPath
2532
}
2633

34+
func checkError(err error) {
35+
if err != nil {
36+
panic(err)
37+
}
38+
}
39+
2740
// RedirectStdout redirects standard output to dev null.
2841
// Panics if an error occurs.
2942
func RedirectStdout(f func()) {
3043
// Redirect stdout, the resulting image is written to this
3144
old := os.Stdout
45+
3246
r, w, err := os.Pipe()
33-
if err != nil {
34-
panic(err)
35-
}
47+
checkError(err)
3648

3749
os.Stdout = w
3850

@@ -46,3 +58,57 @@ func RedirectStdout(f func()) {
4658

4759
os.Stdout = old
4860
}
61+
62+
type mapMetadata struct {
63+
PosX float64 `json:"pos_x,string"`
64+
PosY float64 `json:"pos_y,string"`
65+
Scale float64 `json:"scale,string"`
66+
}
67+
68+
// GetMapMetadata fetches metadata for a specific map version from
69+
// `https://radar-overviews.csgo.saiko.tech/<map>/<crc>/info.json`.
70+
// Panics if any error occurs.
71+
func GetMapMetadata(name string, crc uint32) metadata.Map {
72+
url := fmt.Sprintf("https://radar-overviews.csgo.saiko.tech/%s/%d/info.json", name, crc)
73+
74+
resp, err := http.Get(url)
75+
checkError(err)
76+
77+
defer resp.Body.Close()
78+
79+
var data map[string]mapMetadata
80+
81+
err = json.NewDecoder(resp.Body).Decode(&data)
82+
checkError(err)
83+
84+
mapInfo, ok := data[name]
85+
if !ok {
86+
panic(fmt.Sprintf("failed to get map info.json entry for %q", name))
87+
}
88+
89+
return metadata.Map{
90+
Name: name,
91+
PZero: r2.Point{
92+
X: mapInfo.PosX,
93+
Y: mapInfo.PosY,
94+
},
95+
Scale: mapInfo.Scale,
96+
}
97+
}
98+
99+
// GetMapMetadata fetches metadata for a specific map version from
100+
// `https://radar-overviews.csgo.saiko.tech/<map>/<crc>/info.json`.
101+
// Panics if any error occurs.
102+
func GetMapRadar(name string, crc uint32) image.Image {
103+
url := fmt.Sprintf("https://radar-overviews.csgo.saiko.tech/%s/%d/radar.png", name, crc)
104+
105+
resp, err := http.Get(url)
106+
checkError(err)
107+
108+
defer resp.Body.Close()
109+
110+
img, _, err := image.Decode(resp.Body)
111+
checkError(err)
112+
113+
return img
114+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Parsing & handling encrypted net-messages
2+
3+
See also [net-messages](../net-messages) for regular net-messages.
4+
5+
This example shows how to have the parser deal with encrypted net-messages.
6+
7+
For Valve MM games, the decryption key can be obtained from `.dem.info` files using `MatchInfoDecryptionKey()`.
8+
The key then needs to be passed to `ParserConfig.NetMessageDecryptionKey`.
9+
10+
## Run
11+
12+
go run enc_net_nsg.go -demo path/to/demo.dem -info path/to/demo.dem.info
13+
14+
This prints chat messages from the passed demo (assuming the `.dem.info` file contains the correct decryption key).
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"io/ioutil"
6+
"log"
7+
"os"
8+
9+
dem "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
10+
"github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
11+
)
12+
13+
func checkErr(err error) {
14+
if err != nil {
15+
panic(err)
16+
}
17+
}
18+
19+
func main() {
20+
fl := new(flag.FlagSet)
21+
22+
demPathPtr := fl.String("demo", "", "Demo file `path`")
23+
infoPathPtr := fl.String("info", "", "Info file `path`")
24+
25+
err := fl.Parse(os.Args[1:])
26+
checkErr(err)
27+
28+
demPath := *demPathPtr
29+
infoPath := *infoPathPtr
30+
31+
infoF, err := os.Open(infoPath)
32+
checkErr(err)
33+
34+
b, err := ioutil.ReadAll(infoF)
35+
checkErr(err)
36+
37+
k, err := dem.MatchInfoDecryptionKey(b)
38+
checkErr(err)
39+
40+
f, err := os.Open(demPath)
41+
checkErr(err)
42+
43+
defer f.Close()
44+
45+
cfg := dem.DefaultParserConfig
46+
cfg.NetMessageDecryptionKey = k
47+
48+
p := dem.NewParserWithConfig(f, cfg)
49+
50+
p.RegisterEventHandler(func(warn events.ParserWarn) {
51+
log.Println("WARNING:", warn.Message)
52+
})
53+
54+
p.RegisterEventHandler(func(message events.ChatMessage) {
55+
log.Println(message)
56+
})
57+
58+
err = p.ParseToEnd()
59+
checkErr(err)
60+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"testing"
6+
)
7+
8+
// Just make sure the example runs
9+
func TestEncryptedNetMessages(t *testing.T) {
10+
if testing.Short() {
11+
t.Skip("skipping test")
12+
}
13+
14+
os.Args = []string{"cmd", "-demo", "../../test/cs-demos/match730_003528806449641685104_1453182610_271.dem", "-info", "../../test/cs-demos/match730_003528806449641685104_1453182610_271.dem.info"}
15+
16+
main()
17+
}
18+
19+
// Make sure it doesn't error / crash
20+
func TestEncryptedNetMessages_BadKey(t *testing.T) {
21+
if testing.Short() {
22+
t.Skip("skipping test")
23+
}
24+
25+
os.Args = []string{"cmd", "-demo", "../../test/cs-demos/match730_003528806449641685104_1453182610_271.dem", "-info", "../../test/cs-demos/match730_003449478367177343081_1946274414_112.dem.info"}
26+
27+
main()
28+
}

examples/heatmap/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This example shows how to create a heatmap from positions where players fired their weapons from.
44

5+
:information_source: Uses radar images from `https://radar-overviews.csgo.saiko.tech/<map>/<crc>/radar.png` - see https://github.com/saiko-tech/csgo-centrifuge for more info.
6+
57
See `heatmap.go` for the source code.
68

79
## Running the example

0 commit comments

Comments
 (0)