From a200d82ae67ea210255089cde6ccc2dbb0b556b9 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sat, 2 Jul 2022 19:52:57 +0200 Subject: [PATCH] [Dvar] Better dvar settings for debugging --- src/Components/Modules/Auth.cpp | 2 +- src/Components/Modules/Branding.cpp | 8 +-- src/Components/Modules/Bullet.cpp | 4 +- src/Components/Modules/CardTitles.cpp | 2 +- src/Components/Modules/Chat.cpp | 2 +- src/Components/Modules/Clantags.cpp | 2 +- src/Components/Modules/D3D9Ex.cpp | 2 +- src/Components/Modules/Debug.cpp | 2 +- src/Components/Modules/Dedicated.cpp | 10 ++-- src/Components/Modules/Discovery.cpp | 4 +- src/Components/Modules/Download.cpp | 12 ++--- src/Components/Modules/Dvar.cpp | 68 ++++++++++++++++++------- src/Components/Modules/Dvar.hpp | 9 ++-- src/Components/Modules/FastFiles.cpp | 2 +- src/Components/Modules/Localization.cpp | 2 +- src/Components/Modules/Logger.cpp | 2 +- src/Components/Modules/MapRotation.cpp | 4 +- src/Components/Modules/ModList.cpp | 2 +- src/Components/Modules/Party.cpp | 20 ++++---- src/Components/Modules/Party.hpp | 2 +- src/Components/Modules/PlayerName.cpp | 2 +- src/Components/Modules/QuickPatch.cpp | 4 +- src/Components/Modules/RCon.cpp | 4 +- src/Components/Modules/RawMouse.cpp | 2 +- src/Components/Modules/ServerList.cpp | 12 ++--- src/Components/Modules/TextRenderer.cpp | 14 ++--- src/Components/Modules/Theatre.cpp | 4 +- src/Components/Modules/UIFeeder.cpp | 6 +-- src/Components/Modules/Window.cpp | 4 +- src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 3 ++ src/Game/Structs.hpp | 2 +- 32 files changed, 129 insertions(+), 90 deletions(-) diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 0cbdbce6..01f87c59 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -432,7 +432,7 @@ namespace Components Scheduler::Loop(Auth::Frame, Scheduler::Pipeline::MAIN); // Register dvar - Dvar::Register("sv_securityLevel", 23, 0, 512, Game::dvar_flag::DVAR_SERVERINFO, "Security level for GUID certificates (POW)"); + Dvar::Register("sv_securityLevel", 23, 0, 512, Game::DVAR_SERVERINFO, "Security level for GUID certificates (POW)"); // Install registration hook Utils::Hook(0x6265F9, Auth::DirectConnectStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/Branding.cpp b/src/Components/Modules/Branding.cpp index 0b2a0c34..e878e625 100644 --- a/src/Components/Modules/Branding.cpp +++ b/src/Components/Modules/Branding.cpp @@ -75,7 +75,7 @@ namespace Components [[maybe_unused]] float y, float min, float max, [[maybe_unused]] int flags, const char* description) { return Game::Dvar_RegisterVec2(dvarName, -60.0f, - 474.0f, min, max, Game::dvar_flag::DVAR_ROM, description); + 474.0f, min, max, Game::DVAR_ROM, description); } void Branding::RegisterBrandingDvars() @@ -86,11 +86,11 @@ namespace Components constexpr auto value = false; #endif Branding::CGDrawVersion = Dvar::Register("cg_drawVersion", value, - Game::dvar_flag::DVAR_NONE, "Draw the game version"); + Game::DVAR_NONE, "Draw the game version"); Branding::CGDrawVersionX = Dvar::Register("cg_drawVersionX", 10.0f, - 0.0f, 512.0f, Game::dvar_flag::DVAR_NONE, "X offset for the version string"); + 0.0f, 512.0f, Game::DVAR_NONE, "X offset for the version string"); Branding::CGDrawVersionY = Dvar::Register("cg_drawVersionY", 455.0f, - 0.0f, 512.0f, Game::dvar_flag::DVAR_NONE, "Y offset for the version string"); + 0.0f, 512.0f, Game::DVAR_NONE, "Y offset for the version string"); } Branding::Branding() diff --git a/src/Components/Modules/Bullet.cpp b/src/Components/Modules/Bullet.cpp index b8ec1338..fe18981a 100644 --- a/src/Components/Modules/Bullet.cpp +++ b/src/Components/Modules/Bullet.cpp @@ -45,10 +45,10 @@ namespace Components Bullet::Bullet() { BGSurfacePenetration = Dvar::Register("bg_surfacePenetration", 0.0f, - 0.0f, std::numeric_limits::max(), Game::dvar_flag::DVAR_CODINFO, + 0.0f, std::numeric_limits::max(), Game::DVAR_CODINFO, "Set to a value greater than 0 to override the surface penetration depth"); BGBulletRange = Game::Dvar_RegisterFloat("bg_bulletRange", 8192.0f, - 0.0f, std::numeric_limits::max(), Game::dvar_flag::DVAR_CODINFO, + 0.0f, std::numeric_limits::max(), Game::DVAR_CODINFO, "Max range used when calculating the bullet end position"); Utils::Hook(0x4F6980, BG_GetSurfacePenetrationDepthStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index c5eae749..78e7a2f9 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -192,7 +192,7 @@ namespace Components { Scheduler::Once([] { - CardTitles::CustomTitleDvar = Dvar::Register("customtitle", "", Game::dvar_flag::DVAR_USERINFO | Game::dvar_flag::DVAR_ARCHIVE, "Custom card title"); + CardTitles::CustomTitleDvar = Dvar::Register("customtitle", "", Game::DVAR_USERINFO | Game::DVAR_ARCHIVE, "Custom card title"); }, Scheduler::Pipeline::MAIN); ServerCommands::OnCommand(21, [](Command::Params* params) diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index ead9e87b..2e66a925 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -410,7 +410,7 @@ namespace Components Chat::Chat() { cg_chatWidth = Dvar::Register("cg_chatWidth", 52, 1, std::numeric_limits::max(), Game::DVAR_ARCHIVE, "The normalized maximum width of a chat message"); - sv_disableChat = Dvar::Register("sv_disableChat", false, Game::dvar_flag::DVAR_NONE, "Disable chat messages from clients"); + sv_disableChat = Dvar::Register("sv_disableChat", false, Game::DVAR_NONE, "Disable chat messages from clients"); Events::OnSVInit(AddChatCommands); // Intercept chat sending diff --git a/src/Components/Modules/Clantags.cpp b/src/Components/Modules/Clantags.cpp index c137ef97..eac6a916 100644 --- a/src/Components/Modules/Clantags.cpp +++ b/src/Components/Modules/Clantags.cpp @@ -75,7 +75,7 @@ namespace Components // Create clantag dvar Scheduler::Once([] { - Dvar::Register("clantag", "", Game::dvar_flag::DVAR_USERINFO | Game::dvar_flag::DVAR_ARCHIVE, + Dvar::Register("clantag", "", Game::DVAR_USERINFO | Game::DVAR_ARCHIVE, "If set, your clantag will be shown on the scoreboard."); }, Scheduler::Pipeline::MAIN); diff --git a/src/Components/Modules/D3D9Ex.cpp b/src/Components/Modules/D3D9Ex.cpp index f6b84844..6903e23a 100644 --- a/src/Components/Modules/D3D9Ex.cpp +++ b/src/Components/Modules/D3D9Ex.cpp @@ -748,7 +748,7 @@ namespace Components { if (Dedicated::IsEnabled()) return; - Dvar::Register("r_useD3D9Ex", false, Game::dvar_flag::DVAR_ARCHIVE, "Use extended d3d9 interface!"); + Dvar::Register("r_useD3D9Ex", false, Game::DVAR_ARCHIVE, "Use extended d3d9 interface!"); // Hook Interface creation Utils::Hook::Set(0x6D74D0, D3D9Ex::Direct3DCreate9Stub); diff --git a/src/Components/Modules/Debug.cpp b/src/Components/Modules/Debug.cpp index 25032d40..2821d58c 100644 --- a/src/Components/Modules/Debug.cpp +++ b/src/Components/Modules/Debug.cpp @@ -227,7 +227,7 @@ namespace Components }; DebugOverlay = Game::Dvar_RegisterEnum("debugOverlay", debugOverlayNames_0, 0, - Game::dvar_flag::DVAR_NONE, "Toggles the display of various debug info."); + Game::DVAR_NONE, "Toggles the display of various debug info."); } Debug::Debug() diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 22f49aef..5e475633 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -135,7 +135,7 @@ namespace Components Game::dvar_t* Dedicated::Dvar_RegisterSVNetworkFps(const char* dvarName, int, int min, int, int, const char* description) { - return Game::Dvar_RegisterInt(dvarName, 1000, min, 1000, Game::dvar_flag::DVAR_NONE, description); + return Game::Dvar_RegisterInt(dvarName, 1000, min, 1000, Game::DVAR_NONE, description); } void Dedicated::AddDedicatedCommands() @@ -206,7 +206,7 @@ namespace Components Dedicated::Dedicated() { Dedicated::COMLogFilter = Dvar::Register("com_logFilter", true, - Game::dvar_flag::DVAR_LATCH, "Removes ~95% of unneeded lines from the log"); + Game::DVAR_LATCH, "Removes ~95% of unneeded lines from the log"); if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) { @@ -214,7 +214,7 @@ namespace Components Scheduler::Loop(Steam::SteamAPI_RunCallbacks, Scheduler::Pipeline::SERVER); Dedicated::SVLanOnly = Dvar::Register("sv_lanOnly", false, - Game::dvar_flag::DVAR_NONE, "Don't act as node"); + Game::DVAR_NONE, "Don't act as node"); Utils::Hook(0x60BE98, Dedicated::InitDedicatedServer, HOOK_CALL).install()->quick(); @@ -281,8 +281,8 @@ namespace Components { Scheduler::Once([] { - Dvar::Register("sv_sayName", "^7Console", Game::dvar_flag::DVAR_NONE, "The name to pose as for 'say' commands"); - Dvar::Register("sv_motd", "", Game::dvar_flag::DVAR_NONE, "A custom message of the day for servers"); + Dvar::Register("sv_sayName", "^7Console", Game::DVAR_NONE, "The name to pose as for 'say' commands"); + Dvar::Register("sv_motd", "", Game::DVAR_NONE, "A custom message of the day for servers"); }, Scheduler::Pipeline::MAIN); Events::OnSVInit(Dedicated::AddDedicatedCommands); diff --git a/src/Components/Modules/Discovery.cpp b/src/Components/Modules/Discovery.cpp index a97502ea..7c4c243d 100644 --- a/src/Components/Modules/Discovery.cpp +++ b/src/Components/Modules/Discovery.cpp @@ -14,8 +14,8 @@ namespace Components Discovery::Discovery() { - Dvar::Register("net_discoveryPortRangeMin", 25000, 0, 65535, Game::dvar_flag::DVAR_ARCHIVE, "Minimum scan range port for local server discovery"); - Dvar::Register("net_discoveryPortRangeMax", 35000, 1, 65536, Game::dvar_flag::DVAR_ARCHIVE, "Maximum scan range port for local server discovery"); + Dvar::Register("net_discoveryPortRangeMin", 25000, 0, 65535, Game::DVAR_ARCHIVE, "Minimum scan range port for local server discovery"); + Dvar::Register("net_discoveryPortRangeMax", 35000, 1, 65536, Game::DVAR_ARCHIVE, "Maximum scan range port for local server discovery"); // An additional thread prevents lags // Not sure if that's the best way though diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index 6cda7c4c..d75b90f4 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -903,9 +903,9 @@ namespace Components { Scheduler::Once([] { - Dvar::Register("ui_dl_timeLeft", "", Game::dvar_flag::DVAR_NONE, ""); - Dvar::Register("ui_dl_progress", "", Game::dvar_flag::DVAR_NONE, ""); - Dvar::Register("ui_dl_transRate", "", Game::dvar_flag::DVAR_NONE, ""); + Dvar::Register("ui_dl_timeLeft", "", Game::DVAR_NONE, ""); + Dvar::Register("ui_dl_progress", "", Game::DVAR_NONE, ""); + Dvar::Register("ui_dl_transRate", "", Game::DVAR_NONE, ""); }, Scheduler::Pipeline::MAIN); UIScript::Add("mod_download_cancel", [](UIScript::Token) @@ -916,13 +916,13 @@ namespace Components Scheduler::Once([] { - Dvar::Register("sv_wwwDownload", false, Game::dvar_flag::DVAR_ARCHIVE, "Set to true to enable downloading maps/mods from an external server."); - Dvar::Register("sv_wwwBaseUrl", "", Game::dvar_flag::DVAR_ARCHIVE, "Set to the base url for the external map download."); + Dvar::Register("sv_wwwDownload", false, Game::DVAR_ARCHIVE, "Set to true to enable downloading maps/mods from an external server."); + Dvar::Register("sv_wwwBaseUrl", "", Game::DVAR_ARCHIVE, "Set to the base url for the external map download."); // Force users to enable this because we don't want to accidentally turn everyone's pc into a http server into all their files again // not saying we are but ya know... accidents happen // by having it saved we force the user to enable it in config_mp because it only checks the dvar on startup to see if we should init download or not - Dvar::Register("mod_force_download_server", false, Game::dvar_flag::DVAR_ARCHIVE, "Set to true to force the client to run the download server for mods (for mods in private matches)."); + Dvar::Register("mod_force_download_server", false, Game::DVAR_ARCHIVE, "Set to true to force the client to run the download server for mods (for mods in private matches)."); }, Scheduler::Pipeline::MAIN); Scheduler::Loop([] diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index 5a8fb845..4334dd59 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -52,14 +52,14 @@ namespace Components template <> unsigned int Dvar::Var::get() { if (this->dvar == nullptr) - return 0u; + return 0; if (this->dvar->type == Game::dvar_type::DVAR_TYPE_INT) { return this->dvar->current.unsignedInt; } - return 0u; + return 0; } template <> float Dvar::Var::get() @@ -77,7 +77,7 @@ namespace Components template <> float* Dvar::Var::get() { - static Game::vec4_t vector{ 0.f, 0.f, 0.f, 0.f }; + static Game::vec4_t vector{0.f, 0.f, 0.f, 0.f}; if (this->dvar == nullptr) return vector; @@ -249,7 +249,7 @@ namespace Components } } - return Dvar::Register(name, username.data(), flags | Game::dvar_flag::DVAR_ARCHIVE, description).get(); + return Dvar::Register(name, username.data(), flags | Game::DVAR_ARCHIVE, description).get(); } void Dvar::SetFromStringByNameSafeExternal(const char* dvarName, const char* string) @@ -311,7 +311,7 @@ namespace Components { // Save the dvar original value if it has the archive flag const auto* dvar = Game::Dvar_FindVar(dvarName); - if (dvar != nullptr && dvar->flags & Game::dvar_flag::DVAR_ARCHIVE) + if (dvar != nullptr && dvar->flags & Game::DVAR_ARCHIVE) { if (Dvar::AreArchiveDvarsProtected()) { @@ -328,28 +328,56 @@ namespace Components Utils::Hook::Call(0x4F52E0)(dvarName, value); } + void Dvar::OnRegisterVariant([[maybe_unused]] Game::dvar_t* dvar) + { +#ifdef _DEBUG + dvar->flags &= ~Game::DVAR_CHEAT; +#endif + } + + __declspec(naked) void Dvar::Dvar_RegisterVariant_Stub() + { + __asm + { + pushad + + push eax + call Dvar::OnRegisterVariant + add esp, 0x4 + + popad + + // Game's code + pop edi + pop esi + pop ebp + pop ebx + ret + } + } + Dvar::Dvar() { // set flags of cg_drawFPS to archive - Utils::Hook::Or(0x4F8F69, Game::dvar_flag::DVAR_ARCHIVE); + Utils::Hook::Or(0x4F8F69, Game::DVAR_ARCHIVE); // un-cheat camera_thirdPersonCrosshairOffset and add archive flags - Utils::Hook::Xor(0x447B41, Game::dvar_flag::DVAR_CHEAT | Game::dvar_flag::DVAR_ARCHIVE); + Utils::Hook::Xor(0x447B41, Game::DVAR_CHEAT | Game::DVAR_ARCHIVE); // un-cheat cg_fov and add archive flags - Utils::Hook::Xor(0x4F8E35, Game::dvar_flag::DVAR_CHEAT | Game::dvar_flag::DVAR_ARCHIVE); + Utils::Hook::Xor(0x4F8E35, Game::DVAR_CHEAT | Game::DVAR_ARCHIVE); // un-cheat cg_fovscale and add archive flags - Utils::Hook::Xor(0x4F8E68, Game::dvar_flag::DVAR_CHEAT | Game::dvar_flag::DVAR_ARCHIVE); + Utils::Hook::Xor(0x4F8E68, Game::DVAR_CHEAT | Game::DVAR_ARCHIVE); // un-cheat cg_debugInfoCornerOffset and add archive flags - Utils::Hook::Xor(0x4F8FC2, Game::dvar_flag::DVAR_CHEAT | Game::dvar_flag::DVAR_ARCHIVE); + Utils::Hook::Xor(0x4F8FC2, Game::DVAR_CHEAT | Game::DVAR_ARCHIVE); // remove archive flags for cg_hudchatposition - Utils::Hook::Xor(0x4F9992, Game::dvar_flag::DVAR_ARCHIVE); + Utils::Hook::Xor(0x4F9992, Game::DVAR_ARCHIVE); // remove write protection from fs_game - Utils::Hook::Xor(0x6431EA, Game::dvar_flag::DVAR_INIT); + Utils::Hook::Xor(0x6431EA, Game::DVAR_INIT); // set cg_fov max to 160.0 // because that's the max on SP @@ -361,19 +389,19 @@ namespace Components Utils::Hook::Set(0x408078, &volume); // Uncheat ui_showList - Utils::Hook::Xor(0x6310DC, Game::dvar_flag::DVAR_CHEAT); + Utils::Hook::Xor(0x6310DC, Game::DVAR_CHEAT); // Uncheat ui_debugMode - Utils::Hook::Xor(0x6312DE, Game::dvar_flag::DVAR_CHEAT); + Utils::Hook::Xor(0x6312DE, Game::DVAR_CHEAT); // Hook dvar 'name' registration Utils::Hook(0x40531C, Dvar::Dvar_RegisterName, HOOK_CALL).install()->quick(); // un-cheat safeArea_* and add archive flags - Utils::Hook::Xor(0x42E3F5, Game::dvar_flag::DVAR_ROM | Game::dvar_flag::DVAR_ARCHIVE); //safeArea_adjusted_horizontal - Utils::Hook::Xor(0x42E423, Game::dvar_flag::DVAR_ROM | Game::dvar_flag::DVAR_ARCHIVE); //safeArea_adjusted_vertical - Utils::Hook::Xor(0x42E398, Game::dvar_flag::DVAR_CHEAT | Game::dvar_flag::DVAR_ARCHIVE); //safeArea_horizontal - Utils::Hook::Xor(0x42E3C4, Game::dvar_flag::DVAR_CHEAT | Game::dvar_flag::DVAR_ARCHIVE); //safeArea_vertical + Utils::Hook::Xor(0x42E3F5, Game::DVAR_ROM | Game::DVAR_ARCHIVE); //safeArea_adjusted_horizontal + Utils::Hook::Xor(0x42E423, Game::DVAR_ROM | Game::DVAR_ARCHIVE); //safeArea_adjusted_vertical + Utils::Hook::Xor(0x42E398, Game::DVAR_CHEAT | Game::DVAR_ARCHIVE); //safeArea_horizontal + Utils::Hook::Xor(0x42E3C4, Game::DVAR_CHEAT | Game::DVAR_ARCHIVE); //safeArea_vertical // Don't allow setting cheat protected dvars via menus Utils::Hook(0x63C897, Dvar::SetFromStringByNameExternal, HOOK_CALL).install()->quick(); @@ -404,6 +432,10 @@ namespace Components // Reset archive dvars when client leaves a server Events::OnSteamDisconnect(Dvar::ResetDvarsValue); + + // For debugging + Utils::Hook(0x6483FA, Dvar::Dvar_RegisterVariant_Stub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x648438, Dvar::Dvar_RegisterVariant_Stub, HOOK_JUMP).install()->quick(); } Dvar::~Dvar() diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index fb51fbcb..b457f16b 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -8,10 +8,10 @@ namespace Components class Flag { public: - Flag(Game::dvar_flag flag) : val(flag) {} - Flag(unsigned __int16 flag) : Flag(static_cast(flag)) {} + Flag(Game::DvarFlags flag) : val(flag) {} + Flag(unsigned __int16 flag) : Flag(static_cast(flag)) {} - Game::dvar_flag val; + Game::DvarFlags val; }; class Var @@ -60,5 +60,8 @@ namespace Components static bool AreArchiveDvarsProtected(); static void SaveArchiveDvar(const Game::dvar_t* var); static void DvarSetFromStringByNameStub(const char* dvarName, const char* value); + + static void OnRegisterVariant(Game::dvar_t* dvar); + static void Dvar_RegisterVariant_Stub(); }; } diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index 5ac44386..fedb64d3 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -495,7 +495,7 @@ namespace Components FastFiles::FastFiles() { - Dvar::Register("ui_zoneDebug", false, Game::dvar_flag::DVAR_ARCHIVE, "Display current loaded zone."); + Dvar::Register("ui_zoneDebug", false, Game::DVAR_ARCHIVE, "Display current loaded zone."); // Fix XSurface assets Utils::Hook(0x0048E8A5, FastFiles::Load_XSurfaceArray, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Localization.cpp b/src/Components/Modules/Localization.cpp index a3c87efb..8d43f8ea 100644 --- a/src/Components/Modules/Localization.cpp +++ b/src/Components/Modules/Localization.cpp @@ -277,7 +277,7 @@ namespace Components // Overwrite SetString Utils::Hook(0x4CE5EE, Localization::SetStringStub, HOOK_CALL).install()->quick(); - Localization::UseLocalization = Dvar::Register("ui_localize", true, Game::dvar_flag::DVAR_NONE, "Use localization strings"); + Localization::UseLocalization = Dvar::Register("ui_localize", true, Game::DVAR_NONE, "Use localization strings"); // Generate localized entries for custom classes above 10 AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* /*restrict*/) diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index c47efb6f..19f29235 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -364,7 +364,7 @@ namespace Components Logger::Logger() { - Dvar::Register("iw4x_onelog", false, Game::dvar_flag::DVAR_LATCH | Game::dvar_flag::DVAR_ARCHIVE, "Only write the game log to the 'userraw' OS folder"); + Dvar::Register("iw4x_onelog", false, Game::DVAR_LATCH | Game::DVAR_ARCHIVE, "Only write the game log to the 'userraw' OS folder"); Utils::Hook(0x642139, Logger::BuildOSPathStub, HOOK_JUMP).install()->quick(); Logger::PipeOutput(nullptr); diff --git a/src/Components/Modules/MapRotation.cpp b/src/Components/Modules/MapRotation.cpp index 8c6658c4..5f5210f1 100644 --- a/src/Components/Modules/MapRotation.cpp +++ b/src/Components/Modules/MapRotation.cpp @@ -306,9 +306,9 @@ namespace Components Utils::Hook::Set(0x4152E8, SV_MapRotate_f); SVRandomMapRotation = Dvar::Register("sv_randomMapRotation", false, - Game::dvar_flag::DVAR_ARCHIVE, "Randomize map rotation when true"); + Game::DVAR_ARCHIVE, "Randomize map rotation when true"); SVDontRotate = Dvar::Register("sv_dontRotate", false, - Game::dvar_flag::DVAR_NONE, "Do not perform map rotation"); + Game::DVAR_NONE, "Do not perform map rotation"); } bool MapRotation::unitTest() diff --git a/src/Components/Modules/ModList.cpp b/src/Components/Modules/ModList.cpp index 44b983ef..6d4db41b 100644 --- a/src/Components/Modules/ModList.cpp +++ b/src/Components/Modules/ModList.cpp @@ -93,7 +93,7 @@ namespace Components if (Dedicated::IsEnabled()) return; ModList::CurrentMod = 0; - Dvar::Register("cl_modVidRestart", true, Game::dvar_flag::DVAR_ARCHIVE, "Perform a vid_restart when loading a mod."); + Dvar::Register("cl_modVidRestart", true, Game::DVAR_ARCHIVE, "Perform a vid_restart when loading a mod."); UIScript::Add("LoadMods", ModList::UIScript_LoadMods); UIScript::Add("RunMod", ModList::UIScript_RunMod); diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 7f293e4f..4a0a5524 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -76,9 +76,9 @@ namespace Components return Party::Container.motd; } - Game::dvar_t* Party::RegisterMinPlayers(const char* name, int /*value*/, int /*min*/, int max, Game::dvar_flag flag, const char* description) + Game::dvar_t* Party::RegisterMinPlayers(const char* name, int /*value*/, int /*min*/, int max, Game::DvarFlags flag, const char* description) { - return Dvar::Register(name, 1, 1, max, Game::dvar_flag::DVAR_INIT | flag, description).get(); + return Dvar::Register(name, 1, 1, max, Game::DVAR_INIT | flag, description).get(); } bool Party::PlaylistAwaiting() @@ -154,8 +154,8 @@ namespace Components Party::Party() { - Party::PartyEnable = Dvar::Register("party_enable", Dedicated::IsEnabled(), Game::dvar_flag::DVAR_NONE, "Enable party system"); - Dvar::Register("xblive_privatematch", true, Game::dvar_flag::DVAR_INIT, ""); + Party::PartyEnable = Dvar::Register("party_enable", Dedicated::IsEnabled(), Game::DVAR_NONE, "Enable party system"); + Dvar::Register("xblive_privatematch", true, Game::DVAR_INIT, ""); // various changes to SV_DirectConnect-y stuff to allow non-party joinees Utils::Hook::Set(0x460D96, 0x90E9); @@ -254,12 +254,12 @@ namespace Components Utils::Hook::Set(0x5E3772, "sv_maxclients"); // Unlatch maxclient dvars - Utils::Hook::Xor(0x426187, Game::dvar_flag::DVAR_LATCH); - Utils::Hook::Xor(0x4D374E, Game::dvar_flag::DVAR_LATCH); - Utils::Hook::Xor(0x5E376A, Game::dvar_flag::DVAR_LATCH); - Utils::Hook::Xor(0x4261A1, Game::dvar_flag::DVAR_LATCH); - Utils::Hook::Xor(0x4D376D, Game::dvar_flag::DVAR_LATCH); - Utils::Hook::Xor(0x5E3789, Game::dvar_flag::DVAR_LATCH); + Utils::Hook::Xor(0x426187, Game::DVAR_LATCH); + Utils::Hook::Xor(0x4D374E, Game::DVAR_LATCH); + Utils::Hook::Xor(0x5E376A, Game::DVAR_LATCH); + Utils::Hook::Xor(0x4261A1, Game::DVAR_LATCH); + Utils::Hook::Xor(0x4D376D, Game::DVAR_LATCH); + Utils::Hook::Xor(0x5E3789, Game::DVAR_LATCH); // Patch Live_PlayerHasLoopbackAddr //Utils::Hook::Set(0x418F30, 0x90C3C033); diff --git a/src/Components/Modules/Party.hpp b/src/Components/Modules/Party.hpp index f1d32b09..dada08a8 100644 --- a/src/Components/Modules/Party.hpp +++ b/src/Components/Modules/Party.hpp @@ -50,7 +50,7 @@ namespace Components static SteamID GenerateLobbyId(); - static Game::dvar_t* RegisterMinPlayers(const char* name, int value, int min, int max, Game::dvar_flag flag, const char* description); + static Game::dvar_t* RegisterMinPlayers(const char* name, int value, int min, int max, Game::DvarFlags flag, const char* description); static DWORD UIDvarIntStub(char* dvar); }; diff --git a/src/Components/Modules/PlayerName.cpp b/src/Components/Modules/PlayerName.cpp index 5f29acc0..3233c279 100644 --- a/src/Components/Modules/PlayerName.cpp +++ b/src/Components/Modules/PlayerName.cpp @@ -106,7 +106,7 @@ namespace Components PlayerName::PlayerName() { - sv_allowColoredNames = Dvar::Register("sv_allowColoredNames", true, Game::dvar_flag::DVAR_NONE, "Allow colored names on the server"); + sv_allowColoredNames = Dvar::Register("sv_allowColoredNames", true, Game::DVAR_NONE, "Allow colored names on the server"); // Disable SV_UpdateUserinfo_f, to block changing the name ingame Utils::Hook::Set(0x6258D0, 0xC3); diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 5efa88a4..7e987eb4 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -248,7 +248,7 @@ namespace Components Utils::Hook(0x4F66A3, CL_KeyEvent_ConsoleEscape_Stub, HOOK_JUMP).install()->quick(); // Intermission time dvar - Game::Dvar_RegisterFloat("scr_intermissionTime", 10, 0, 120, Game::dvar_flag::DVAR_NONE, "Time in seconds before match server loads the next map"); + Game::Dvar_RegisterFloat("scr_intermissionTime", 10, 0, 120, Game::DVAR_NONE, "Time in seconds before match server loads the next map"); g_antilag = Game::Dvar_RegisterBool("g_antilag", true, Game::DVAR_CODINFO, "Perform antilag"); Utils::Hook(0x5D6D56, QuickPatch::ClientEventsFireWeaponStub, HOOK_JUMP).install()->quick(); @@ -328,7 +328,7 @@ namespace Components // Numerical ping (cg_scoreboardPingText 1) Utils::Hook::Set(0x45888E, 1); - Utils::Hook::Set(0x45888C, Game::dvar_flag::DVAR_CHEAT); + Utils::Hook::Set(0x45888C, Game::DVAR_CHEAT); // increase font sizes for chat on higher resolutions static float float13 = 13.0f; diff --git a/src/Components/Modules/RCon.cpp b/src/Components/Modules/RCon.cpp index 894065be..5a16e35d 100644 --- a/src/Components/Modules/RCon.cpp +++ b/src/Components/Modules/RCon.cpp @@ -78,8 +78,8 @@ namespace Components Scheduler::Once([] { - RCon::RconPassword = Dvar::Register("rcon_password", "", Game::dvar_flag::DVAR_NONE, "The password for rcon"); - RCon::RconLogRequests = Dvar::Register("rcon_log_requests", false, Game::dvar_flag::DVAR_NONE, "Print remote commands in the output log"); + RCon::RconPassword = Dvar::Register("rcon_password", "", Game::DVAR_NONE, "The password for rcon"); + RCon::RconLogRequests = Dvar::Register("rcon_log_requests", false, Game::DVAR_NONE, "Print remote commands in the output log"); }, Scheduler::Pipeline::MAIN); Network::OnPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data) diff --git a/src/Components/Modules/RawMouse.cpp b/src/Components/Modules/RawMouse.cpp index dfd8575a..f48d8f33 100644 --- a/src/Components/Modules/RawMouse.cpp +++ b/src/Components/Modules/RawMouse.cpp @@ -149,7 +149,7 @@ namespace Components Utils::Hook(0x467C03, RawMouse::IN_Init, HOOK_CALL).install()->quick(); Utils::Hook(0x64D095, RawMouse::IN_Init, HOOK_JUMP).install()->quick(); - RawMouse::M_RawInput = Dvar::Register("m_rawinput", true, Game::dvar_flag::DVAR_ARCHIVE, "Use raw mouse input, Improves accuracy & has better support for higher polling rates. Use in_restart to take effect if not enabled."); + RawMouse::M_RawInput = Dvar::Register("m_rawinput", true, Game::DVAR_ARCHIVE, "Use raw mouse input, Improves accuracy & has better support for higher polling rates. Use in_restart to take effect if not enabled."); Window::OnWndMessage(WM_INPUT, RawMouse::OnRawInput); Window::OnCreate(RawMouse::IN_RawMouse_Init); diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 691f64e1..6397fd52 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -779,14 +779,14 @@ namespace Components Scheduler::Once([] { ServerList::UIServerSelected = Dvar::Register("ui_serverSelected", false, - Game::dvar_flag::DVAR_NONE, "Whether a server has been selected in the serverlist"); + Game::DVAR_NONE, "Whether a server has been selected in the serverlist"); ServerList::UIServerSelectedMap = Dvar::Register("ui_serverSelectedMap", "mp_afghan", - Game::dvar_flag::DVAR_NONE, "Map of the selected server"); + Game::DVAR_NONE, "Map of the selected server"); ServerList::NETServerQueryLimit = Dvar::Register("net_serverQueryLimit", 1, - 1, 10, Dedicated::IsEnabled() ? Game::dvar_flag::DVAR_NONE : Game::dvar_flag::DVAR_ARCHIVE, "Amount of server queries per frame"); + 1, 10, Dedicated::IsEnabled() ? Game::DVAR_NONE : Game::DVAR_ARCHIVE, "Amount of server queries per frame"); ServerList::NETServerFrames = Dvar::Register("net_serverFrames", 30, - 1, 60, Dedicated::IsEnabled() ? Game::dvar_flag::DVAR_NONE : Game::dvar_flag::DVAR_ARCHIVE, "Amount of server query frames per second"); + 1, 60, Dedicated::IsEnabled() ? Game::DVAR_NONE : Game::DVAR_ARCHIVE, "Amount of server query frames per second"); }, Scheduler::Pipeline::MAIN); // Fix ui_netsource dvar @@ -829,8 +829,8 @@ namespace Components // Set default masterServerName + port and save it Utils::Hook::Set(0x60AD92, "master.xlabs.dev"); - Utils::Hook::Set(0x60AD90, Game::dvar_flag::DVAR_NONE); // masterServerName - Utils::Hook::Set(0x60ADC6, Game::dvar_flag::DVAR_NONE); // masterPort + Utils::Hook::Set(0x60AD90, Game::DVAR_NONE); // masterServerName + Utils::Hook::Set(0x60ADC6, Game::DVAR_NONE); // masterPort // Add server list feeder UIFeeder::Add(2.0f, ServerList::GetServerCount, ServerList::GetServerText, ServerList::SelectServer); diff --git a/src/Components/Modules/TextRenderer.cpp b/src/Components/Modules/TextRenderer.cpp index 780912ff..0fb0a268 100644 --- a/src/Components/Modules/TextRenderer.cpp +++ b/src/Components/Modules/TextRenderer.cpp @@ -1599,10 +1599,10 @@ namespace Components { currentColorTable = &colorTableDefault; - cg_newColors = Dvar::Register("cg_newColors", true, Game::dvar_flag::DVAR_ARCHIVE, "Use Warfare 2 color code style."); - cg_fontIconAutocomplete = Dvar::Register("cg_fontIconAutocomplete", true, Game::dvar_flag::DVAR_ARCHIVE, "Show autocomplete for fonticons when typing."); - cg_fontIconAutocompleteHint = Dvar::Register("cg_fontIconAutocompleteHint", true, Game::dvar_flag::DVAR_ARCHIVE, "Show hint text in autocomplete for fonticons."); - sv_customTextColor = Game::Dvar_RegisterColor("sv_customTextColor", 1, 0.7f, 0, 1, Game::dvar_flag::DVAR_CODINFO, "Color for the extended color code."); + cg_newColors = Dvar::Register("cg_newColors", true, Game::DVAR_ARCHIVE, "Use Warfare 2 color code style."); + cg_fontIconAutocomplete = Dvar::Register("cg_fontIconAutocomplete", true, Game::DVAR_ARCHIVE, "Show autocomplete for fonticons when typing."); + cg_fontIconAutocompleteHint = Dvar::Register("cg_fontIconAutocompleteHint", true, Game::DVAR_ARCHIVE, "Show hint text in autocomplete for fonticons."); + sv_customTextColor = Game::Dvar_RegisterColor("sv_customTextColor", 1, 0.7f, 0, 1, Game::DVAR_CODINFO, "Color for the extended color code."); // Initialize font icons when initializing UI Utils::Hook(0x4B5422, UI_Init_Hk, HOOK_CALL).install()->quick(); @@ -1617,11 +1617,11 @@ namespace Components Utils::Hook(0x417770, ColorIndex, HOOK_JUMP).install()->quick(); // Add a colorblind mode for team colors - r_colorBlind = Dvar::Register("r_colorBlind", false, Game::dvar_flag::DVAR_ARCHIVE, "Use color-blindness-friendly colors"); + r_colorBlind = Dvar::Register("r_colorBlind", false, Game::DVAR_ARCHIVE, "Use color-blindness-friendly colors"); // A dark red - g_ColorBlind_EnemyTeam = Game::Dvar_RegisterColor("g_ColorBlind_EnemyTeam", 0.659f, 0.088f, 0.145f, 1, Game::dvar_flag::DVAR_ARCHIVE, "Enemy team color for colorblind mode"); + g_ColorBlind_EnemyTeam = Game::Dvar_RegisterColor("g_ColorBlind_EnemyTeam", 0.659f, 0.088f, 0.145f, 1, Game::DVAR_ARCHIVE, "Enemy team color for colorblind mode"); // A bright yellow - g_ColorBlind_MyTeam = Game::Dvar_RegisterColor("g_ColorBlind_MyTeam", 1, 0.859f, 0.125f, 1, Game::dvar_flag::DVAR_ARCHIVE, "Ally team color for colorblind mode"); + g_ColorBlind_MyTeam = Game::Dvar_RegisterColor("g_ColorBlind_MyTeam", 1, 0.859f, 0.125f, 1, Game::DVAR_ARCHIVE, "Ally team color for colorblind mode"); // Replace team colors with colorblind team colors when colorblind is enabled Utils::Hook(0x406530, GetUnpackedColorByNameStub, HOOK_JUMP).install()->quick(); diff --git a/src/Components/Modules/Theatre.cpp b/src/Components/Modules/Theatre.cpp index 855a54e9..46285135 100644 --- a/src/Components/Modules/Theatre.cpp +++ b/src/Components/Modules/Theatre.cpp @@ -342,8 +342,8 @@ namespace Components Theatre::Theatre() { - Dvar::Register("cl_autoRecord", true, Game::dvar_flag::DVAR_ARCHIVE, "Automatically record games."); - Dvar::Register("cl_demosKeep", 30, 1, 999, Game::dvar_flag::DVAR_ARCHIVE, "How many demos to keep with autorecord."); + Dvar::Register("cl_autoRecord", true, Game::DVAR_ARCHIVE, "Automatically record games."); + Dvar::Register("cl_demosKeep", 30, 1, 999, Game::DVAR_ARCHIVE, "How many demos to keep with autorecord."); Utils::Hook(0x5A8370, Theatre::GamestateWriteStub, HOOK_CALL).install()->quick(); Utils::Hook(0x5A85D2, Theatre::RecordGamestateStub, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/UIFeeder.cpp b/src/Components/Modules/UIFeeder.cpp index 292428da..cefc0400 100644 --- a/src/Components/Modules/UIFeeder.cpp +++ b/src/Components/Modules/UIFeeder.cpp @@ -383,9 +383,9 @@ namespace Components Scheduler::Once([] { - Dvar::Register("ui_map_long", "Afghan", Game::dvar_flag::DVAR_NONE, ""); - Dvar::Register("ui_map_name", "mp_afghan", Game::dvar_flag::DVAR_NONE, ""); - Dvar::Register("ui_map_desc", "", Game::dvar_flag::DVAR_NONE, ""); + Dvar::Register("ui_map_long", "Afghan", Game::DVAR_NONE, ""); + Dvar::Register("ui_map_name", "mp_afghan", Game::DVAR_NONE, ""); + Dvar::Register("ui_map_desc", "", Game::DVAR_NONE, ""); }, Scheduler::Pipeline::MAIN); // Get feeder item count diff --git a/src/Components/Modules/Window.cpp b/src/Components/Modules/Window.cpp index e725d397..f044ea08 100644 --- a/src/Components/Modules/Window.cpp +++ b/src/Components/Modules/Window.cpp @@ -165,8 +165,8 @@ namespace Components Window::Window() { // Borderless window - Window::NoBorder = Dvar::Register("r_noborder", true, Game::dvar_flag::DVAR_ARCHIVE, "Do not use a border in windowed mode"); - Window::NativeCursor = Dvar::Register("ui_nativeCursor", false, Game::dvar_flag::DVAR_ARCHIVE, "Display native cursor"); + Window::NoBorder = Dvar::Register("r_noborder", true, Game::DVAR_ARCHIVE, "Do not use a border in windowed mode"); + Window::NativeCursor = Dvar::Register("ui_nativeCursor", false, Game::DVAR_ARCHIVE, "Display native cursor"); Utils::Hook(0x507643, Window::StyleHookStub, HOOK_CALL).install()->quick(); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 9bf202cf..84ebd2ce 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -124,6 +124,7 @@ namespace Game Dvar_RegisterEnum_t Dvar_RegisterEnum = Dvar_RegisterEnum_t(0x412E40); Dvar_RegisterString_t Dvar_RegisterString = Dvar_RegisterString_t(0x4FC7E0); Dvar_RegisterColor_t Dvar_RegisterColor = Dvar_RegisterColor_t(0x4F28E0); + Dvar_RegisterVec3Color_t Dvar_RegisterVec3Color = Dvar_RegisterVec3Color_t(0x4918B0); Dvar_GetUnpackedColorByName_t Dvar_GetUnpackedColorByName = Dvar_GetUnpackedColorByName_t(0x406530); Dvar_FindVar_t Dvar_FindVar = Dvar_FindVar_t(0x4D5390); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 5f2fed37..a4eceabb 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -295,6 +295,9 @@ namespace Game typedef dvar_t*(__cdecl * Dvar_RegisterColor_t)(const char* dvarName, float r, float g, float b, float a, unsigned __int16 flags, const char* description); extern Dvar_RegisterColor_t Dvar_RegisterColor; + typedef dvar_t*(__cdecl * Dvar_RegisterVec3Color_t)(const char* dvarName, float x, float y, float z, float max, unsigned __int16 flags, const char* description); + extern Dvar_RegisterVec3Color_t Dvar_RegisterVec3Color; + typedef void(__cdecl * Dvar_SetFromStringByName_t)(const char* dvarName, const char* string); extern Dvar_SetFromStringByName_t Dvar_SetFromStringByName; diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index cbc87b27..f54bbff3 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -133,7 +133,7 @@ namespace Game SURF_TYPE_COUNT }; - enum dvar_flag : unsigned __int16 + enum DvarFlags : unsigned __int16 { DVAR_NONE = 0, // No flags DVAR_ARCHIVE = 1 << 0, // Set to cause it to be saved to config_mp.cfg of the client