-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathenc_net_msg.go
60 lines (43 loc) · 1.03 KB
/
enc_net_msg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"flag"
"io/ioutil"
"log"
"os"
dem "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs"
"github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/events"
)
func checkErr(err error) {
if err != nil {
panic(err)
}
}
func main() {
fl := new(flag.FlagSet)
demPathPtr := fl.String("demo", "", "Demo file `path`")
infoPathPtr := fl.String("info", "", "Info file `path`")
err := fl.Parse(os.Args[1:])
checkErr(err)
demPath := *demPathPtr
infoPath := *infoPathPtr
infoF, err := os.Open(infoPath)
checkErr(err)
b, err := ioutil.ReadAll(infoF)
checkErr(err)
k, err := dem.MatchInfoDecryptionKey(b)
checkErr(err)
f, err := os.Open(demPath)
checkErr(err)
defer f.Close()
cfg := dem.DefaultParserConfig
cfg.NetMessageDecryptionKey = k
p := dem.NewParserWithConfig(f, cfg)
p.RegisterEventHandler(func(warn events.ParserWarn) {
log.Println("WARNING:", warn.Message)
})
p.RegisterEventHandler(func(message events.ChatMessage) {
log.Println(message)
})
err = p.ParseToEnd()
checkErr(err)
}