-
Notifications
You must be signed in to change notification settings - Fork 115
/
console.cpp
1330 lines (1110 loc) · 31.1 KB
/
console.cpp
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=====================================================================================//
#include "client_pch.h"
#include <time.h>
#include "console.h"
#include "ivideomode.h"
#include "zone.h"
#include "sv_main.h"
#include "server.h"
#include "MapReslistGenerator.h"
#include "tier0/vcrmode.h"
#if defined( _X360 )
#include "xbox/xbox_console.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#if !defined( _X360 )
#define MAXPRINTMSG 4096
#else
#define MAXPRINTMSG 1024
#endif
bool con_debuglog = false;
bool con_initialized = false;
bool con_debuglogmapprefixed = false;
CThreadFastMutex g_AsyncNotifyTextMutex;
static ConVar con_timestamp( "con_timestamp", "0", 0, "Prefix console.log entries with timestamps" );
// In order to avoid excessive opening and closing of the console log file
// we wrap it in an object and keep the handle open. This is necessary
// because of the sometimes considerable cost of opening and closing files
// on Windows. Opening and closing files on Windows is always moderately
// expensive, but profiling may dramatically underestimate the true cost
// because some anti-virus software can make closing a file handle take
// 20-90 ms!
class ConsoleLogManager
{
public:
ConsoleLogManager();
~ConsoleLogManager();
void RemoveConsoleLogFile();
bool ReadConsoleLogFile( CUtlBuffer& buf );
FileHandle_t GetConsoleLogFileHandleForAppend();
void CloseFileIfOpen();
private:
FileHandle_t m_fh;
const char *GetConsoleLogFilename() const;
};
// Wrap the ConsoleLogManager in a function to ensure that the object is always
// constructed before it is used.
ConsoleLogManager& GetConsoleLogManager()
{
static ConsoleLogManager object;
return object;
}
void ConsoleLogFileCallback( IConVar *var, const char *pOldValue, float flOldValue )
{
ConVarRef con_logfile( var->GetName() );
const char *logFile = con_logfile.GetString();
// close any existing file, because we have changed the name
GetConsoleLogManager().CloseFileIfOpen();
// validate the path and the .log/.txt extensions
if ( !COM_IsValidPath( logFile ) || !COM_IsValidLogFilename( logFile ) )
{
ConMsg( "invalid log filename\n" );
con_logfile.SetValue( "console.log" );
return;
}
else
{
const char *extension = Q_GetFileExtension( logFile );
if ( !extension || ( Q_strcasecmp( extension, "log" ) && Q_strcasecmp( extension, "txt" ) ) )
{
char szTemp[MAX_PATH];
V_sprintf_safe( szTemp, "%s.log", logFile );
con_logfile.SetValue( szTemp );
return;
}
}
if ( !COM_IsValidPath( logFile ) )
{
con_debuglog = CommandLine()->FindParm( "-condebug" ) != 0;
}
else
{
con_debuglog = true;
}
}
ConVar con_logfile( "con_logfile", "", 0, "Console output gets written to this file", false, 0.0f, false, 0.0f, ConsoleLogFileCallback );
static const char *GetTimestampString( void )
{
static char string[128];
tm today;
VCRHook_LocalTime( &today );
Q_snprintf( string, sizeof( string ), "%02i/%02i/%04i - %02i:%02i:%02i",
today.tm_mon+1, today.tm_mday, 1900 + today.tm_year,
today.tm_hour, today.tm_min, today.tm_sec );
return string;
}
#ifndef SWDS
static ConVar con_trace( "con_trace", "0", FCVAR_MATERIAL_SYSTEM_THREAD, "Print console text to low level printout." );
static ConVar con_notifytime( "con_notifytime","8", FCVAR_MATERIAL_SYSTEM_THREAD, "How long to display recent console text to the upper part of the game window" );
static ConVar con_times("contimes", "8", FCVAR_MATERIAL_SYSTEM_THREAD, "Number of console lines to overlay for debugging." );
static ConVar con_drawnotify( "con_drawnotify", "1", 0, "Disables drawing of notification area (for taking screenshots)." );
static ConVar con_enable("con_enable", "0", FCVAR_ARCHIVE, "Allows the console to be activated.");
static ConVar con_filter_enable ( "con_filter_enable","0", FCVAR_MATERIAL_SYSTEM_THREAD, "Filters console output based on the setting of con_filter_text. 1 filters completely, 2 displays filtered text brighter than other text." );
static ConVar con_filter_text ( "con_filter_text","", FCVAR_MATERIAL_SYSTEM_THREAD, "Text with which to filter console spew. Set con_filter_enable 1 or 2 to activate." );
static ConVar con_filter_text_out ( "con_filter_text_out","", FCVAR_MATERIAL_SYSTEM_THREAD, "Text with which to filter OUT of console spew. Set con_filter_enable 1 or 2 to activate." );
//-----------------------------------------------------------------------------
// Purpose: Implements the console using VGUI
//-----------------------------------------------------------------------------
class CConPanel : public CBasePanel
{
typedef CBasePanel BaseClass;
public:
enum
{
MAX_NOTIFY_TEXT_LINE = 256
};
CConPanel( vgui::Panel *parent );
virtual ~CConPanel( void );
virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
// Draws the text
virtual void Paint();
// Draws the background image
virtual void PaintBackground();
// Draw notify area
virtual void DrawNotify( void );
// Draws debug ( Con_NXPrintf ) areas
virtual void DrawDebugAreas( void );
int ProcessNotifyLines( int &left, int &top, int &right, int &bottom, bool bDraw );
// Draw helpers
virtual int DrawText( vgui::HFont font, int x, int y, wchar_t *data );
virtual bool ShouldDraw( void );
void Con_NPrintf( int idx, const char *msg );
void Con_NXPrintf( const struct con_nprint_s *info, const char *msg );
void AddToNotify( const Color& clr, char const *msg );
void ClearNotify();
private:
// Console font
vgui::HFont m_hFont;
vgui::HFont m_hFontFixed;
struct CNotifyText
{
Color clr;
float liferemaining;
wchar_t text[MAX_NOTIFY_TEXT_LINE];
};
CCopyableUtlVector< CNotifyText > m_NotifyText;
enum
{
MAX_DBG_NOTIFY = 128,
DBG_NOTIFY_TIMEOUT = 4,
};
float da_default_color[3];
typedef struct
{
wchar_t szNotify[MAX_NOTIFY_TEXT_LINE];
float expire;
float color[3];
bool fixed_width_font;
} da_notify_t;
da_notify_t da_notify[MAX_DBG_NOTIFY];
bool m_bDrawDebugAreas;
};
static CConPanel *g_pConPanel = NULL;
/*
================
Con_HideConsole_f
================
*/
void Con_HideConsole_f( void )
{
if ( IsX360() )
return;
if ( EngineVGui()->IsConsoleVisible() )
{
// hide the console
EngineVGui()->HideConsole();
}
}
/*
================
Con_ShowConsole_f
================
*/
void Con_ShowConsole_f( void )
{
if ( IsX360() )
return;
if ( vgui::input()->GetAppModalSurface() )
{
// If a dialog has modal, it probably has grabbed keyboard focus, so showing
// the console would be a bad idea.
return;
}
if ( !g_ClientDLL->ShouldAllowConsole() )
return;
// make sure we're allowed to see the console
if ( con_enable.GetBool() || developer.GetInt() || CommandLine()->CheckParm("-console") || CommandLine()->CheckParm("-rpt") )
{
// show the console
EngineVGui()->ShowConsole();
// remove any loading screen
SCR_EndLoadingPlaque();
}
}
//-----------------------------------------------------------------------------
// Purpose: toggles the console
//-----------------------------------------------------------------------------
void Con_ToggleConsole_f( void )
{
if ( IsX360() )
return;
if (EngineVGui()->IsConsoleVisible())
{
Con_HideConsole_f();
// If we hide the console, we also hide the game UI
EngineVGui()->HideGameUI();
}
else
{
Con_ShowConsole_f();
}
}
//-----------------------------------------------------------------------------
// Purpose: Clears the console
//-----------------------------------------------------------------------------
void Con_Clear_f( void )
{
if ( IsX360() )
return;
EngineVGui()->ClearConsole();
Con_ClearNotify();
}
/*
================
Con_ClearNotify
================
*/
void Con_ClearNotify (void)
{
if ( g_pConPanel )
{
g_pConPanel->ClearNotify();
}
}
#endif // SWDS
ConsoleLogManager::ConsoleLogManager()
{
m_fh = FILESYSTEM_INVALID_HANDLE;
}
ConsoleLogManager::~ConsoleLogManager()
{
// This fails because of destructor order problems. The file
// system has already been shut down by the time this runs.
// We'll have to count on the OS to close the file for us.
//CloseFileIfOpen();
}
void ConsoleLogManager::RemoveConsoleLogFile()
{
// Make sure the log file is closed before we try deleting it.
CloseFileIfOpen();
g_pFileSystem->RemoveFile( GetConsoleLogFilename(), "GAME" );
}
bool ConsoleLogManager::ReadConsoleLogFile( CUtlBuffer& buf )
{
// Make sure the log file is closed before we try reading it.
CloseFileIfOpen();
const char *pLogFile = GetConsoleLogFilename();
if ( g_pFullFileSystem->ReadFile( pLogFile, "GAME", buf ) )
return true;
return false;
}
FileHandle_t ConsoleLogManager::GetConsoleLogFileHandleForAppend()
{
if ( m_fh == FILESYSTEM_INVALID_HANDLE )
{
const char* file = GetConsoleLogFilename();
m_fh = g_pFileSystem->Open( file, "a" );
}
return m_fh;
}
void ConsoleLogManager::CloseFileIfOpen()
{
if ( m_fh != FILESYSTEM_INVALID_HANDLE )
{
g_pFileSystem->Close( m_fh );
m_fh = FILESYSTEM_INVALID_HANDLE;
}
}
const char *ConsoleLogManager::GetConsoleLogFilename() const
{
const char *logFile = con_logfile.GetString();
if ( !COM_IsValidPath( logFile ) || !COM_IsValidLogFilename( logFile ) )
{
return "console.log";
}
return logFile;
}
/*
================
Con_Init
================
*/
void Con_Init (void)
{
#ifdef DEDICATED
con_debuglog = false; // the dedicated server's console will handle this
con_debuglogmapprefixed = false;
// Check -consolelog arg and set con_logfile if it's present. This gets some messages logged
// that we would otherwise miss due to con_logfile being set in the .cfg file.
const char *filename = NULL;
if ( CommandLine()->CheckParm( "-consolelog", &filename ) && filename && filename[ 0 ] )
{
con_logfile.SetValue( filename );
}
#else
bool bRPTClient = ( CommandLine()->FindParm( "-rpt" ) != 0 );
con_debuglog = bRPTClient || ( CommandLine()->FindParm( "-condebug" ) != 0 );
con_debuglogmapprefixed = CommandLine()->FindParm( "-makereslists" ) != 0;
if ( con_debuglog )
{
con_logfile.SetValue( "console.log" );
if ( bRPTClient || ( CommandLine()->FindParm( "-conclearlog" ) ) )
{
GetConsoleLogManager().RemoveConsoleLogFile();
}
}
#endif // !DEDICATED
con_initialized = true;
}
/*
================
Con_Shutdown
================
*/
void Con_Shutdown (void)
{
con_initialized = false;
}
/*
================
Read the console log from disk and return it in 'buf'. Buf should come
in as an empty TEXT_BUFFER CUtlBuffer.
Returns true if the log file is successfully read.
================
*/
bool GetConsoleLogFileData( CUtlBuffer& buf )
{
return GetConsoleLogManager().ReadConsoleLogFile( buf );
}
/*
================
Con_DebugLog
================
*/
void Con_DebugLog( const char *fmt, ...)
{
va_list argptr;
char data[MAXPRINTMSG];
va_start(argptr, fmt);
Q_vsnprintf(data, sizeof(data), fmt, argptr);
va_end(argptr);
FileHandle_t fh = GetConsoleLogManager().GetConsoleLogFileHandleForAppend();
if (fh != FILESYSTEM_INVALID_HANDLE )
{
if ( con_debuglogmapprefixed )
{
char const *prefix = MapReslistGenerator().LogPrefix();
if ( prefix )
{
g_pFileSystem->Write( prefix, strlen(prefix), fh );
}
}
if ( con_timestamp.GetBool() )
{
static bool needTimestamp = true; // Start the first line with a timestamp
if ( needTimestamp )
{
const char *timestamp = GetTimestampString();
g_pFileSystem->Write( timestamp, strlen( timestamp ), fh );
g_pFileSystem->Write( ": ", 2, fh );
}
needTimestamp = V_stristr( data, "\n" ) != 0;
}
g_pFileSystem->Write( data, strlen(data), fh );
// Now that we don't close the file we need to flush it in order
// to make sure that the data makes it to the file system.
g_pFileSystem->Flush( fh );
}
}
static bool g_fIsDebugPrint = false;
#ifndef SWDS
/*
================
Con_Printf
Handles cursor positioning, line wrapping, etc
================
*/
static bool g_fColorPrintf = false;
static bool g_bInColorPrint = false;
extern CThreadLocalInt<> g_bInSpew;
void Con_Printf( const char *fmt, ... );
extern ConVar spew_consolelog_to_debugstring;
void Con_ColorPrint( const Color& clr, char const *msg )
{
if ( IsPC() )
{
if ( g_bInColorPrint )
return;
int nCon_Filter_Enable = con_filter_enable.GetInt();
if ( nCon_Filter_Enable > 0 )
{
const char *pszText = con_filter_text.GetString();
const char *pszIgnoreText = con_filter_text_out.GetString();
switch( nCon_Filter_Enable )
{
case 1:
// if line does not contain keyword do not print the line
if ( pszText && ( *pszText != '\0' ) && ( Q_stristr( msg, pszText ) == NULL ))
return;
if ( pszIgnoreText && *pszIgnoreText && ( Q_stristr( msg, pszIgnoreText ) != NULL ) )
return;
break;
case 2:
if ( pszIgnoreText && *pszIgnoreText && ( Q_stristr( msg, pszIgnoreText ) != NULL ) )
return;
// if line does not contain keyword print it in a darker color
if ( pszText && ( *pszText != '\0' ) && ( Q_stristr( msg, pszText ) == NULL ))
{
Color mycolor(200, 200, 200, 150 );
g_pCVar->ConsoleColorPrintf( mycolor, "%s", msg );
return;
}
break;
default:
// by default do no filtering
break;
}
}
g_bInColorPrint = true;
// also echo to debugging console
if ( Plat_IsInDebugSession() && !con_trace.GetInt() && !spew_consolelog_to_debugstring.GetBool() )
{
Sys_OutputDebugString(msg);
}
if ( sv.IsDedicated() )
{
g_bInColorPrint = false;
return; // no graphics mode
}
bool convisible = Con_IsVisible();
bool indeveloper = ( developer.GetInt() > 0 );
bool debugprint = g_fIsDebugPrint;
if ( g_fColorPrintf )
{
g_pCVar->ConsoleColorPrintf( clr, "%s", msg );
}
else
{
// write it out to the vgui console no matter what
if ( g_fIsDebugPrint )
{
// Don't spew debug stuff to actual console once in game, unless console isn't up
if ( !cl.IsActive() || !convisible )
{
g_pCVar->ConsoleDPrintf( "%s", msg );
}
}
else
{
g_pCVar->ConsolePrintf( "%s", msg );
}
}
// Make sure we "spew" if this wan't generated from the spew system
if ( !g_bInSpew )
{
Msg( "%s", msg );
}
// Only write to notify if it's non-debug or we are running with developer set > 0
// Buf it it's debug then make sure we don't have the console down
if ( ( !debugprint || indeveloper ) && !( debugprint && convisible ) )
{
if ( g_pConPanel )
{
g_pConPanel->AddToNotify( clr, msg );
}
}
g_bInColorPrint = false;
}
#if defined( _X360 )
int r,g,b,a;
char buffer[MAXPRINTMSG];
const char *pFrom;
char *pTo;
clr.GetColor(r, g, b, a);
// fixup percent printers
pFrom = msg;
pTo = buffer;
while ( *pFrom && pTo < buffer+sizeof(buffer)-1 )
{
*pTo = *pFrom++;
if ( *pTo++ == '%' )
*pTo++ = '%';
}
*pTo = '\0';
XBX_DebugString( XMAKECOLOR(r,g,b), buffer );
#endif
}
#endif
// returns false if the print function shouldn't continue
bool HandleRedirectAndDebugLog( const char *msg )
{
// Add to redirected message
if ( SV_RedirectActive() )
{
SV_RedirectAddText( msg );
return false;
}
// log all messages to file
if ( con_debuglog )
Con_DebugLog( "%s", msg );
if (!con_initialized)
{
return false;
}
return true;
}
void Con_Print( const char *msg )
{
if ( !msg || !msg[0] )
return;
if ( !HandleRedirectAndDebugLog( msg ) )
{
return;
}
#ifdef SWDS
Msg( "%s", msg );
#else
if ( sv.IsDedicated() )
{
Msg( "%s", msg );
}
else
{
#if !defined( _X360 )
Color clr( 255, 255, 255, 255 );
#else
Color clr( 0, 0, 0, 255 );
#endif
Con_ColorPrint( clr, msg );
}
#endif
}
void Con_Printf( const char *fmt, ... )
{
va_list argptr;
char msg[MAXPRINTMSG];
static bool inupdate;
va_start( argptr, fmt );
Q_vsnprintf( msg, sizeof( msg ), fmt, argptr );
va_end( argptr );
#ifndef NO_VCR
// Normally, we shouldn't need to write this data to the file, but it can help catch
// out-of-sync errors earlier.
if ( vcr_verbose.GetInt() )
{
VCRGenericString( "Con_Printf", msg );
}
#endif
if ( !HandleRedirectAndDebugLog( msg ) )
{
return;
}
#ifdef SWDS
Msg( "%s", msg );
#else
if ( sv.IsDedicated() )
{
Msg( "%s", msg );
}
else
{
#if !defined( _X360 )
Color clr( 255, 255, 255, 255 );
#else
Color clr( 0, 0, 0, 255 );
#endif
Con_ColorPrint( clr, msg );
}
#endif
}
#ifndef SWDS
//-----------------------------------------------------------------------------
// Purpose:
// Input : clr -
// *fmt -
// ... -
//-----------------------------------------------------------------------------
void Con_ColorPrintf( const Color& clr, const char *fmt, ... )
{
va_list argptr;
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
Q_vsnprintf (msg,sizeof( msg ), fmt,argptr);
va_end (argptr);
AUTO_LOCK( g_AsyncNotifyTextMutex );
if ( !HandleRedirectAndDebugLog( msg ) )
{
return;
}
g_fColorPrintf = true;
Con_ColorPrint( clr, msg );
g_fColorPrintf = false;
}
#endif
/*
================
Con_DPrintf
A Con_Printf that only shows up if the "developer" cvar is set
================
*/
void Con_DPrintf (const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
Q_vsnprintf(msg,sizeof( msg ), fmt,argptr);
va_end (argptr);
g_fIsDebugPrint = true;
#ifdef SWDS
DevMsg( "%s", msg );
#else
if ( sv.IsDedicated() )
{
DevMsg( "%s", msg );
}
else
{
Color clr( 196, 181, 80, 255 );
Con_ColorPrint ( clr, msg );
}
#endif
g_fIsDebugPrint = false;
}
/*
==================
Con_SafePrintf
Okay to call even when the screen can't be updated
==================
*/
void Con_SafePrintf (const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
Q_vsnprintf(msg,sizeof( msg ), fmt,argptr);
va_end (argptr);
#ifndef SWDS
bool temp;
temp = scr_disabled_for_loading;
scr_disabled_for_loading = true;
#endif
g_fIsDebugPrint = true;
Con_Printf ("%s", msg);
g_fIsDebugPrint = false;
#ifndef SWDS
scr_disabled_for_loading = temp;
#endif
}
#ifndef SWDS
bool Con_IsVisible()
{
return (EngineVGui()->IsConsoleVisible());
}
void Con_NPrintf( int idx, const char *fmt, ... )
{
va_list argptr;
char outtext[MAXPRINTMSG];
va_start(argptr, fmt);
Q_vsnprintf( outtext, sizeof( outtext ), fmt, argptr);
va_end(argptr);
if ( IsPC() )
{
g_pConPanel->Con_NPrintf( idx, outtext );
}
else
{
Con_Printf( outtext );
}
}
void Con_NXPrintf( const struct con_nprint_s *info, const char *fmt, ... )
{
va_list argptr;
char outtext[MAXPRINTMSG];
va_start(argptr, fmt);
Q_vsnprintf( outtext, sizeof( outtext ), fmt, argptr);
va_end(argptr);
if ( IsPC() )
{
g_pConPanel->Con_NXPrintf( info, outtext );
}
else
{
Con_Printf( outtext );
}
}
//-----------------------------------------------------------------------------
// Purpose: Creates the console panel
// Input : *parent -
//-----------------------------------------------------------------------------
CConPanel::CConPanel( vgui::Panel *parent ) : CBasePanel( parent, "CConPanel" )
{
// Full screen assumed
SetSize( videomode->GetModeStereoWidth(), videomode->GetModeStereoHeight() );
SetPos( 0, 0 );
SetVisible( true );
SetMouseInputEnabled( false );
SetKeyBoardInputEnabled( false );
da_default_color[0] = 1.0;
da_default_color[1] = 1.0;
da_default_color[2] = 1.0;
m_bDrawDebugAreas = false;
g_pConPanel = this;
memset( da_notify, 0, sizeof(da_notify) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CConPanel::~CConPanel( void )
{
}
void CConPanel::Con_NPrintf( int idx, const char *msg )
{
if ( idx < 0 || idx >= MAX_DBG_NOTIFY )
return;
#ifdef WIN32
_snwprintf( da_notify[idx].szNotify, sizeof( da_notify[idx].szNotify ) / sizeof( wchar_t ) - 1, L"%S", msg );
#else
_snwprintf( da_notify[idx].szNotify, sizeof( da_notify[idx].szNotify ) / sizeof( wchar_t ) - 1, L"%s", msg );
#endif
da_notify[idx].szNotify[ sizeof( da_notify[idx].szNotify ) / sizeof( wchar_t ) - 1 ] = L'\0';
// Reset values
da_notify[idx].expire = realtime + DBG_NOTIFY_TIMEOUT;
VectorCopy( da_default_color, da_notify[idx].color );
da_notify[idx].fixed_width_font = false;
m_bDrawDebugAreas = true;
}
void CConPanel::Con_NXPrintf( const struct con_nprint_s *info, const char *msg )
{
if ( !info )
return;
if ( info->index < 0 || info->index >= MAX_DBG_NOTIFY )
return;
#ifdef WIN32
_snwprintf( da_notify[info->index].szNotify, sizeof( da_notify[info->index].szNotify ) / sizeof( wchar_t ) - 1, L"%S", msg );
#else
_snwprintf( da_notify[info->index].szNotify, sizeof( da_notify[info->index].szNotify ) / sizeof( wchar_t ) - 1, L"%s", msg );
#endif
da_notify[info->index].szNotify[ sizeof( da_notify[info->index].szNotify ) / sizeof( wchar_t ) - 1 ] = L'\0';
// Reset values
if ( info->time_to_live == -1 )
da_notify[ info->index ].expire = -1; // special marker means to just draw it once
else
da_notify[ info->index ].expire = realtime + info->time_to_live;
VectorCopy( info->color, da_notify[ info->index ].color );
da_notify[ info->index ].fixed_width_font = info->fixed_width_font;
m_bDrawDebugAreas = true;
}
static void safestrncat( wchar_t *text, int maxCharactersWithNullTerminator, wchar_t const *add, int addchars )
{
int maxCharactersWithoutTerminator = maxCharactersWithNullTerminator - 1;
int curlen = wcslen( text );
if ( curlen >= maxCharactersWithoutTerminator )
return;
wchar_t *p = text + curlen;
while ( curlen++ < maxCharactersWithoutTerminator &&
--addchars >= 0 )
{
*p++ = *add++;
}
*p = 0;
}
void CConPanel::AddToNotify( const Color& clr, char const *msg )
{
if ( !host_initialized )
return;
// notify area only ever draws in developer mode - it should never be used for game messages
if ( !developer.GetBool() )
return;
// skip any special characters
if ( msg[0] == 1 ||
msg[0] == 2 )
{
msg++;
}
// Nothing left
if ( !msg[0] )
return;
// Protect against background modifications to m_NotifyText.
AUTO_LOCK( g_AsyncNotifyTextMutex );
CNotifyText *current = NULL;
int slot = m_NotifyText.Count() - 1;
if ( slot < 0 )
{
slot = m_NotifyText.AddToTail();
current = &m_NotifyText[ slot ];
current->clr = clr;
current->text[ 0 ] = 0;
current->liferemaining = con_notifytime.GetFloat();;
}
else
{
current = &m_NotifyText[ slot ];
current->clr = clr;
}
Assert( current );
wchar_t unicode[ 1024 ];
g_pVGuiLocalize->ConvertANSIToUnicode( msg, unicode, sizeof( unicode ) );
wchar_t const *p = unicode;
while ( *p )
{
const wchar_t *nextreturn = wcsstr( p, L"\n" );
if ( nextreturn != NULL )
{
int copysize = nextreturn - p + 1;
safestrncat( current->text, MAX_NOTIFY_TEXT_LINE, p, copysize );
// Add a new notify, but don't add a new one if the previous one was empty...
if ( current->text[0] && current->text[0] != L'\n' )
{
slot = m_NotifyText.AddToTail();
current = &m_NotifyText[ slot ];
}
// Clear it
current->clr = clr;
current->text[ 0 ] = 0;
current->liferemaining = con_notifytime.GetFloat();
// Skip return character
p += copysize;
continue;
}
// Append it