From a5680fdc619e25672dae611b03f4ff488d2347cb Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 1 Aug 2021 13:30:11 +0200 Subject: [PATCH 1/2] Color dvar --- src/Components/Modules/Colors.cpp | 30 +++++++++++++++--------------- src/Components/Modules/Colors.hpp | 6 +++--- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Components/Modules/Colors.cpp b/src/Components/Modules/Colors.cpp index 15407879..6951a95e 100644 --- a/src/Components/Modules/Colors.cpp +++ b/src/Components/Modules/Colors.cpp @@ -4,8 +4,8 @@ namespace Components { Dvar::Var Colors::NewColors; Dvar::Var Colors::ColorBlind; - Dvar::Var Colors::ColorAlly; - Dvar::Var Colors::ColorEnemy; + Game::dvar_t* Colors::ColorAlly; + Game::dvar_t* Colors::ColorEnemy; std::vector Colors::ColorTable; @@ -223,7 +223,7 @@ namespace Components } // Patches team overhead normally - bool Colors::Dvar_GetUnpackedColorByName(const char* name, float* color) + bool Colors::Dvar_GetUnpackedColorByName(const char* name, float* expandedColor) { if (Colors::ColorBlind.get()) { @@ -231,21 +231,21 @@ namespace Components if (!str.compare("g_TeamColor_EnemyTeam")) { // A dark red - auto* colorlindEnemy = Colors::ColorEnemy.get(); - color[0] = colorlindEnemy[0]; - color[1] = colorlindEnemy[1]; - color[2] = colorlindEnemy[2]; - color[3] = colorlindEnemy[3]; + auto* colorblindEnemy = Colors::ColorEnemy->current.color; + *expandedColor = (float)(unsigned __int8)colorblindEnemy[0] / 255.0f; + expandedColor[1] = (float)(unsigned __int8)colorblindEnemy[1] / 255.0f; + expandedColor[2] = (float)(unsigned __int8)colorblindEnemy[2] / 255.0f; + expandedColor[3] = (float)(unsigned __int8)colorblindEnemy[3] / 255.0f; return false; } else if (!str.compare("g_TeamColor_MyTeam")) { // A bright yellow - auto* colorblindAlly = Colors::ColorAlly.get(); - color[0] = colorblindAlly[0]; - color[1] = colorblindAlly[1]; - color[2] = colorblindAlly[2]; - color[3] = colorblindAlly[3]; + auto* colorblindAlly = Colors::ColorAlly->current.color; + *expandedColor = (float)(unsigned __int8)colorblindAlly[0] / 255.0f; + expandedColor[1] = (float)(unsigned __int8)colorblindAlly[1] / 255.0f; + expandedColor[2] = (float)(unsigned __int8)colorblindAlly[2] / 255.0f; + expandedColor[3] = (float)(unsigned __int8)colorblindAlly[3] / 255.0f; return false; } } @@ -279,8 +279,8 @@ namespace Components { // Add a colorblind mode for team colors Colors::ColorBlind = Dvar::Register("r_colorBlindTeams", false, Game::dvar_flag::DVAR_FLAG_SAVED, "Use color-blindness-friendly colors for ingame team names"); - Colors::ColorEnemy = Game::Dvar_RegisterVec4("g_TeamColor_EnemyTeam_Color", 0.659f, 0.088f, 0.145f, 1, 0, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Enemy team color"); - Colors::ColorAlly = Game::Dvar_RegisterVec4("g_TeamColor_MyTeam_Color", 1, 0.859f, 0.125f, 1, 0, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Allied team color"); + Colors::ColorEnemy = Game::Dvar_RegisterColor("g_ColorBlind_EnemyTeam", 0.659f, 0.088f, 0.145f, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Enemy team color for colorblind mode"); + Colors::ColorAlly = Game::Dvar_RegisterColor("g_ColorBlind_MyTeam", 1, 0.859f, 0.125f, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Ally team color for colorblind mode"); Utils::Hook(0x406530, Colors::GetUnpackedColorByNameStub, HOOK_JUMP).install()->quick(); // Disable SV_UpdateUserinfo_f, to block changing the name ingame diff --git a/src/Components/Modules/Colors.hpp b/src/Components/Modules/Colors.hpp index a964c674..657d47d7 100644 --- a/src/Components/Modules/Colors.hpp +++ b/src/Components/Modules/Colors.hpp @@ -23,8 +23,8 @@ namespace Components static Dvar::Var NewColors; static Dvar::Var ColorBlind; - static Dvar::Var ColorAlly; - static Dvar::Var ColorEnemy; + static Game::dvar_t* ColorAlly; + static Game::dvar_t* ColorEnemy; static DWORD HsvToRgb(HsvColor hsv); @@ -38,7 +38,7 @@ namespace Components static void LookupColor(DWORD* color, char index); static void LookupColorStub(); static char* CleanStrStub(char* string); - static bool Dvar_GetUnpackedColorByName(const char* name, float* color); + static bool Dvar_GetUnpackedColorByName(const char* name, float* expandedColor); static void GetUnpackedColorByNameStub(); static std::vector ColorTable; }; From 1bd4bcba0579051c6924566d79eab36ba307f160 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 1 Aug 2021 14:22:42 +0200 Subject: [PATCH 2/2] Color dvar --- src/Components/Modules/Colors.cpp | 38 +++++++++++++++---------------- src/Components/Modules/Colors.hpp | 4 ++-- src/Game/Structs.hpp | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Components/Modules/Colors.cpp b/src/Components/Modules/Colors.cpp index 6951a95e..8b857600 100644 --- a/src/Components/Modules/Colors.cpp +++ b/src/Components/Modules/Colors.cpp @@ -4,8 +4,8 @@ namespace Components { Dvar::Var Colors::NewColors; Dvar::Var Colors::ColorBlind; - Game::dvar_t* Colors::ColorAlly; - Game::dvar_t* Colors::ColorEnemy; + Game::dvar_t* Colors::ColorAllyColorBlind; + Game::dvar_t* Colors::ColorEnemyColorBlind; std::vector Colors::ColorTable; @@ -227,25 +227,23 @@ namespace Components { if (Colors::ColorBlind.get()) { - auto str = std::string(name); - if (!str.compare("g_TeamColor_EnemyTeam")) + const auto str = std::string(name); + if (str == "g_TeamColor_EnemyTeam") { - // A dark red - auto* colorblindEnemy = Colors::ColorEnemy->current.color; - *expandedColor = (float)(unsigned __int8)colorblindEnemy[0] / 255.0f; - expandedColor[1] = (float)(unsigned __int8)colorblindEnemy[1] / 255.0f; - expandedColor[2] = (float)(unsigned __int8)colorblindEnemy[2] / 255.0f; - expandedColor[3] = (float)(unsigned __int8)colorblindEnemy[3] / 255.0f; + auto* colorblindEnemy = Colors::ColorEnemyColorBlind->current.color; + expandedColor[0] = static_cast(colorblindEnemy[0]) / 255.0f; + expandedColor[1] = static_cast(colorblindEnemy[1]) / 255.0f; + expandedColor[2] = static_cast(colorblindEnemy[2]) / 255.0f; + expandedColor[3] = static_cast(colorblindEnemy[3]) / 255.0f; return false; } - else if (!str.compare("g_TeamColor_MyTeam")) + else if (str == "g_TeamColor_MyTeam") { - // A bright yellow - auto* colorblindAlly = Colors::ColorAlly->current.color; - *expandedColor = (float)(unsigned __int8)colorblindAlly[0] / 255.0f; - expandedColor[1] = (float)(unsigned __int8)colorblindAlly[1] / 255.0f; - expandedColor[2] = (float)(unsigned __int8)colorblindAlly[2] / 255.0f; - expandedColor[3] = (float)(unsigned __int8)colorblindAlly[3] / 255.0f; + auto* colorblindAlly = Colors::ColorAllyColorBlind->current.color; + expandedColor[0] = static_cast(colorblindAlly[0]) / 255.0f; + expandedColor[1] = static_cast(colorblindAlly[1]) / 255.0f; + expandedColor[2] = static_cast(colorblindAlly[2]) / 255.0f; + expandedColor[3] = static_cast(colorblindAlly[3]) / 255.0f; return false; } } @@ -279,8 +277,10 @@ namespace Components { // Add a colorblind mode for team colors Colors::ColorBlind = Dvar::Register("r_colorBlindTeams", false, Game::dvar_flag::DVAR_FLAG_SAVED, "Use color-blindness-friendly colors for ingame team names"); - Colors::ColorEnemy = Game::Dvar_RegisterColor("g_ColorBlind_EnemyTeam", 0.659f, 0.088f, 0.145f, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Enemy team color for colorblind mode"); - Colors::ColorAlly = Game::Dvar_RegisterColor("g_ColorBlind_MyTeam", 1, 0.859f, 0.125f, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Ally team color for colorblind mode"); + // A dark red + Colors::ColorEnemyColorBlind = Game::Dvar_RegisterColor("g_ColorBlind_EnemyTeam", 0.659f, 0.088f, 0.145f, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Enemy team color for colorblind mode"); + // A bright yellow + Colors::ColorAllyColorBlind = Game::Dvar_RegisterColor("g_ColorBlind_MyTeam", 1, 0.859f, 0.125f, 1, Game::dvar_flag::DVAR_FLAG_SAVED, "Ally team color for colorblind mode"); Utils::Hook(0x406530, Colors::GetUnpackedColorByNameStub, HOOK_JUMP).install()->quick(); // Disable SV_UpdateUserinfo_f, to block changing the name ingame diff --git a/src/Components/Modules/Colors.hpp b/src/Components/Modules/Colors.hpp index 657d47d7..be1f24de 100644 --- a/src/Components/Modules/Colors.hpp +++ b/src/Components/Modules/Colors.hpp @@ -23,8 +23,8 @@ namespace Components static Dvar::Var NewColors; static Dvar::Var ColorBlind; - static Game::dvar_t* ColorAlly; - static Game::dvar_t* ColorEnemy; + static Game::dvar_t* ColorAllyColorBlind; + static Game::dvar_t* ColorEnemyColorBlind; static DWORD HsvToRgb(HsvColor hsv); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 7fdf309a..e64e5d09 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -2347,7 +2347,7 @@ namespace Game float value; float vector[4]; const char *string; - char color[4]; + unsigned char color[4]; }; struct $BFBB53559BEAC4289F32B924847E59CB