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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//
#include "cl_screenshotmanager.h"
#include "convar.h"
#include "replaysystem.h"
#include "netmessages.h"
#include "cl_replaymanager.h"
#include "cl_sessionblockdownloader.h"
#include "cl_recordingsession.h"
#include "cl_renderqueue.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//----------------------------------------------------------------------------------------
extern ConVar replay_postdeathrecordtime;
//----------------------------------------------------------------------------------------
CON_COMMAND( save_replay, "Save a replay of the current life if possible." )
{
// Is the user running a listen server?
if ( g_pEngineClient->IsListenServer() )
{
Replay_HudMsg( "#Replay_NoListenServer", "replay\\record_fail.wav", true );
return;
}
// Replay enabled on the server?
if ( !g_pReplay->IsReplayEnabled() )
{
Replay_HudMsg( "#Replay_NotEnabled", "replay\\record_fail.wav", true );
return;
}
// Are we recording?
if ( !g_pReplay->IsRecording() )
{
Replay_HudMsg( "#Replay_NotRecording", "replay\\record_fail.wav", true );
return;
}
// Is replay disabled on the client?
if ( g_pClientReplayContextInternal->IsClientSideReplayDisabled() )
{
Replay_HudMsg( "#Replay_ClientSideDisabled", NULL, true );
return;
}
// Get the replay for the current life
CReplay *pReplayForCurrentLife = CL_GetReplayManager()->m_pReplayThisLife;
// Already saved this replay?
if ( !pReplayForCurrentLife || pReplayForCurrentLife->m_bRequestedByUser || pReplayForCurrentLife->m_bSaved )
{
Replay_HudMsg( "#Replay_AlreadySaved", "replay\\record_fail.wav" );
return;
}
// Take a screenshot and write it to disk if one hasn't been taken already
if ( !pReplayForCurrentLife->GetScreenshotCount() )
{
CaptureScreenshotParams_t params;
V_memset( ¶ms, 0, sizeof( params ) );
params.m_flDelay = 0.0f;
params.m_bPrimary = true;
CL_GetScreenshotManager()->CaptureScreenshot( params );
}
// Send a message to the server, regardless of whether the player is alive or dead, requesting
// that a demo be written. Format a file name with the client's steam id and a timestamp
// (gpGlobals->tickcount).
CLC_SaveReplay msgSaveReplay;
g_pEngineClient->GetNetChannel()->SendNetMsg( msgSaveReplay, true );
// Get the session
CClientRecordingSession *pSession = CL_CastSession( CL_GetRecordingSessionManager()->Find( pReplayForCurrentLife->m_hSession ) );
if ( !pSession )
{
AssertMsg( 0, "Replay points to a non-existent session - should never happen!" );
CL_GetErrorSystem()->AddErrorFromTokenName( "#Replay_ReplayBadSession" );
return;
}
// Replay for current life is complete (ie, player is dead and replay is ready to be committed)
if ( pReplayForCurrentLife->m_bComplete )
{
CL_GetReplayManager()->CommitPendingReplayAndBeginDownload();
}
else
{
// Mark the replay as requested by the user, so we can commit automatically as soon as
// the replay is complete (ie when the player dies, etc.).
pReplayForCurrentLife->m_bRequestedByUser = true;
}
// Cache replay pointer in owning session
pSession->CacheReplay( pReplayForCurrentLife );
// Make sure downloading is enabled
pSession->EnsureDownloadingEnabled();
// Add the new entry to the replay browser
g_pClient->OnSaveReplay( pReplayForCurrentLife->GetHandle(), true );
}
//----------------------------------------------------------------------------------------
CON_COMMAND( replay_add_fake_replays, "Adds a set of fake replays" )
{
if ( args.ArgC() < 2 )
{
DevMsg( "Use \'replay_add_fake_replays\' <num fake replays to add> <today only>\n" );
return;
}
// bool bTodayOnly = args.ArgC() >= 3 && args[2][0] == '1';
for ( int i = 0; i < atoi(args[1]); ++i )
{
// TODO:
}
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_confirmquit, "Make sure all replays are rendered before quitting", FCVAR_HIDDEN | FCVAR_DONTRECORD )
{
// TODO: Check to see if any replays are downloading - warn user. If user wants to
// quit anyway, make sure to set any blocks to not downloaded, save, and delete any
// files that were only partially downloaded.
// Unrendered replays? Display the quit confirmation dialog with the option to render all and quit
if ( CL_GetReplayManager()->GetUnrenderedReplayCount() > 0 && g_pClient->OnConfirmQuit() )
{
// Play a sound.
g_pClient->PlaySound( "replay\\confirmquit.wav" );
}
else
{
g_pEngine->Cbuf_AddText( "quit" );
g_pEngine->Cbuf_AddText( "\n" );
}
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_deleteclientreplays, "Deletes all replays from client replay history, as well as all files associated with each replay.", FCVAR_DONTRECORD )
{
CUtlVector< ReplayHandle_t > vecReplayHandles;
FOR_EACH_REPLAY( i )
{
vecReplayHandles.AddToTail( GET_REPLAY_AT( i )->GetHandle() );
}
FOR_EACH_VEC( vecReplayHandles, i )
{
CL_GetReplayManager()->DeleteReplay( vecReplayHandles[ i ], true );
}
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_removeclientreplay, "Remove the replay at the given index.", FCVAR_DONTRECORD )
{
if ( args.ArgC() != 2 )
{
Msg( "Not enough parameters.\n" );
return;
}
CL_GetReplayManager()->DeleteReplay( atoi(args[ 1 ]), true );
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_printclientreplays, "Prints out all client replay info", FCVAR_DONTRECORD )
{
FOR_EACH_REPLAY( i )
{
const CReplay *pReplay = GET_REPLAY_AT( i );
if ( !pReplay )
continue;
int nMonth, nDay, nYear;
pReplay->m_RecordTime.GetDate( nDay, nMonth, nYear );
int nHour, nMin, nSec;
pReplay->m_RecordTime.GetTime( nHour, nMin, nSec );
int nSpawnTick = pReplay->m_nSpawnTick;
int nDeathTick = pReplay->m_nDeathTick;
// TODO: All of this should go into a virtual function in CReplay, rather than some here and some in DumpGameSpecificData()
char szTitle[MAX_REPLAY_TITLE_LENGTH];
g_pVGuiLocalize->ConvertUnicodeToANSI( pReplay->m_wszTitle, szTitle, sizeof( szTitle ) );
Msg( "replay %i: \"%s\"\n", i, szTitle );
Msg( " handle: %i\n", pReplay->GetHandle() );
Msg( " spawn/death tick: %i / %i\n", nSpawnTick, nDeathTick );
Msg( " date: %i/%i/%i\n", nMonth, nDay, nYear );
Msg( " time: %i:%i:%i\n", nHour, nMin, nSec );
Msg( " map: %s\n", pReplay->m_szMapName );
CClientRecordingSession *pSession = CL_CastSession( CL_GetRecordingSessionManager()->FindSession( pReplay->m_hSession ) );
const char *pSessionName = pSession ? pSession->m_strName.Get() : NULL;
Msg( " session name: %s\n", pSessionName ? pSessionName : "" );
if ( pSession )
{
Msg( " last block downloaded: %i\n", pSession->GetGreatestConsecutiveBlockDownloaded() );
Msg( " last block to download: %i\n", pSession->GetLastBlockToDownload() );
}
int nScreenshotCount = pReplay->GetScreenshotCount();
Msg( "\n" );
Msg( " # screenshots: %i\n", nScreenshotCount );
Msg( " session handle: %i\n", (int)pReplay->m_hSession );
for ( int i = 0; i < nScreenshotCount; ++i )
{
const CReplayScreenshot *pScreenshot = pReplay->GetScreenshot( i );
Msg( " screenshot %i:\n", i );
Msg( " dimensions: w=%i, h=%i\n", pScreenshot->m_nWidth, pScreenshot->m_nHeight );
Msg( " base filename: %s\n", pScreenshot->m_szBaseFilename );
}
int nPerfCount = pReplay->GetPerformanceCount();
Msg( "\n" );
Msg( "# performances: %i\n", nPerfCount );
for ( int i = 0; i < nPerfCount; ++i )
{
const CReplayPerformance *pCurPerformance = pReplay->GetPerformance( i );
g_pVGuiLocalize->ConvertUnicodeToANSI( pCurPerformance->m_wszTitle, szTitle, sizeof( szTitle ) );
Msg( " performance %i:\n", i );
Msg( " title: %s\n", szTitle );
Msg( " ticks: in=%i out=%i\n", pCurPerformance->m_nTickIn, pCurPerformance->m_nTickOut );
Msg( " filename: %s\n", pCurPerformance->m_szBaseFilename );
}
Msg( "\n" );
pReplay->DumpGameSpecificData();
// Print replay status
const char *pStatus;
switch ( pReplay->m_nStatus )
{
case CReplay::REPLAYSTATUS_INVALID: pStatus = "invalid"; break;
case CReplay::REPLAYSTATUS_DOWNLOADPHASE: pStatus = "download phase"; break;
case CReplay::REPLAYSTATUS_READYTOCONVERT: pStatus = "ready to convert"; break;
case CReplay::REPLAYSTATUS_RENDERING: pStatus = "rendering"; break;
case CReplay::REPLAYSTATUS_RENDERED: pStatus = "rendered"; break;
case CReplay::REPLAYSTATUS_ERROR: pStatus = "error"; break;
default: pStatus = "";
}
Msg( " status: %s\n\n\n", pStatus );
}
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_renderpause, "Pause Replay rendering.", FCVAR_DONTRECORD )
{
if ( !CL_GetMovieManager()->IsRendering() )
return;
if ( g_pReplayDemoPlayer->IsReplayPaused() )
{
Msg( "Replay rendering already paused.\n" );
return;
}
// Pause playback
g_pReplayDemoPlayer->PauseReplay();
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_renderunpause, "Unpause Replay rendering.", FCVAR_DONTRECORD )
{
if ( !CL_GetMovieManager()->IsRendering() )
return;
if ( !g_pReplayDemoPlayer->IsReplayPaused() )
{
Msg( "Replay rendering not paused.\n" );
return;
}
// Unpause
g_pReplayDemoPlayer->ResumeReplay();
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_printqueuedtakes, "Print a list of takes queued for rendering.", FCVAR_DONTRECORD )
{
const int nCount = CL_GetRenderQueue()->GetCount();
if ( !nCount )
{
ConMsg( "No takes queued for render.\n" );
return;
}
ConMsg( "Takes queued for render:\n" );
ConMsg( " %65s%65s\n", "Replay Name", "Take Name" );
for ( int i = 0; i < nCount; ++i )
{
ReplayHandle_t hReplay;
int iPerf;
CL_GetRenderQueue()->GetEntryData( i, &hReplay, &iPerf );
const CReplay *pReplay = CL_GetReplayManager()->GetReplay( hReplay );
if ( !pReplay )
continue;
char szTakeName[MAX_REPLAY_TITLE_LENGTH];
if ( iPerf == -1 )
{
V_strcpy( szTakeName, "original" );
}
else
{
const CReplayPerformance *pPerformance = pReplay->GetPerformance( iPerf );
if ( !pPerformance )
continue;
V_wcstostr( pPerformance->m_wszTitle, -1, szTakeName, sizeof( szTakeName ) );
}
char szReplayTitle[MAX_REPLAY_TITLE_LENGTH];
V_wcstostr( pReplay->m_wszTitle, -1, szReplayTitle, sizeof( szReplayTitle ) );
ConMsg( " %02i:%65s%65s\n", i, szReplayTitle, szTakeName );
}
}
//----------------------------------------------------------------------------------------
CON_COMMAND_F( replay_clearqueuedtakes, "Clear takes from render queue.", FCVAR_DONTRECORD )
{
CL_GetRenderQueue()->Clear();
ConMsg( "Cleared.\n" );
}
//----------------------------------------------------------------------------------------
|