SpewRetval_t NewSpew(SpewType_t Type, const char *What) { if (Removed || (!What || !ml_Lua)) { return SPEW_CONTINUE; } Color tempColor = GetSpewOutputColor(); tempColor.GetColor(Red,Green,Blue,Alpha); ILuaObject* hook = ml_Lua->GetGlobal("hook"); ILuaObject* hookCall = hook->GetMember("Call"); ml_Lua->Push(hookCall); ml_Lua->Push("SimpleSpew"); ml_Lua->PushNil(); ml_Lua->PushLong(Type); ml_Lua->Push(What); ml_Lua->Push( GetSpewOutputGroup() ); ml_Lua->PushLong( GetSpewOutputLevel() ); ml_Lua->PushLong(Red); ml_Lua->PushLong(Green); ml_Lua->PushLong(Blue); ml_Lua->PushLong(Alpha); ml_Lua->Call(10,0); hookCall->UnReference(); hook->UnReference(); if (OldSpew) { return OldSpew(Type, What); } else { return (SpewRetval_t)0; } }
//----------------------------------------------------------------------------- // Spew func //----------------------------------------------------------------------------- SpewRetval_t ModelBrowserSpewFunc( SpewType_t spewType, const tchar *pMsg ) { OutputDebugString( pMsg ); switch( spewType ) { case SPEW_ASSERT: g_pCVar->ConsoleColorPrintf( Color( 255, 192, 0, 255 ), pMsg ); #ifdef _DEBUG return SPEW_DEBUGGER; #else return SPEW_CONTINUE; #endif case SPEW_ERROR: g_pCVar->ConsoleColorPrintf( Color( 255, 0, 0, 255 ), pMsg ); return SPEW_ABORT; case SPEW_WARNING: g_pCVar->ConsoleColorPrintf( Color( 192, 192, 0, 255 ), pMsg ); break; case SPEW_MESSAGE: { Color c = GetSpewOutputColor(); if ( !Q_stricmp( GetSpewOutputGroup(), "developer" ) ) g_pCVar->ConsoleDPrintf( pMsg ); else g_pCVar->ConsoleColorPrintf( c, pMsg ); } break; } return SPEW_CONTINUE; }
SpewRetval_t CmdLib_SpewOutputFunc( SpewType_t type, char const *pMsg ) { // Hopefully two threads won't call this simultaneously right at the start! if ( !g_bSpewCSInitted ) { InitializeCriticalSection( &g_SpewCS ); g_bSpewCSInitted = true; } WORD old; SpewRetval_t retVal; EnterCriticalSection( &g_SpewCS ); { if (( type == SPEW_MESSAGE ) || (type == SPEW_LOG )) { Color c = GetSpewOutputColor(); if ( c.r() != 255 || c.g() != 255 || c.b() != 255 ) { // custom color old = SetConsoleTextColor( c.r(), c.g(), c.b(), c.a() ); } else { old = SetConsoleTextColor( 1, 1, 1, 0 ); } retVal = SPEW_CONTINUE; } else if( type == SPEW_WARNING ) { old = SetConsoleTextColor( 1, 1, 0, 1 ); retVal = SPEW_CONTINUE; } else if( type == SPEW_ASSERT ) { old = SetConsoleTextColor( 1, 0, 0, 1 ); retVal = SPEW_DEBUGGER; #ifdef MPI // VMPI workers don't want to bring up dialogs and suchlike. // They need to have a special function installed to handle // the exceptions and write the minidumps. // Install the function after VMPI_Init with a call: // SetupToolsMinidumpHandler( VMPI_ExceptionFilter ); if ( g_bUseMPI && !g_bMPIMaster && !Plat_IsInDebugSession() ) { // Generating an exception and letting the // installed handler handle it ::RaiseException ( 0, // dwExceptionCode EXCEPTION_NONCONTINUABLE, // dwExceptionFlags 0, // nNumberOfArguments, NULL // const ULONG_PTR* lpArguments ); // Never get here (non-continuable exception) VMPI_HandleCrash( pMsg, NULL, true ); exit( 0 ); } #endif } else if( type == SPEW_ERROR ) { old = SetConsoleTextColor( 1, 0, 0, 1 ); retVal = SPEW_ABORT; // doesn't matter.. we exit below so we can return an errorlevel (which dbg.dll doesn't do). } else { old = SetConsoleTextColor( 1, 1, 1, 1 ); retVal = SPEW_CONTINUE; } if ( !g_bSuppressPrintfOutput || type == SPEW_ERROR ) printf( "%s", pMsg ); OutputDebugString( pMsg ); if ( type == SPEW_ERROR ) { printf( "\n" ); OutputDebugString( "\n" ); } if( g_pLogFile ) { CmdLib_FPrintf( g_pLogFile, "%s", pMsg ); g_pFileSystem->Flush( g_pLogFile ); } // Dispatch to other spew hooks. FOR_EACH_LL( g_ExtraSpewHooks, i ) g_ExtraSpewHooks[i]( pMsg ); RestoreConsoleTextColor( old ); } LeaveCriticalSection( &g_SpewCS ); if ( type == SPEW_ERROR ) { CmdLib_Exit( 1 ); } return retVal; }