2022-05-25 14:18:29 +02:00
|
|
|
//==== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. =====//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//
|
|
|
|
//===========================================================================//
|
|
|
|
|
2023-05-10 00:05:38 +02:00
|
|
|
#include "tier0_pch.h"
|
2022-07-08 00:55:01 +02:00
|
|
|
#include "tier0/dbg.h"
|
2022-05-25 14:18:29 +02:00
|
|
|
#include "tier0/platform.h"
|
2023-03-27 02:01:48 +02:00
|
|
|
#ifndef NETCONSOLE
|
2022-05-25 14:18:29 +02:00
|
|
|
#include "tier0/threadtools.h"
|
2022-08-03 18:34:44 +02:00
|
|
|
#include "tier0/commandline.h"
|
2022-05-25 14:18:29 +02:00
|
|
|
|
|
|
|
#if defined( _X360 )
|
|
|
|
#include "xbox/xbox_console.h"
|
|
|
|
#endif
|
2023-03-27 02:01:48 +02:00
|
|
|
#endif // !NETCONSOLE
|
2023-05-10 00:05:38 +02:00
|
|
|
|
|
|
|
CoreMsgVCallbackSink_t g_CoreMsgVCallback = nullptr;
|
2022-05-25 14:18:29 +02:00
|
|
|
|
2022-07-06 21:11:32 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// True if -hushasserts was passed on command line.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool HushAsserts()
|
|
|
|
{
|
2023-03-27 02:01:48 +02:00
|
|
|
#if defined (DBGFLAG_ASSERT) && !defined (NETCONSOLE)
|
2022-07-08 00:55:01 +02:00
|
|
|
static bool s_bHushAsserts = !!CommandLine()->FindParm("-hushasserts");
|
|
|
|
return s_bHushAsserts;
|
|
|
|
#else
|
2022-07-06 21:11:32 +02:00
|
|
|
return true;
|
2022-07-08 00:55:01 +02:00
|
|
|
#endif
|
2022-07-06 21:11:32 +02:00
|
|
|
}
|
|
|
|
|
2022-05-25 14:18:29 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Templates to assist in validating pointers:
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-04-02 17:02:04 +02:00
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidReadPtr(void* ptr, int count/* = 1*/)
|
2022-05-25 14:18:29 +02:00
|
|
|
{
|
|
|
|
#if defined( _WIN32 ) && !defined( _X360 )
|
|
|
|
Assert(!IsBadReadPtr(ptr, count));
|
|
|
|
#else
|
|
|
|
Assert(!count || ptr);
|
|
|
|
#endif
|
2023-04-02 17:02:04 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
NOTE_UNUSED(ptr);
|
|
|
|
NOTE_UNUSED(count);
|
|
|
|
#endif // NDEBUG
|
2022-05-25 14:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-04-02 17:02:04 +02:00
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidWritePtr(void* ptr, int count/* = 1*/)
|
2022-05-25 14:18:29 +02:00
|
|
|
{
|
|
|
|
#if defined( _WIN32 ) && !defined( _X360 )
|
|
|
|
Assert(!IsBadWritePtr(ptr, count));
|
|
|
|
#else
|
|
|
|
Assert(!count || ptr);
|
|
|
|
#endif
|
2023-04-02 17:02:04 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
NOTE_UNUSED(ptr);
|
|
|
|
NOTE_UNUSED(count);
|
|
|
|
#endif // NDEBUG
|
2022-05-25 14:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-04-02 17:02:04 +02:00
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidReadWritePtr(void* ptr, int count/* = 1*/)
|
2022-05-25 14:18:29 +02:00
|
|
|
{
|
|
|
|
#if defined( _WIN32 ) && !defined( _X360 )
|
|
|
|
Assert(!(IsBadWritePtr(ptr, count) || IsBadReadPtr(ptr, count)));
|
|
|
|
#else
|
|
|
|
Assert(!count || ptr);
|
|
|
|
#endif
|
2023-04-02 17:02:04 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
NOTE_UNUSED(ptr);
|
|
|
|
NOTE_UNUSED(count);
|
|
|
|
#endif // NDEBUG
|
2022-05-25 14:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-04-02 17:02:04 +02:00
|
|
|
/*PLATFORM_INTERFACE*/ void _AssertValidStringPtr(const TCHAR* ptr, int maxchar/* = 0xFFFFFF */)
|
2022-05-25 14:18:29 +02:00
|
|
|
{
|
|
|
|
#if defined( _WIN32 ) && !defined( _X360 )
|
|
|
|
#ifdef TCHAR_IS_CHAR
|
|
|
|
Assert(!IsBadStringPtr(ptr, maxchar));
|
|
|
|
#else
|
|
|
|
Assert(!IsBadStringPtrW(ptr, maxchar));
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
Assert(ptr);
|
|
|
|
#endif
|
2023-04-02 17:02:04 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
NOTE_UNUSED(ptr);
|
|
|
|
NOTE_UNUSED(maxchar);
|
|
|
|
#endif // NDEBUG
|
2022-05-25 14:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-04-02 17:02:04 +02:00
|
|
|
/*PLATFORM_INTERFACE*/ void AssertValidWStringPtr(const wchar_t* ptr, int maxchar/* = 0xFFFFFF */)
|
2022-05-25 14:18:29 +02:00
|
|
|
{
|
|
|
|
#if defined( _WIN32 ) && !defined( _X360 )
|
|
|
|
Assert(!IsBadStringPtrW(ptr, maxchar));
|
|
|
|
#else
|
|
|
|
Assert(ptr);
|
|
|
|
#endif
|
2023-04-02 17:02:04 +02:00
|
|
|
#ifdef NDEBUG
|
|
|
|
NOTE_UNUSED(ptr);
|
|
|
|
NOTE_UNUSED(maxchar);
|
|
|
|
#endif // NDEBUG
|
2022-05-25 14:18:29 +02:00
|
|
|
}
|
|
|
|
|
2023-03-26 16:09:05 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Show logs to all console interfaces (va_list version)
|
|
|
|
// Input : logType -
|
|
|
|
// logLevel -
|
|
|
|
// context -
|
|
|
|
// *pszLogger -
|
|
|
|
// *pszFormat -
|
|
|
|
// args -
|
|
|
|
// exitCode -
|
2023-03-27 02:01:48 +02:00
|
|
|
// *pszUptimeOverride -
|
2023-03-26 16:09:05 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-27 02:01:48 +02:00
|
|
|
void CoreMsgV(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
|
|
|
|
const char* pszLogger, const char* pszFormat, va_list args,
|
|
|
|
const UINT exitCode /*= NO_ERROR*/, const char* pszUptimeOverride /*= nullptr*/)
|
2023-03-26 16:09:05 +02:00
|
|
|
{
|
2023-05-10 00:05:38 +02:00
|
|
|
// Must be initialized before calling this function!
|
|
|
|
Assert(g_CoreMsgVCallback != nullptr);
|
|
|
|
g_CoreMsgVCallback(logType, logLevel, context, pszLogger, pszFormat, args, exitCode, pszUptimeOverride);
|
2023-03-25 21:27:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Show logs to all console interfaces
|
2023-03-26 16:09:05 +02:00
|
|
|
// Input : logType -
|
|
|
|
// logLevel -
|
|
|
|
// context -
|
|
|
|
// exitCode -
|
|
|
|
// *pszLogger -
|
|
|
|
// *pszFormat -
|
|
|
|
// ... -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CoreMsg(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
|
|
|
|
const UINT exitCode, const char* pszLogger, const char* pszFormat, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, pszFormat);
|
|
|
|
CoreMsgV(logType, logLevel, context, pszLogger, pszFormat, args, exitCode);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Prints general debugging messages
|
2023-03-25 21:27:49 +01:00
|
|
|
// Input : context -
|
|
|
|
// *fmt - ... -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void DevMsg(eDLL_T context, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2023-04-01 10:58:15 +02:00
|
|
|
CoreMsgV(LogType_t::LOG_INFO, LogLevel_t::LEVEL_NOTIFY, context, "sdk", fmt, args);
|
2023-03-25 21:27:49 +01:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2023-03-26 16:09:05 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Prints logs from remote console
|
|
|
|
// Input : context -
|
|
|
|
// *fmt - ... -
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-03-27 02:01:48 +02:00
|
|
|
void NetMsg(LogType_t logType, eDLL_T context, const char* uptime, const char* fmt, ...)
|
2023-03-26 16:09:05 +02:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2023-03-27 02:01:48 +02:00
|
|
|
CoreMsgV(logType, LogLevel_t::LEVEL_NOTIFY, context, "netconsole", fmt, args, NO_ERROR, uptime);
|
2023-03-26 16:09:05 +02:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2023-03-25 21:27:49 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Print engine and SDK warnings
|
|
|
|
// Input : context -
|
|
|
|
// *fmt - ... -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void Warning(eDLL_T context, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2023-03-26 16:09:05 +02:00
|
|
|
CoreMsgV(LogType_t::LOG_WARNING, LogLevel_t::LEVEL_NOTIFY, context, "sdk(warning)", fmt, args);
|
2023-03-25 21:27:49 +01:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Print engine and SDK errors
|
|
|
|
// Input : context -
|
|
|
|
// code -
|
|
|
|
// *fmt - ... -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void Error(eDLL_T context, const UINT code, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2023-03-26 16:09:05 +02:00
|
|
|
CoreMsgV(LogType_t::LOG_ERROR, LogLevel_t::LEVEL_NOTIFY, context, "sdk(error)", fmt, args, code);
|
2023-03-25 21:27:49 +01:00
|
|
|
va_end(args);
|
2022-05-25 14:18:29 +02:00
|
|
|
}
|