-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
122 lines (102 loc) · 3.56 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"flag"
"fmt"
"os"
"text/tabwriter"
dem "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
events "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
)
type baitStruct struct {
name string
totalBaits int
}
//ders id
// 76561198128945703
func isBaitingFile(fd string, id int64, topBaiters bool) {
f, err := os.Open(fd)
if err != nil {
panic(err)
}
defer f.Close()
p := dem.NewParser(f)
defer p.Close()
totalBaits := 0
pname := ""
var tb map[int64]*baitStruct
tb = make(map[int64]*baitStruct)
p.RegisterEventHandler(func(e events.MatchStart) {
for _, ply := range p.GameState().Participants().All() {
if ply.SteamID64 != 0 {
if topBaiters {
tb[int64(ply.SteamID64)] = &baitStruct{name: ply.Name, totalBaits: 0}
fmt.Printf("[%v] %v\n", ply.SteamID64, tb[int64(ply.SteamID64)].name)
} else {
fmt.Printf("[%v] %v\n", ply.SteamID64, ply.Name)
}
}
}
})
p.RegisterEventHandler(func(e events.Kill) {
if p.GameState().IsMatchStarted() {
// fmt.Printf("[round #%v] %v killed %v\n", p.GameState().TotalRoundsPlayed(), e.Killer.Name, e.Victim.Name)
if e.Victim.SteamID64 == uint64(id) || topBaiters {
pname = e.Victim.Name
// Calculate people alive on team
aliveteam := 0
for _, tm := range e.Victim.TeamState.Members() {
if tm.LastAlivePosition != tm.Position() {
aliveteam = aliveteam + 1
} else {
}
}
if aliveteam == 1 {
// println("Potential Baiter: " + e.Victim.Name + " at " + fmt.Sprint(p.GameState().TotalRoundsPlayed()))
totalBaits = totalBaits + 1
if topBaiters {
tb[int64(e.Victim.SteamID64)].totalBaits = (tb[int64(e.Victim.SteamID64)].totalBaits) + 1
}
}
}
}
})
p.RegisterEventHandler(func(e events.AnnouncementWinPanelMatch) {
if !topBaiters {
roundsPlayed := float32(p.GameState().TotalRoundsPlayed())
fTotalBaits := float32(totalBaits)
fmt.Println("======BAIT CALC======")
fmt.Printf("Player: %v(%v) on %v\n", pname, id, p.Header().MapName)
fmt.Printf("Baited %v/%v = %v percent of rounds\n", totalBaits, p.GameState().TotalRoundsPlayed(), (fTotalBaits/roundsPlayed)*100)
fmt.Println("=====================")
} else {
fmt.Println("======BAIT CALC======")
fmt.Println("MAP: " + p.Header().MapName)
w := new(tabwriter.Writer)
w.Init(os.Stdout, 30, 1, 0, '-', tabwriter.Debug)
fmt.Fprint(w, "name\tid\tpercent of rounds baited\n")
for _, ply := range p.GameState().Participants().All() {
if ply.SteamID64 != 0 {
roundsPlayed := float32(p.GameState().TotalRoundsPlayed())
fTotalBaits := float32(tb[int64(ply.SteamID64)].totalBaits)
fmt.Fprintf(w, "%v\t%v\t%v\n", ply.Name, ply.SteamID64, (fTotalBaits/roundsPlayed)*100)
// fmt.Printf("Player: %v(%v) ", ply.Name, ply.SteamID64)
// fmt.Printf("Baited %v/%v = %v percent of rounds\n", tb[int64(ply.SteamID64)].totalBaits, p.GameState().TotalRoundsPlayed(), (fTotalBaits/roundsPlayed)*100)
w.Flush()
}
}
fmt.Println("=====================")
}
})
err = p.ParseToEnd()
if err != nil {
panic(err)
}
}
func main() {
println("Is He Baiting For Frags? - The Age Old Question")
demoFile := flag.String("demofile", "test.dem", "The demo file to parse")
steamID := flag.Int64("steamId", 76561198128945703, "SteamId64 of player to Watch")
topBaiters := flag.Bool("topBaiters", false, "Analyze every player")
flag.Parse()
isBaitingFile(*demoFile, *steamID, *topBaiters)
}