Merge pull request #101 from Rackover/colordblind_team_colors

colorblind friendly team colors!
This commit is contained in:
Dss0 2021-08-01 18:01:26 +02:00 committed by GitHub
commit a52f2e9f32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 7 deletions

View File

@ -286,7 +286,7 @@ namespace Components
push [esp + 2Ch]
push [esp + 2Ch]
call AssetHandler::IsAssetEligible
add esp, 08h
add esp, 8h
mov [esp + 20h], eax
popad
@ -295,13 +295,13 @@ namespace Components
test al, al
jz doNotLoad
mov eax, [esp + 8]
mov eax, [esp + 8h]
sub esp, 14h
mov ecx, 5BB657h
jmp ecx
doNotLoad:
mov eax, [esp + 8]
mov eax, [esp + 8h]
retn
}
}

View File

@ -3,6 +3,10 @@
namespace Components
{
Dvar::Var Colors::NewColors;
Dvar::Var Colors::ColorBlind;
Game::dvar_t* Colors::ColorAllyColorBlind;
Game::dvar_t* Colors::ColorEnemyColorBlind;
std::vector<DWORD> Colors::ColorTable;
DWORD Colors::HsvToRgb(Colors::HsvColor hsv)
@ -218,8 +222,69 @@ namespace Components
}
}
// Patches team overhead normally
bool Colors::Dvar_GetUnpackedColorByName(const char* name, float* expandedColor)
{
if (Colors::ColorBlind.get<bool>())
{
const auto str = std::string(name);
if (str == "g_TeamColor_EnemyTeam")
{
// Dvar_GetUnpackedColor
auto* colorblindEnemy = Colors::ColorEnemyColorBlind->current.color;
expandedColor[0] = static_cast<float>(colorblindEnemy[0]) / 255.0f;
expandedColor[1] = static_cast<float>(colorblindEnemy[1]) / 255.0f;
expandedColor[2] = static_cast<float>(colorblindEnemy[2]) / 255.0f;
expandedColor[3] = static_cast<float>(colorblindEnemy[3]) / 255.0f;
return false;
}
else if (str == "g_TeamColor_MyTeam")
{
// Dvar_GetUnpackedColor
auto* colorblindAlly = Colors::ColorAllyColorBlind->current.color;
expandedColor[0] = static_cast<float>(colorblindAlly[0]) / 255.0f;
expandedColor[1] = static_cast<float>(colorblindAlly[1]) / 255.0f;
expandedColor[2] = static_cast<float>(colorblindAlly[2]) / 255.0f;
expandedColor[3] = static_cast<float>(colorblindAlly[3]) / 255.0f;
return false;
}
}
return true;
}
__declspec(naked) void Colors::GetUnpackedColorByNameStub()
{
__asm
{
push [esp + 8h]
push [esp + 8h]
call Colors::Dvar_GetUnpackedColorByName
add esp, 8h
test al, al
jnz continue
retn
continue:
push edi
mov edi, [esp + 8h]
push 406535h
retn
}
}
Colors::Colors()
{
// Add a colorblind mode for team colors
Colors::ColorBlind = Dvar::Register<bool>("r_colorBlindTeams", false, Game::dvar_flag::DVAR_FLAG_SAVED, "Use color-blindness-friendly colors for ingame team names");
// 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
Utils::Hook::Set<BYTE>(0x6258D0, 0xC3);
@ -239,7 +304,7 @@ namespace Components
Utils::Hook(0x4AD470, Colors::CleanStrStub, HOOK_JUMP).install()->quick();
// Register dvar
Colors::NewColors = Dvar::Register<bool>("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare˛ color code style.");
Colors::NewColors = Dvar::Register<bool>("cg_newColors", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Use Warfare 2 color code style.");
Game::Dvar_RegisterColor("sv_customTextColor", 1, 0.7f, 0, 1, Game::dvar_flag::DVAR_FLAG_REPLICATED, "Color for the extended color code.");
Dvar::Register<bool>("sv_allowColoredNames", true, Game::dvar_flag::DVAR_FLAG_NONE, "Allow colored names on the server");

View File

@ -22,6 +22,9 @@ namespace Components
};
static Dvar::Var NewColors;
static Dvar::Var ColorBlind;
static Game::dvar_t* ColorAllyColorBlind;
static Game::dvar_t* ColorEnemyColorBlind;
static DWORD HsvToRgb(HsvColor hsv);
@ -35,6 +38,8 @@ 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* expandedColor);
static void GetUnpackedColorByNameStub();
static std::vector<DWORD> ColorTable;
};
}

View File

@ -193,6 +193,7 @@ namespace Components
"Killera",
"Lithium",
"Louvenarde",
"FutureRave",
"OneFourOne",
"quaK",
"RaidMax",

View File

@ -99,11 +99,11 @@ namespace Game
Dvar_RegisterFloat_t Dvar_RegisterFloat = Dvar_RegisterFloat_t(0x648440);
Dvar_RegisterVec2_t Dvar_RegisterVec2 = Dvar_RegisterVec2_t(0x4F6070);
Dvar_RegisterVec3_t Dvar_RegisterVec3 = Dvar_RegisterVec3_t(0x4EF8E0);
Dvar_RegisterVec4_t Dvar_RegisterVec4 = Dvar_RegisterVec4_t(0x4F28E0);
Dvar_RegisterVec4_t Dvar_RegisterVec4 = Dvar_RegisterVec4_t(0x471500);
Dvar_RegisterInt_t Dvar_RegisterInt = Dvar_RegisterInt_t(0x479830);
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);//0x471500;
Dvar_RegisterColor_t Dvar_RegisterColor = Dvar_RegisterColor_t(0x4F28E0);
Dvar_GetUnpackedColorByName_t Dvar_GetUnpackedColorByName = Dvar_GetUnpackedColorByName_t(0x406530);
Dvar_FindVar_t Dvar_FindVar = Dvar_FindVar_t(0x4D5390);

View File

@ -2347,7 +2347,7 @@ namespace Game
float value;
float vector[4];
const char *string;
char color[4];
unsigned char color[4];
};
struct $BFBB53559BEAC4289F32B924847E59CB