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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Xbox console link
//
//=====================================================================================//
#include "xbox/xbox_console.h"
#include "xbox/xbox_vxconsole.h"
#include "tier0/threadtools.h"
#include "tier0/tslist.h"
#include "tier0/ICommandLine.h"
#include "tier0/memdbgon.h"
// all redirecting funneled here, stop redirecting in this module only
#undef OutputDebugStringA
#pragma comment( lib, "xbdm.lib" )
struct DebugString_t
{
unsigned int color;
char *pString;
};
#define XBX_DBGCOMMANDPREFIX "XCMD"
#define XBX_DBGRESPONSEPREFIX "XACK"
#define XBX_DBGPRINTPREFIX "XPRT"
#define XBX_DBGCOLORPREFIX "XCLR"
#define XBX_MAX_RCMDLENGTH 256
#define XBX_MAX_MESSAGE 2048
CThreadFastMutex g_xbx_dbgChannelMutex;
CThreadFastMutex g_xbx_dbgCommandHandlerMutex;
static char g_xbx_dbgRemoteBuf[XBX_MAX_RCMDLENGTH];
static HANDLE g_xbx_dbgValidEvent;
static HANDLE g_xbx_dbgCmdCompleteEvent;
bool g_xbx_bUseVXConsoleOutput = true;
bool g_xbx_bDoSyncOutput;
static ThreadHandle_t g_xbx_hDebugThread;
CTSQueue<DebugString_t> g_xbx_DebugStringQueue;
extern CInterlockedInt g_xbx_numProfileCounters;
extern unsigned int g_xbx_profileCounters[];
extern char g_xbx_profileName[];
int g_xbx_freeMemory;
_inline bool XBX_NoXBDM() { return false; }
static CXboxConsole XboxConsole;
DLL_EXPORT IXboxConsole *GetConsoleInterface()
{
return &XboxConsole;
}
//-----------------------------------------------------------------------------
// Low level string output.
// Input string should be stack based, can get clobbered.
//-----------------------------------------------------------------------------
static void OutputStringToDevice( unsigned int color, char *pString, bool bRemoteValid )
{
if ( !bRemoteValid )
{
// local debug only
OutputDebugStringA( pString );
return;
}
// remote debug valid
// non pure colors don't translate well - find closest pure hue
unsigned int bestColor = color;
int r = ( bestColor & 0xFF );
int g = ( bestColor >> 8 ) & 0xFF;
int b = ( bestColor >> 16 ) & 0xFF;
if ( ( r && r != 255 ) || ( g && g != 255 ) || ( b && b != 255 ) )
{
int r0, g0, b0;
unsigned int minDist = 0xFFFFFFFF;
for ( int i=0; i<8; i++ )
{
r0 = g0 = b0 = 0;
if ( i&4 )
r0 = 255;
if ( i&2 )
g0 = 255;
if ( i&1 )
b0 = 255;
unsigned int d = ( r-r0 )*( r-r0 ) + ( g-g0 )*( g-g0 ) + ( b-b0 )*( b-b0 );
if ( minDist > d )
{
minDist = d;
bestColor = XMAKECOLOR( r0, g0, b0 );
}
}
}
// create color string
char colorString[16];
sprintf( colorString, XBX_DBGCOLORPREFIX "[%8.8x]", bestColor );
// chunk line out, for each cr
char strBuffer[XBX_MAX_RCMDLENGTH];
char *pStart = pString;
char *pEnd = pStart + strlen( pStart );
char *pNext;
while ( pStart < pEnd )
{
pNext = strchr( pStart, '\n' );
if ( !pNext )
pNext = pEnd;
else
*pNext = '\0';
int length = _snprintf( strBuffer, XBX_MAX_RCMDLENGTH, "%s!%s%s", XBX_DBGPRINTPREFIX, colorString, pStart );
if ( length == -1 )
{
strBuffer[sizeof( strBuffer )-1] = '\0';
}
// Send the string
DmSendNotificationString( strBuffer );
// advance past cr
pStart = pNext+1;
}
}
//-----------------------------------------------------------------------------
// XBX_IsConsoleConnected
//
//-----------------------------------------------------------------------------
bool CXboxConsole::IsConsoleConnected()
{
bool bConnected;
if ( g_xbx_dbgValidEvent == NULL )
{
// init was never called
return false;
}
AUTO_LOCK_FM( g_xbx_dbgChannelMutex );
bConnected = ( WaitForSingleObject( g_xbx_dbgValidEvent, 0 ) == WAIT_OBJECT_0 );
return bConnected;
}
//-----------------------------------------------------------------------------
// Output string to listening console. Queues output for slave thread.
// Needs to be lightweight.
//-----------------------------------------------------------------------------
void CXboxConsole::DebugString( unsigned int color, const char* pFormat, ... )
{
if ( XBX_NoXBDM() )
return;
va_list args;
char szStringBuffer[XBX_MAX_MESSAGE];
int length;
// resolve string
va_start( args, pFormat );
length = _vsnprintf( szStringBuffer, sizeof( szStringBuffer ), pFormat, args );
if ( length == -1 )
{
szStringBuffer[sizeof( szStringBuffer ) - 1] = '\0';
}
va_end( args );
if ( !g_xbx_bDoSyncOutput )
{
// queue string for delayed output
DebugString_t debugString;
debugString.color = color;
debugString.pString = strdup( szStringBuffer );
g_xbx_DebugStringQueue.PushItem( debugString );
}
else
{
bool bRemoteValid = g_xbx_bUseVXConsoleOutput && XBX_IsConsoleConnected();
OutputStringToDevice( color, szStringBuffer, bRemoteValid );
}
}
//-----------------------------------------------------------------------------
// Waits for debug queue to drain.
//-----------------------------------------------------------------------------
void CXboxConsole::FlushDebugOutput()
{
while ( g_xbx_DebugStringQueue.Count() != 0 )
{
Sleep( 1 );
}
}
//-----------------------------------------------------------------------------
// _xdbg_strlen
//
// Critical section safe.
//-----------------------------------------------------------------------------
int _xdbg_strlen( const CHAR* str )
{
const CHAR* strEnd = str;
while( *strEnd )
strEnd++;
return strEnd - str;
}
//-----------------------------------------------------------------------------
// _xdbg_tolower
//
// Critical section safe.
//-----------------------------------------------------------------------------
inline CHAR _xdbg_tolower( CHAR ch )
{
if( ch >= 'A' && ch <= 'Z' )
return ch - ( 'A' - 'a' );
else
return ch;
}
//-----------------------------------------------------------------------------
// _xdbg_strnicmp
//
// Critical section safe.
//-----------------------------------------------------------------------------
BOOL _xdbg_strnicmp( const CHAR* str1, const CHAR* str2, int n )
{
while ( ( _xdbg_tolower( *str1 ) == _xdbg_tolower( *str2 ) ) && *str1 && n > 0 )
{
--n;
++str1;
++str2;
}
return ( !n || _xdbg_tolower( *str1 ) == _xdbg_tolower( *str2 ) );
}
//-----------------------------------------------------------------------------
// _xdbg_strcpy
//
// Critical section safe.
//-----------------------------------------------------------------------------
VOID _xdbg_strcpy( CHAR* strDest, const CHAR* strSrc )
{
while ( ( *strDest++ = *strSrc++ ) != 0 );
}
//-----------------------------------------------------------------------------
// _xdbg_strcpyn
//
// Critical section safe.
//-----------------------------------------------------------------------------
VOID _xdbg_strcpyn( CHAR* strDest, const CHAR* strSrc, int numChars )
{
while ( numChars>0 && ( *strDest++ = *strSrc++ ) != 0 )
numChars--;
}
//-----------------------------------------------------------------------------
// _xdbg_gettoken
//
// Critical section safe.
//-----------------------------------------------------------------------------
void _xdbg_gettoken( CHAR** tokenStream, CHAR* token, int tokenSize )
{
int c;
int len;
CHAR* data;
len = 0;
// skip prefix whitespace
data = *tokenStream;
while ( ( c = *data ) <= ' ' )
{
if ( !c )
goto cleanUp;
data++;
}
// parse a token
do
{
if ( len < tokenSize )
token[len++] = c;
data++;
c = *data;
} while ( c > ' ' );
if ( len >= tokenSize )
len = 0;
cleanUp:
token[len] = '\0';
*tokenStream = data;
}
//-----------------------------------------------------------------------------
// _xdbg_tokenize
//
// Critical section safe.
//-----------------------------------------------------------------------------
int _xdbg_tokenize( CHAR* tokenStream, CHAR** tokens, int maxTokens )
{
char token[64];
// tokenize stream into seperate tokens
int numTokens = 0;
while ( 1 )
{
tokens[numTokens++] = tokenStream;
if ( numTokens >= maxTokens )
break;
_xdbg_gettoken( &tokenStream, token, sizeof( token ) );
if ( !tokenStream[0] || !token[0] )
break;
*tokenStream = '\0';
tokenStream++;
}
return ( numTokens );
}
//-----------------------------------------------------------------------------
// _xdbg_findtoken
//
// Critical section safe. Returns -1 if not found
//-----------------------------------------------------------------------------
int _xdbg_findtoken( CHAR** tokens, int numTokens, CHAR* token )
{
int i;
int len;
len = _xdbg_strlen( token );
for ( i=0; i<numTokens; i++ )
{
if ( _xdbg_strnicmp( tokens[i], token, len ) )
return i;
}
// not found
return -1;
}
//-----------------------------------------------------------------------------
// _DebugCommandHandler
//
//-----------------------------------------------------------------------------
HRESULT __stdcall _DebugCommandHandler( const CHAR* strCommand, CHAR* strResponse, DWORD dwResponseLen, PDM_CMDCONT pdmcc )
{
CHAR buff[256];
CHAR* args[8];
int numArgs;
AUTO_LOCK_FM( g_xbx_dbgCommandHandlerMutex );
// skip over the command prefix and the exclamation mark
strCommand += _xdbg_strlen( XBX_DBGCOMMANDPREFIX ) + 1;
if ( strCommand[0] == '\0' )
{
// just a ping
goto cleanUp;
}
// get command and optional arguments
_xdbg_strcpyn( buff, strCommand, sizeof( buff ) );
numArgs = _xdbg_tokenize( buff, args, sizeof( args )/sizeof( CHAR* ) );
if ( _xdbg_strnicmp( args[0], "__connect__", 11 ) )
{
if ( numArgs > 1 && atoi( args[1] ) == VXCONSOLE_PROTOCOL_VERSION )
{
// initial connect - respond that we're connected
_xdbg_strcpyn( strResponse, XBX_DBGRESPONSEPREFIX "Connected To Application.", dwResponseLen );
SetEvent( g_xbx_dbgValidEvent );
// notify convar system to send its commands
// allows vxconsole to re-connect during game
_xdbg_strcpy( g_xbx_dbgRemoteBuf, "getcvars" );
XBX_QueueEvent( XEV_REMOTECMD, ( int )g_xbx_dbgRemoteBuf, 0, 0 );
}
else
{
_xdbg_strcpyn( strResponse, XBX_DBGRESPONSEPREFIX "Rejecting Connection: Wrong Protocol Version.", dwResponseLen );
}
goto cleanUp;
}
if ( _xdbg_strnicmp( args[0], "__disconnect__", 14 ) )
{
// respond that we're disconnected
_xdbg_strcpyn( strResponse, XBX_DBGRESPONSEPREFIX "Disconnected.", dwResponseLen );
ResetEvent( g_xbx_dbgValidEvent );
goto cleanUp;
}
if ( _xdbg_strnicmp( args[0], "__complete__", 12 ) )
{
// remote server has finished command - respond to acknowledge
_xdbg_strcpyn( strResponse, XBX_DBGRESPONSEPREFIX "OK", dwResponseLen );
// set the complete event - allows expected synchronous calling mechanism
SetEvent( g_xbx_dbgCmdCompleteEvent );
goto cleanUp;
}
if ( _xdbg_strnicmp( args[0], "__memory__", 10 ) )
{
// get a current stat of available memory
MEMORYSTATUS stat;
GlobalMemoryStatus( &stat );
g_xbx_freeMemory = stat.dwAvailPhys;
if ( _xdbg_findtoken( args, numArgs, "quiet" ) > 0 )
{
_xdbg_strcpyn( strResponse, XBX_DBGRESPONSEPREFIX "OK", dwResponseLen );
}
else
{
// 32 MB is reserved and fixed by OS, so not reporting
_snprintf( strResponse, dwResponseLen, XBX_DBGRESPONSEPREFIX "Available: %.2f MB, Used: %.2f MB, Free: %.2f MB",
stat.dwTotalPhys/( 1024.0f*1024.0f ) - 32.0f,
( stat.dwTotalPhys - stat.dwAvailPhys )/( 1024.0f*1024.0f ) - 32.0f,
stat.dwAvailPhys/( 1024.0f*1024.0f ) );
}
goto cleanUp;
}
if ( g_xbx_dbgRemoteBuf[0] )
{
// previous command still pending
_xdbg_strcpyn( strResponse, XBX_DBGRESPONSEPREFIX "Cannot execute: Previous command still pending", dwResponseLen );
}
else
{
// add the command to the event queue to be processed by main app
_xdbg_strcpy( g_xbx_dbgRemoteBuf, strCommand );
XBX_QueueEvent( XEV_REMOTECMD, ( int )g_xbx_dbgRemoteBuf, 0, 0 );
_xdbg_strcpyn( strResponse, XBX_DBGRESPONSEPREFIX "OK", dwResponseLen );
}
cleanUp:
return XBDM_NOERR;
}
//-----------------------------------------------------------------------------
// XBX_SendRemoteCommand
//
//-----------------------------------------------------------------------------
void CXboxConsole::SendRemoteCommand( const char *pCommand, bool async )
{
char cmdString[XBX_MAX_RCMDLENGTH];
if ( XBX_NoXBDM() || !IsConsoleConnected() )
return;
AUTO_LOCK_FM( g_xbx_dbgChannelMutex );
_snprintf( cmdString, sizeof( cmdString ), "%s!%s", XBX_DBGCOMMANDPREFIX, pCommand );
HRESULT hr = DmSendNotificationString( cmdString );
if ( FAILED( hr ) )
{
XBX_Error( "XBX_SendRemoteCommand: failed on %s", cmdString );
}
// wait for command completion
if ( !async )
{
DWORD timeout;
if ( !strnicmp( pCommand, "Assert()", 8 ) )
{
// the assert is waiting for user to make selection
timeout = INFINITE;
}
else
{
// no vxconsole operation should take this long
timeout = 15000;
}
if ( WaitForSingleObject( g_xbx_dbgCmdCompleteEvent, timeout ) == WAIT_TIMEOUT )
{
// we have no choice but to dump core
DmCrashDump( false );
}
}
}
//-----------------------------------------------------------------------------
// Handle delayed VXConsole transactions
//
//-----------------------------------------------------------------------------
static unsigned _DebugThreadFunc( void *pParam )
{
while ( 1 )
{
Sleep( 10 );
if ( !g_xbx_DebugStringQueue.Count() && !g_xbx_numProfileCounters && !g_xbx_freeMemory )
{
continue;
}
if ( g_xbx_numProfileCounters )
{
// build and send asynchronously
char dbgCommand[XBX_MAX_RCMDLENGTH];
_snprintf( dbgCommand, sizeof( dbgCommand ), "SetProfileData() %s 0x%8.8x", g_xbx_profileName, g_xbx_profileCounters );
XBX_SendRemoteCommand( dbgCommand, true );
// mark as sent
g_xbx_numProfileCounters = 0;
}
if ( g_xbx_freeMemory )
{
// build and send asynchronously
char dbgCommand[XBX_MAX_RCMDLENGTH];
_snprintf( dbgCommand, sizeof( dbgCommand ), "FreeMemory() 0x%8.8x", g_xbx_freeMemory );
XBX_SendRemoteCommand( dbgCommand, true );
// mark as sent
g_xbx_freeMemory = 0;
}
bool bRemoteValid = g_xbx_bUseVXConsoleOutput && XBX_IsConsoleConnected();
while ( 1 )
{
DebugString_t debugString;
if ( !g_xbx_DebugStringQueue.PopItem( &debugString ) )
{
break;
}
OutputStringToDevice( debugString.color, debugString.pString, bRemoteValid );
free( debugString.pString );
}
}
return 0;
}
//-----------------------------------------------------------------------------
// XBX_InitConsoleMonitor
//
//-----------------------------------------------------------------------------
void CXboxConsole::InitConsoleMonitor( bool bWaitForConnect )
{
if ( XBX_NoXBDM() )
return;
// create our events
g_xbx_dbgValidEvent = CreateEvent( XBOX_DONTCARE, TRUE, FALSE, NULL );
g_xbx_dbgCmdCompleteEvent = CreateEvent( XBOX_DONTCARE, FALSE, FALSE, NULL );
// register our command handler with the debug monitor
HRESULT hr = DmRegisterCommandProcessor( XBX_DBGCOMMANDPREFIX, _DebugCommandHandler );
if ( FAILED( hr ) )
{
XBX_Error( "XBX_InitConsoleMonitor: failed to register command processor" );
}
// user can have output bypass slave thread
g_xbx_bDoSyncOutput = CommandLine()->FindParm( "-syncoutput" ) != 0;
// create a slave thread to do delayed VXConsole transactions
ThreadId_t threadID;
g_xbx_hDebugThread = CreateSimpleThread( _DebugThreadFunc, NULL, &threadID, 16*1024 );
ThreadSetDebugName( threadID, "DebugThread" );
ThreadSetAffinity( g_xbx_hDebugThread, XBOX_PROCESSOR_5 );
if ( bWaitForConnect )
{
XBX_DebugString( XBX_CLR_DEFAULT, "Waiting For VXConsole Connection...\n" );
WaitForSingleObject( g_xbx_dbgValidEvent, INFINITE );
}
}
//-----------------------------------------------------------------------------
// Sends a disconnect signal to possibly attached VXConsole.
//-----------------------------------------------------------------------------
void CXboxConsole::DisconnectConsoleMonitor()
{
if ( XBX_NoXBDM() )
return;
// caller is trying to safely stop vxconsole traffic, disconnect must be synchronous
XBX_SendRemoteCommand( "Disconnect()", false );
}
bool CXboxConsole::GetXboxName( char *pName, unsigned *pLength )
{
return ( DmGetXboxName( pName, (DWORD *)pLength ) == XBDM_NOERR );
}
void CXboxConsole::CrashDump( bool b )
{
DmCrashDump(b);
}
//-----------------------------------------------------------------------------
// Walk to a specific module and dump size info
//-----------------------------------------------------------------------------
int CXboxConsole::DumpModuleSize( const char *pName )
{
HRESULT error;
PDM_WALK_MODULES pWalkMod = NULL;
DMN_MODLOAD modLoad;
int size = 0;
// iterate and find match
do
{
error = DmWalkLoadedModules( &pWalkMod, &modLoad );
if ( XBDM_NOERR == error && !stricmp( modLoad.Name, pName ) )
{
Msg( "0x%8.8x, %5.2f MB, %s\n", modLoad.BaseAddress, modLoad.Size/( 1024.0f*1024.0f ), modLoad.Name );
size = modLoad.Size;
error = XBDM_ENDOFLIST;
}
}
while ( XBDM_NOERR == error );
DmCloseLoadedModules( pWalkMod );
if ( error != XBDM_ENDOFLIST )
{
Warning( "DmWalkLoadedModules() failed.\n" );
}
return size;
}
//-----------------------------------------------------------------------------
// 360 spew sizes of dll modules
//-----------------------------------------------------------------------------
char const* HACK_stristr( char const* pStr, char const* pSearch ) // hack because moved code from above vstdlib
{
AssertValidStringPtr(pStr);
AssertValidStringPtr(pSearch);
if (!pStr || !pSearch)
return 0;
char const* pLetter = pStr;
// Check the entire string
while (*pLetter != 0)
{
// Skip over non-matches
if (tolower((unsigned char)*pLetter) == tolower((unsigned char)*pSearch))
{
// Check for match
char const* pMatch = pLetter + 1;
char const* pTest = pSearch + 1;
while (*pTest != 0)
{
// We've run off the end; don't bother.
if (*pMatch == 0)
return 0;
if (tolower((unsigned char)*pMatch) != tolower((unsigned char)*pTest))
break;
++pMatch;
++pTest;
}
// Found a match!
if (*pTest == 0)
return pLetter;
}
++pLetter;
}
return 0;
}
void CXboxConsole::DumpDllInfo( const char *pBasePath )
{
// Directories containing dlls
static char *dllDirs[] =
{
"bin",
"hl2\\bin",
"tf\\bin",
"portal\\bin",
"episodic\\bin"
};
char binPath[MAX_PATH];
char dllPath[MAX_PATH];
char searchPath[MAX_PATH];
HMODULE hModule;
WIN32_FIND_DATA wfd;
HANDLE hFind;
Msg( "Dumping Module Sizes...\n" );
for ( int i = 0; i < ARRAYSIZE( dllDirs ); ++i )
{
int totalSize = 0;
_snprintf( binPath, sizeof( binPath ), "%s\\%s", pBasePath, dllDirs[i] );
_snprintf( searchPath, sizeof( binPath ), "%s\\*.dll", binPath );
// show the directory we're searching
Msg( "\nDirectory: %s\n\n", binPath );
// Start the find and check for failure.
hFind = FindFirstFile( searchPath, &wfd );
if ( INVALID_HANDLE_VALUE == hFind )
{
Warning( "No Files Found.\n" );
}
else
{
// Load and unload each dll individually.
do
{
if ( !HACK_stristr( wfd.cFileName, "_360.dll" ) )
{
// exclude explicit pc dlls
// FindFirstFile does not support a spec mask of *_360.dll on the Xbox HDD
continue;
}
_snprintf( dllPath, sizeof( dllPath ), "%s\\%s", binPath, wfd.cFileName );
hModule = LoadLibrary( dllPath );
if ( hModule )
{
totalSize += DumpModuleSize( wfd.cFileName );
FreeLibrary( hModule );
}
else
{
Warning( "Failed to load: %s\n", dllPath );
}
}
while( FindNextFile( hFind, &wfd ) );
FindClose( hFind );
Msg( "Total Size: %.2f MB\n", totalSize/( 1024.0f*1024.0f ) );
}
}
}
void CXboxConsole::OutputDebugString( const char *p )
{
::OutputDebugStringA( p );
}
bool CXboxConsole::IsDebuggerPresent()
{
return ( DmIsDebuggerPresent() != 0 );
}
|