-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
171 lines (139 loc) · 4.46 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package main
import (
"fmt"
"os"
"path/filepath"
"time"
dem "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
common "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
events "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
st "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/sendtables"
)
const (
obsModeNone = iota // not in spectator mode
obsModeDeathCam // special mode for death cam animation
obsModeFreezeCam // zooms to a target, and freeze-frames on them
obsModeFixed // view from a fixed camera position
obsModeInEye // follow a player in first person view
obsModeChase // follow a player in third person view
obsModeRoaming // free roaming
)
func main() {
if len(os.Args) < 2 {
fmt.Printf("Usage: %s <path/to/demo>\n", filepath.Base(os.Args[0]))
return
}
fmt.Printf("Analyze started: %s\n", os.Args[1])
f, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
defer f.Close()
p := dem.NewParser(f)
defer p.Close()
var roundStartTime time.Duration
roundNo := p.GameState().TotalRoundsPlayed() + 1
inRound := false
bustas := make(map[*common.Player]bool)
p.RegisterEventHandler(func(e events.RoundFreezetimeEnd) {
roundNo = p.GameState().TotalRoundsPlayed() + 1
inRound = true
roundStartTime = p.CurrentTime()
bustas = make(map[*common.Player]bool)
// fmt.Printf("Round %d started\n", roundNo)
for _, player := range p.GameState().Participants().Connected() {
coachingTeam, ok := player.Entity.PropertyValue("m_iCoachingTeam")
if !ok || coachingTeam.IntVal == 0 {
continue
}
obsMode, ok := player.Entity.PropertyValue("m_iObserverMode")
if !ok {
continue
}
if obsMode.IntVal == obsModeFixed {
bustas[player] = true
}
}
})
p.RegisterEventHandler(func(e events.RoundEnd) {
inRound = false
// timeSinceRoundStart := p.CurrentTime() - roundStartTime
// fmt.Printf("Round %d ended [%fs]\n", roundNo, timeSinceRoundStart.Seconds())
for busta := range bustas {
coachingTeam, ok := busta.Entity.PropertyValue("m_iCoachingTeam")
if !ok || coachingTeam.IntVal == 0 {
continue
}
fmt.Printf("Round: %d, Busta: [%s]%s (%d)\n", roundNo, getTeamTag(common.Team(coachingTeam.IntVal)), busta.Name, busta.SteamID64)
}
bustas = make(map[*common.Player]bool)
})
p.RegisterEventHandler(func(e events.PlayerDisconnected) {
timeSinceRoundStart := p.CurrentTime() - roundStartTime
_, ok := bustas[e.Player]
if !ok {
return
}
delete(bustas, e.Player)
if !inRound || timeSinceRoundStart.Milliseconds() < 10000 {
return
}
coachingTeam, ok := e.Player.Entity.PropertyValue("m_iCoachingTeam")
if !ok || coachingTeam.IntVal == 0 {
return
}
fmt.Printf("Round: %d, Busta: [%s]%s (%d)\n", roundNo, getTeamTag(common.Team(coachingTeam.IntVal)), e.Player.Name, e.Player.SteamID64)
})
p.RegisterEventHandler(func(events.DataTablesParsed) {
p.ServerClasses().FindByName("CCSPlayer").OnEntityCreated(func(entity st.Entity) {
entity.Property("m_iObserverMode").OnUpdate(func(val st.PropertyValue) {
obs := p.GameState().Participants().ByEntityID()[entity.ID()]
newObsMode := val.IntVal
coachingTeam := common.TeamUnassigned
timeSinceRoundStart := p.CurrentTime() - roundStartTime
if obs.Team != common.TeamSpectators {
return
}
prop, ok := obs.Entity.PropertyValue("m_iCoachingTeam")
if ok {
coachingTeam = common.Team(prop.IntVal)
}
// fmt.Printf("%s -> %d [%fs]\n", obs.Name, newObsMode, timeSinceRoundStart.Seconds())
if newObsMode == obsModeInEye {
if !inRound || timeSinceRoundStart.Milliseconds() < 500 {
delete(bustas, obs)
}
} else if newObsMode == obsModeFixed {
allTeamDead := true
for _, busta := range p.GameState().Participants().TeamMembers(coachingTeam) {
if busta != nil && busta.IsAlive() {
allTeamDead = false
break
}
}
if !allTeamDead || (coachingTeam != common.TeamTerrorists && coachingTeam != common.TeamCounterTerrorists) {
bustas[obs] = true
}
}
})
})
})
err = p.ParseToEnd()
if err != nil {
panic(err)
}
fmt.Printf("Analyze ended: %s\n", os.Args[1])
}
func getTeamTag(team common.Team) string {
switch team {
case common.TeamUnassigned:
return "UNASSIGNED"
case common.TeamSpectators:
return "SPEC"
case common.TeamTerrorists:
return "T"
case common.TeamCounterTerrorists:
return "CT"
}
return "UNKNOWN"
}