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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//
#include "cbase.h"
#if defined( REPLAY_ENABLED )
#include "cs_replay.h"
#include "c_cs_player.h"
#include "cs_gamestats_shared.h"
#include "cs_client_gamestats.h"
#include "clientmode_shared.h"
#include "replay/ireplaymoviemanager.h"
#include "replay/ireplayfactory.h"
#include "replay/ireplayscreenshotmanager.h"
#include "replay/screenshot.h"
#include <time.h>
//----------------------------------------------------------------------------------------
extern IReplayScreenshotManager *g_pReplayScreenshotManager;
//----------------------------------------------------------------------------------------
CCSReplay::CCSReplay()
{
}
CCSReplay::~CCSReplay()
{
}
void CCSReplay::OnBeginRecording()
{
BaseClass::OnBeginRecording();
// Setup the newly created replay
C_CSPlayer* pPlayer = C_CSPlayer::GetLocalCSPlayer();
if ( pPlayer )
{
SetPlayerClass( pPlayer->PlayerClass() );
SetPlayerTeam( pPlayer->GetTeamNumber() );
}
}
void CCSReplay::OnEndRecording()
{
if ( gameeventmanager )
{
gameeventmanager->RemoveListener( this );
}
BaseClass::OnEndRecording();
}
void CCSReplay::OnComplete()
{
BaseClass::OnComplete();
}
void CCSReplay::Update()
{
BaseClass::Update();
}
float CCSReplay::GetSentryKillScreenshotDelay()
{
ConVarRef replay_screenshotsentrykilldelay( "replay_screenshotsentrykilldelay" );
return replay_screenshotsentrykilldelay.IsValid() ? replay_screenshotsentrykilldelay.GetFloat() : 0.5f;
}
void CCSReplay::FireGameEvent( IGameEvent *pEvent )
{
C_CSPlayer *pLocalPlayer = C_CSPlayer::GetLocalCSPlayer();
if ( !pLocalPlayer )
return;
CaptureScreenshotParams_t params;
V_memset( ¶ms, 0, sizeof( params ) );
if ( FStrEq( pEvent->GetName(), "player_death" ) )
{
ConVarRef replay_debug( "replay_debug" );
if ( replay_debug.IsValid() && replay_debug.GetBool() )
{
DevMsg( "%i: CCSReplay::FireGameEvent(): player_death\n", gpGlobals->tickcount );
}
int nKillerID = pEvent->GetInt( "attacker" );
int nVictimID = pEvent->GetInt( "userid" );
int nDeathFlags = pEvent->GetInt( "death_flags" );
const char *pWeaponName = pEvent->GetString( "weapon" );
// Suicide?
bool bSuicide = nKillerID == nVictimID;
// Try to get killer
C_CSPlayer *pKiller = ToCSPlayer( USERID2PLAYER( nKillerID ) );
// Try to get victim
C_CSPlayer *pVictim = ToCSPlayer( USERID2PLAYER( nVictimID ) );
// Inflictor was a sentry gun?
bool bSentry = V_strnicmp( pWeaponName, "obj_sentrygun", 13 ) == 0;
// Is the killer the local player?
if ( nKillerID == pLocalPlayer->GetUserID() &&
!bSuicide &&
!bSentry )
{
// Domination?
if ( nDeathFlags & REPLAY_DEATH_DOMINATION )
{
AddDomination( nVictimID );
}
// Revenge?
if ( pEvent->GetInt( "death_flags" ) & REPLAY_DEATH_REVENGE )
{
AddRevenge( nVictimID );
}
// Add victim info to kill list
if ( pVictim )
{
AddKill( pVictim->GetPlayerName(), pVictim->PlayerClass() );
}
// Take a quick screenshot with some delay
ConVarRef replay_screenshotkilldelay( "replay_screenshotkilldelay" );
if ( replay_screenshotkilldelay.IsValid() )
{
params.m_flDelay = GetKillScreenshotDelay();
g_pReplayScreenshotManager->CaptureScreenshot( params );
}
}
// Player death?
else if ( pKiller &&
nVictimID == pLocalPlayer->GetUserID() )
{
// Record who killed the player if not a suicide
if ( !bSuicide )
{
RecordPlayerDeath( pKiller->GetPlayerName(), pKiller->PlayerClass() );
}
// Take screenshot - taking a screenshot during feign death is cool, too.
ConVarRef replay_deathcammaxverticaloffset( "replay_deathcammaxverticaloffset" );
ConVarRef replay_playerdeathscreenshotdelay( "replay_playerdeathscreenshotdelay" );
params.m_flDelay = replay_playerdeathscreenshotdelay.IsValid() ? replay_playerdeathscreenshotdelay.GetFloat() : 0.0f;
params.m_nEntity = pLocalPlayer->entindex();
params.m_posCamera.Init( 0,0, replay_deathcammaxverticaloffset.IsValid() ? replay_deathcammaxverticaloffset.GetFloat() : 150 );
params.m_angCamera.Init( 90, 0, 0 ); // Look straight down
params.m_bUseCameraAngles = true;
params.m_bIgnoreMinTimeBetweenScreenshots = true;
g_pReplayScreenshotManager->CaptureScreenshot( params );
}
}
}
bool CCSReplay::IsValidClass( int iClass ) const
{
return ( iClass >= CS_CLASS_NONE && iClass < CS_NUM_CLASSES );
}
bool CCSReplay::IsValidTeam( int iTeam ) const
{
return ( iTeam == TEAM_TERRORIST || iTeam == TEAM_CT );
}
bool CCSReplay::GetCurrentStats( RoundStats_t &out )
{
out = g_CSClientGameStats.GetLifetimeStats();
return true;
}
const char *CCSReplay::GetStatString( int iStat ) const
{
return CSStatProperty_Table[ iStat ].szSteamName;
}
const char *CCSReplay::GetPlayerClass( int iClass ) const
{
Assert( iClass >= CS_CLASS_NONE && iClass < CS_NUM_CLASSES );
return GetCSClassInfo( iClass )->m_pClassName;
}
bool CCSReplay::Read( KeyValues *pIn )
{
return BaseClass::Read( pIn );
}
void CCSReplay::Write( KeyValues *pOut )
{
BaseClass::Write( pOut );
}
const char *CCSReplay::GetMaterialFriendlyPlayerClass() const
{
return BaseClass::GetMaterialFriendlyPlayerClass();
}
void CCSReplay::DumpGameSpecificData() const
{
BaseClass::DumpGameSpecificData();
}
//----------------------------------------------------------------------------------------
class CCSReplayFactory : public IReplayFactory
{
public:
virtual CReplay *Create()
{
return new CCSReplay();
}
};
static CCSReplayFactory s_ReplayManager;
IReplayFactory *g_pReplayFactory = &s_ReplayManager;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CCSReplayFactory, IReplayFactory, INTERFACE_VERSION_REPLAY_FACTORY, s_ReplayManager );
#endif
|