From b2ce189ba158842123c21c50ff40dd5f45faf7da Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:35:10 +0200 Subject: [PATCH] Tools: rename NETCONSOLE define to _TOOLS Rename since this would actually be used for all tools. Also moved 'plat_time.cpp' to tier0 so anything could compile it. --- r5dev/core/logdef.cpp | 12 ++++---- r5dev/core/logger.cpp | 36 +++++++++++------------ r5dev/engine/net.cpp | 12 ++++---- r5dev/engine/net.h | 4 +-- r5dev/netconsole/CMakeLists.txt | 4 +-- r5dev/tier0/dbg.cpp | 20 +++++++++++-- r5dev/{netconsole => tier0}/plat_time.cpp | 10 +++++-- r5dev/tier2/socketcreator.cpp | 4 +-- r5dev/windows/console.cpp | 16 +++++----- 9 files changed, 69 insertions(+), 49 deletions(-) rename r5dev/{netconsole => tier0}/plat_time.cpp (85%) diff --git a/r5dev/core/logdef.cpp b/r5dev/core/logdef.cpp index 27986967..4227fcf9 100644 --- a/r5dev/core/logdef.cpp +++ b/r5dev/core/logdef.cpp @@ -20,7 +20,7 @@ void SpdLog_Init(const bool bAnsiColor) return; } -#ifndef NETCONSOLE +#ifndef _TOOLS g_LogSessionUUID = CreateUUID(); g_LogSessionDirectory = fmt::format("platform\\logs\\{:s}", g_LogSessionUUID); /************************ @@ -33,16 +33,16 @@ void SpdLog_Init(const bool bAnsiColor) g_ImGuiLogger->set_pattern("%v"); g_ImGuiLogger->set_level(spdlog::level::trace); } -#endif // !NETCONSOLE +#endif // !_TOOLS /************************ * WINDOWS LOGGER SETUP * ************************/ { -#ifdef NETCONSOLE +#ifdef _TOOLS g_TermLogger = spdlog::default_logger(); #else g_TermLogger = spdlog::stdout_logger_mt("win_console"); -#endif // NETCONSOLE +#endif // _TOOLS // Determine if user wants ansi-color logging in the terminal. if (bAnsiColor) @@ -57,10 +57,10 @@ void SpdLog_Init(const bool bAnsiColor) //g_TermLogger->set_level(spdlog::level::trace); } -#ifndef NETCONSOLE +#ifndef _TOOLS spdlog::set_default_logger(g_TermLogger); // Set as default. SpdLog_Create(); -#endif // !NETCONSOLE +#endif // !_TOOLS spdlog::set_level(spdlog::level::trace); bInitialized = true; diff --git a/r5dev/core/logger.cpp b/r5dev/core/logger.cpp index 765ccef9..a9440300 100644 --- a/r5dev/core/logger.cpp +++ b/r5dev/core/logger.cpp @@ -9,13 +9,13 @@ #ifndef CLIENT_DLL #include "engine/server/sv_rcon.h" #endif // !CLIENT_DLL -#ifndef NETCONSOLE +#ifndef _TOOLS #include "vscript/languages/squirrel_re/include/sqstdaux.h" -#endif // !NETCONSOLE +#endif // !_TOOLS static const std::regex s_AnsiRowRegex("\\\033\\[.*?m"); std::mutex g_LogMutex; -#if !defined (DEDICATED) && !defined (NETCONSOLE) +#if !defined (DEDICATED) && !defined (_TOOLS) ImVec4 CheckForWarnings(LogType_t type, eDLL_T context, const ImVec4& defaultCol) { ImVec4 color = defaultCol; @@ -67,7 +67,7 @@ ImVec4 GetColorForContext(LogType_t type, eDLL_T context) return CheckForWarnings(type, context, ImVec4(0.81f, 0.81f, 0.81f, 1.00f)); } } -#endif // !DEDICATED && !NETCONSOLE +#endif // !DEDICATED && !_TOOLS const char* GetContextNameByIndex(eDLL_T context, const bool ansiColor = false) { @@ -150,18 +150,18 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context, const char* pszContext = GetContextNameByIndex(context, bUseColor); message.append(pszContext); -#if !defined (DEDICATED) && !defined (NETCONSOLE) +#if !defined (DEDICATED) && !defined (_TOOLS) ImVec4 overlayColor = GetColorForContext(logType, context); eDLL_T overlayContext = context; -#endif // !DEDICATED && !NETCONSOLE +#endif // !DEDICATED && !_TOOLS -#if !defined (NETCONSOLE) +#if !defined (_TOOLS) bool bSquirrel = false; bool bWarning = false; bool bError = false; #else NOTE_UNUSED(pszLogger); -#endif // !NETCONSOLE +#endif // !_TOOLS //------------------------------------------------------------------------- // Setup logger and context @@ -169,24 +169,24 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context, switch (logType) { case LogType_t::LOG_WARNING: -#if !defined (DEDICATED) && !defined (NETCONSOLE) +#if !defined (DEDICATED) && !defined (_TOOLS) overlayContext = eDLL_T::SYSTEM_WARNING; -#endif // !DEDICATED && !NETCONSOLE +#endif // !DEDICATED && !_TOOLS if (bUseColor) { message.append(g_svYellowF); } break; case LogType_t::LOG_ERROR: -#if !defined (DEDICATED) && !defined (NETCONSOLE) +#if !defined (DEDICATED) && !defined (_TOOLS) overlayContext = eDLL_T::SYSTEM_ERROR; -#endif // !DEDICATED && !NETCONSOLE +#endif // !DEDICATED && !_TOOLS if (bUseColor) { message.append(g_svRedF); } break; -#ifndef NETCONSOLE +#ifndef _TOOLS case LogType_t::SQ_INFO: bSquirrel = true; break; @@ -198,7 +198,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context, bSquirrel = true; bWarning = true; break; -#endif // !NETCONSOLE +#endif // !_TOOLS default: break; } @@ -211,7 +211,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context, const string formatted = FormatV(pszFormat, argsCopy); va_end(argsCopy); -#ifndef NETCONSOLE +#ifndef _TOOLS //------------------------------------------------------------------------- // Colorize script warnings and errors //------------------------------------------------------------------------- @@ -253,7 +253,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context, message.append(g_svYellowF); } } -#endif // !NETCONSOLE +#endif // !_TOOLS message.append(formatted); //------------------------------------------------------------------------- @@ -271,7 +271,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context, } } -#ifndef NETCONSOLE +#ifndef _TOOLS // Output is always logged to the file. std::shared_ptr ntlogger = spdlog::get(pszLogger); // <-- Obtain by 'pszLogger'. assert(ntlogger.get() != nullptr); @@ -307,7 +307,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context, g_LogStream.clear(); #endif // !DEDICATED -#endif // !NETCONSOLE +#endif // !_TOOLS if (exitCode) // Terminate the process if an exit code was passed. { diff --git a/r5dev/engine/net.cpp b/r5dev/engine/net.cpp index 424a5342..93614bb8 100644 --- a/r5dev/engine/net.cpp +++ b/r5dev/engine/net.cpp @@ -6,7 +6,7 @@ #include "core/stdafx.h" #include "engine/net.h" -#ifndef NETCONSOLE +#ifndef _TOOLS #include "tier1/cvar.h" #include "mathlib/color.h" #include "net.h" @@ -15,9 +15,9 @@ #include "server/server.h" #include "client/client.h" #endif // !CLIENT_DLL -#endif // !NETCONSOLE +#endif // !_TOOLS -#ifndef NETCONSOLE +#ifndef _TOOLS //----------------------------------------------------------------------------- // Purpose: hook and log the receive datagram // Input : iSocket - @@ -190,7 +190,7 @@ bool NET_ReadMessageType(int* outType, bf_read* buffer) return !buffer->IsOverflowed(); } -#endif // !NETCONSOLE +#endif // !_TOOLS //----------------------------------------------------------------------------- // Purpose: returns the WSA error code @@ -294,7 +294,7 @@ const char* NET_ErrorString(int iCode) } } -#ifndef NETCONSOLE +#ifndef _TOOLS /////////////////////////////////////////////////////////////////////////////// void VNet::Detour(const bool bAttach) const { @@ -310,4 +310,4 @@ netadr_t* g_pNetAdr = nullptr; netkey_t* g_pNetKey = nullptr; double* g_pNetTime = nullptr; -#endif // !NETCONSOLE +#endif // !_TOOLS diff --git a/r5dev/engine/net.h b/r5dev/engine/net.h index b1864b82..34ec844c 100644 --- a/r5dev/engine/net.h +++ b/r5dev/engine/net.h @@ -1,6 +1,6 @@ #pragma once -#ifndef NETCONSOLE +#ifndef _TOOLS #include "engine/net_chan.h" #include "tier1/lzss.h" #define MAX_STREAMS 2 @@ -79,6 +79,6 @@ class VNet : public IDetour virtual void Detour(const bool bAttach) const; }; /////////////////////////////////////////////////////////////////////////////// -#endif // !NETCONSOLE +#endif // !_TOOLS const char* NET_ErrorString(int iCode); diff --git a/r5dev/netconsole/CMakeLists.txt b/r5dev/netconsole/CMakeLists.txt index bb951a54..c18e4c43 100644 --- a/r5dev/netconsole/CMakeLists.txt +++ b/r5dev/netconsole/CMakeLists.txt @@ -6,13 +6,13 @@ start_sources() add_sources( SOURCE_GROUP "Core" "netconsole.cpp" "netconsole.h" - "plat_time.cpp" "${ENGINE_SOURCE_DIR}/core/logdef.cpp" "${ENGINE_SOURCE_DIR}/core/logdef.h" "${ENGINE_SOURCE_DIR}/core/logger.cpp" "${ENGINE_SOURCE_DIR}/core/logger.h" "${ENGINE_SOURCE_DIR}/core/termutil.cpp" "${ENGINE_SOURCE_DIR}/core/termutil.h" + "${ENGINE_SOURCE_DIR}/tier0/plat_time.cpp" ) add_sources( SOURCE_GROUP "Engine" @@ -40,7 +40,7 @@ set_target_properties( ${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)../../../${BUILD_OUTPUT_DIR}/bin/" ) target_compile_definitions( ${PROJECT_NAME} PRIVATE - "NETCONSOLE" + "_TOOLS" ) target_link_libraries( ${PROJECT_NAME} PRIVATE "tier0" diff --git a/r5dev/tier0/dbg.cpp b/r5dev/tier0/dbg.cpp index 550dd822..c48b5768 100644 --- a/r5dev/tier0/dbg.cpp +++ b/r5dev/tier0/dbg.cpp @@ -8,14 +8,14 @@ #include "tier0/dbg.h" #include "tier0/platform.h" -#ifndef NETCONSOLE +#ifndef _TOOLS #include "tier0/threadtools.h" #include "tier0/commandline.h" #if defined( _X360 ) #include "xbox/xbox_console.h" #endif -#endif // !NETCONSOLE +#endif // !_TOOLS CoreMsgVCallbackSink_t g_CoreMsgVCallback = nullptr; @@ -24,7 +24,7 @@ CoreMsgVCallbackSink_t g_CoreMsgVCallback = nullptr; //----------------------------------------------------------------------------- bool HushAsserts() { -#if defined (DBGFLAG_ASSERT) && !defined (NETCONSOLE) +#if defined (DBGFLAG_ASSERT) && !defined (_TOOLS) static bool s_bHushAsserts = !!CommandLine()->FindParm("-hushasserts"); return s_bHushAsserts; #else @@ -222,3 +222,17 @@ void DevWarning(eDLL_T context, const char* fmt, ...) va_end(args); } #endif // !DBGFLAG_STRINGS_STRIP + +//----------------------------------------------------------------------------- +// Purpose: Print engine and SDK errors, and exit process +// Input : context - +// code - +// *fmt - ... - +//----------------------------------------------------------------------------- +void Plat_FatalError(eDLL_T context, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + CoreMsgV(LogType_t::LOG_ERROR, LogLevel_t::LEVEL_NOTIFY, context, "sdk(error)", fmt, args, EXIT_FAILURE); + va_end(args); +} diff --git a/r5dev/netconsole/plat_time.cpp b/r5dev/tier0/plat_time.cpp similarity index 85% rename from r5dev/netconsole/plat_time.cpp rename to r5dev/tier0/plat_time.cpp index 751ed36d..70dd0ffa 100644 --- a/r5dev/netconsole/plat_time.cpp +++ b/r5dev/tier0/plat_time.cpp @@ -1,3 +1,9 @@ +//=============================================================================// +// +// Purpose: Static platform time utilities +// ---------------------------------------------------------------------------- +// NOTE: use this for standalone/tools projects +//=============================================================================// #include "core/stdafx.h" static LARGE_INTEGER g_PerformanceFrequency; @@ -78,11 +84,11 @@ uint64 Plat_USTime() return (uint64)((CurrentTime.QuadPart - g_ClockStart.QuadPart) * g_PerformanceCounterToUS); } -#ifdef NETCONSOLE +#ifdef _TOOLS #define TIMER_FORMAT "(%.3f) " #else #define TIMER_FORMAT "[%.3f] " -#endif // NETCONSOLE +#endif // _TOOLS const char* Plat_GetProcessUpTime() { diff --git a/r5dev/tier2/socketcreator.cpp b/r5dev/tier2/socketcreator.cpp index e731d5fd..dce477b7 100644 --- a/r5dev/tier2/socketcreator.cpp +++ b/r5dev/tier2/socketcreator.cpp @@ -6,9 +6,9 @@ #include #include -#ifndef NETCONSOLE +#ifndef _TOOLS #include -#endif // !NETCONSOLE +#endif // !_TOOLS #include //----------------------------------------------------------------------------- diff --git a/r5dev/windows/console.cpp b/r5dev/windows/console.cpp index 3dae895c..3bfb0f19 100644 --- a/r5dev/windows/console.cpp +++ b/r5dev/windows/console.cpp @@ -5,7 +5,7 @@ //=============================================================================// #include "core/stdafx.h" -#ifndef NETCONSOLE +#ifndef _TOOLS #include "core/init.h" #include "core/logdef.h" #include "tier0/frametask.h" @@ -13,7 +13,7 @@ #ifndef DEDICATED #include "windows/id3dx.h" #endif // !DEDICATED -#endif // !NETCONSOLE +#endif // !_TOOLS #include "windows/system.h" #include "windows/console.h" @@ -80,7 +80,7 @@ void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color) //----------------------------------------------------------------------------- void Console_Init(const bool bAnsiColor) { -#ifndef NETCONSOLE +#ifndef _TOOLS /////////////////////////////////////////////////////////////////////////// // Create the console window if (AllocConsole() == FALSE) @@ -107,7 +107,7 @@ void Console_Init(const bool bAnsiColor) { CloseHandle(hThread); } -#endif // !NETCONSOLE +#endif // !_TOOLS HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); DWORD dwMode = NULL; @@ -128,9 +128,9 @@ void Console_Init(const bool bAnsiColor) AnsiColors_Init(); } -#ifndef NETCONSOLE +#ifndef _TOOLS SetConsoleCtrlHandler(ConsoleHandlerRoutine, true); -#endif // !NETCONSOLE +#endif // !_TOOLS } //----------------------------------------------------------------------------- @@ -147,7 +147,7 @@ void Console_Shutdown() } } -#ifndef NETCONSOLE +#ifndef _TOOLS //############################################################################# // CONSOLE WORKER //############################################################################# @@ -169,4 +169,4 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID) } return NULL; } -#endif // !NETCONSOLE +#endif // !_TOOLS