From f0687f8203d71eaff715b3e1212c7027d2cee259 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Tue, 16 Nov 2021 16:56:13 +0000 Subject: [PATCH] Use correct enum over numbers for com_error --- src/Components/Modules/Dedicated.cpp | 2 +- src/Components/Modules/Dedicated.hpp | 2 +- src/Components/Modules/Logger.cpp | 8 ++++---- src/Components/Modules/Logger.hpp | 4 ++-- src/Components/Modules/Renderer.cpp | 2 +- src/Components/Modules/Script.cpp | 8 ++++---- src/Components/Modules/ZoneBuilder.cpp | 4 ++-- src/Game/Functions.hpp | 2 +- src/Game/Structs.hpp | 12 ++++++++++++ 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 7ff6330c..f99ce32f 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -96,7 +96,7 @@ namespace Components Game::SV_GameSendServerCommand(-1, 0, list.data()); } - void Dedicated::TimeWrapStub(int code, const char* message) + void Dedicated::TimeWrapStub(Game::errorParm_t code, const char* message) { static bool partyEnable; static std::string mapname; diff --git a/src/Components/Modules/Dedicated.hpp b/src/Components/Modules/Dedicated.hpp index 162e1a8f..f7210be2 100644 --- a/src/Components/Modules/Dedicated.hpp +++ b/src/Components/Modules/Dedicated.hpp @@ -25,6 +25,6 @@ namespace Components static void TransmitGuids(); - static void TimeWrapStub(int code, const char* message); + static void TimeWrapStub(Game::errorParm_t code, const char* message); }; } diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index 22ad6e09..10a38fc9 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -51,7 +51,7 @@ namespace Components } } - void Logger::ErrorPrint(int error, const std::string& message) + void Logger::ErrorPrint(Game::errorParm_t error, const std::string& message) { #ifdef DEBUG if (IsDebuggerPresent()) __debugbreak(); @@ -60,19 +60,19 @@ namespace Components return Game::Com_Error(error, "%s", message.data()); } - void Logger::Error(int error, const char* message, ...) + void Logger::Error(Game::errorParm_t error, const char* message, ...) { return Logger::ErrorPrint(error, Logger::Format(&message)); } void Logger::Error(const char* message, ...) { - return Logger::ErrorPrint(0, Logger::Format(&message)); + return Logger::ErrorPrint(Game::ERR_FATAL, Logger::Format(&message)); } void Logger::SoftError(const char* message, ...) { - return Logger::ErrorPrint(2, Logger::Format(&message)); + return Logger::ErrorPrint(Game::ERR_SERVERDISCONNECT, Logger::Format(&message)); } std::string Logger::Format(const char** message) diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index 26625324..a6799b96 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -11,9 +11,9 @@ namespace Components static void MessagePrint(int channel, const std::string& message); static void Print(int channel, const char* message, ...); static void Print(const char* message, ...); - static void ErrorPrint(int error, const std::string& message); + static void ErrorPrint(Game::errorParm_t error, const std::string& message); static void Error(const char* message, ...); - static void Error(int error, const char* message, ...); + static void Error(Game::errorParm_t error, const char* message, ...); static void SoftError(const char* message, ...); static bool IsConsoleReady(); diff --git a/src/Components/Modules/Renderer.cpp b/src/Components/Modules/Renderer.cpp index 2422fde2..984474b0 100644 --- a/src/Components/Modules/Renderer.cpp +++ b/src/Components/Modules/Renderer.cpp @@ -108,7 +108,7 @@ namespace Components void Renderer::R_TextureFromCodeError(const char* sampler, Game::GfxCmdBufState* state) { - Game::Com_Error(0, "Tried to use sampler '%s' when it isn't valid for material '%s' and technique '%s'", + Game::Com_Error(Game::ERR_FATAL, "Tried to use sampler '%s' when it isn't valid for material '%s' and technique '%s'", sampler, state->material->info.name, state->technique->name); } diff --git a/src/Components/Modules/Script.cpp b/src/Components/Modules/Script.cpp index 72995ce6..354b9465 100644 --- a/src/Components/Modules/Script.cpp +++ b/src/Components/Modules/Script.cpp @@ -24,7 +24,7 @@ namespace Components Logger::Print(23, "Error: unknown function %s in %s\n", funcName.data(), Script::ScriptName.data()); Logger::Print(23, "************************************\n"); - Logger::Error(5, "script compile error\nunknown function %s\n%s\n\n", funcName.data(), Script::ScriptName.data()); + Logger::Error(Game::ERR_SCRIPT_DROP, "script compile error\nunknown function %s\n%s\n\n", funcName.data(), Script::ScriptName.data()); } __declspec(naked) void Script::StoreFunctionNameStub() @@ -168,7 +168,7 @@ namespace Components Script::PrintSourcePos(Script::ScriptName.data(), offset); Logger::Print(23, "************************************\n\n"); - Logger::Error(5, "script compile error\n%s\n%s\n(see console for actual details)\n", msgbuf, Script::ScriptName.data()); + Logger::Error(Game::ERR_SCRIPT_DROP, "script compile error\n%s\n%s\n(see console for actual details)\n", msgbuf, Script::ScriptName.data()); } int Script::LoadScriptAndLabel(const std::string& script, const std::string& label) @@ -178,7 +178,7 @@ namespace Components if (!Game::Scr_LoadScript(script.data())) { Logger::Print("Script %s encountered an error while loading. (doesn't exist?)", script.data()); - Logger::Error(1, reinterpret_cast(0x70B810), script.data()); + Logger::Error(Game::ERR_DROP, reinterpret_cast(0x70B810), script.data()); } else { @@ -407,7 +407,7 @@ namespace Components { if (!gentity->client) { - Logger::Error(5, "Entity: %i is not a client", gentity); + Logger::Error(Game::ERR_SCRIPT_DROP, "Entity: %i is not a client", gentity); } return &Game::svs_clients[gentity->s.number]; } diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index efff6316..f8f45fc4 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -851,7 +851,7 @@ namespace Components Command::Add("error", [](Command::Params*) { - Game::Com_Error(0, "This is a test %s\n", "error"); + Game::Com_Error(Game::ERR_FATAL, "This is a test %s\n", "error"); }); // now load default assets and shaders @@ -1412,7 +1412,7 @@ namespace Components // build final techsets fastfile if (subCount > 24) { - Logger::ErrorPrint(1, "How did you have 576 fastfiles?\n"); + Logger::ErrorPrint(Game::ERR_DROP, "How did you have 576 fastfiles?\n"); } curTechsets_list.clear(); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 2569dbcf..e98103c4 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -121,7 +121,7 @@ namespace Game typedef void(__cdecl * Com_ClientPacketEvent_t)(); extern Com_ClientPacketEvent_t Com_ClientPacketEvent; - typedef void(__cdecl * Com_Error_t)(int type, const char* message, ...); + typedef void(__cdecl * Com_Error_t)(errorParm_t type, const char* message, ...); extern Com_Error_t Com_Error; typedef void(__cdecl * Com_Printf_t)(int channel, const char *fmt, ...); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 2d8b443c..63d4ce72 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -177,6 +177,18 @@ namespace Game CS_ACTIVE = 0x5, } clientstate_t; + typedef enum + { + ERR_FATAL = 0x0, + ERR_DROP = 0x1, + ERR_SERVERDISCONNECT = 0x2, + ERR_DISCONNECT = 0x3, + ERR_SCRIPT = 0x4, + ERR_SCRIPT_DROP = 0x5, + ERR_LOCALIZATION = 0x6, + ERR_MAPLOADERRORSUMMARY = 0x7 + } errorParm_t; + struct FxEffectDef; struct pathnode_t; struct pathnode_tree_t;