Skip to content

Commit

Permalink
Implement player model glow color based on player color (#4366)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski authored Nov 16, 2024
1 parent 6a362bc commit 1554631
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 9 deletions.
28 changes: 28 additions & 0 deletions Source/CS2/Constants/ColorConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,32 @@ constexpr auto kPlayerColors = std::to_array<Color>({

constexpr Color kColorDefuseKit{119, 221, 255};

constexpr Color kColorPlayerYellowSaturated{255, 251, 0};
constexpr Color kColorPlayerPurpleSaturated{255, 0, 183};
constexpr Color kColorPlayerGreenSaturated{0, 255, 196};
constexpr Color kColorPlayerBlueSaturated{0, 166, 255};
constexpr Color kColorPlayerOrangeSaturated{255, 136, 0};

constexpr auto kPlayerColorsSaturated = std::to_array<Color>({
kColorPlayerBlueSaturated,
kColorPlayerGreenSaturated,
kColorPlayerYellowSaturated,
kColorPlayerOrangeSaturated,
kColorPlayerPurpleSaturated
});

constexpr Color kColorPlayerYellowHalfSaturated{255, 253, 128};
constexpr Color kColorPlayerPurpleHalfSaturated{255, 128, 219};
constexpr Color kColorPlayerGreenHalfSaturated{128, 255, 255};
constexpr Color kColorPlayerBlueHalfSaturated{128, 210, 255};
constexpr Color kColorPlayerOrangeHalfSaturated{255, 195, 128};

constexpr auto kPlayerColorsHalfSaturated = std::to_array<Color>({
kColorPlayerBlueHalfSaturated,
kColorPlayerGreenHalfSaturated,
kColorPlayerYellowHalfSaturated,
kColorPlayerOrangeHalfSaturated,
kColorPlayerPurpleHalfSaturated
});

}
30 changes: 24 additions & 6 deletions Source/Features/Visuals/ModelGlow/ModelGlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ class ModelGlow {

[[nodiscard]] cs2::Color getColor(auto&& playerPawn) const noexcept
{
if (playerPawn.hasImmunity().valueOr(false)) {
switch (playerPawn.teamNumber()) {
case TeamNumber::TT: return cs2::Color{255, 217, 128};
case TeamNumber::CT: return cs2::Color{128, 191, 255};
default: return cs2::kColorWhite;
}
if (playerPawn.hasImmunity().valueOr(false))
return getColorHalfSaturated(playerPawn);
return getColorSaturated(playerPawn);
}

[[nodiscard]] cs2::Color getColorSaturated(auto&& playerPawn) const noexcept
{
if (state().playerModelGlowColorType == PlayerModelGlowColorType::PlayerOrTeamColor) {
if (const auto playerColor = playerPawn.playerController().getPlayerColorSaturated(); playerColor.has_value())
return *playerColor;
}

switch (playerPawn.teamNumber()) {
Expand All @@ -121,5 +125,19 @@ class ModelGlow {
}
}

[[nodiscard]] cs2::Color getColorHalfSaturated(auto&& playerPawn) const noexcept
{
if (state().playerModelGlowColorType == PlayerModelGlowColorType::PlayerOrTeamColor) {
if (const auto playerColor = playerPawn.playerController().getPlayerColorHalfSaturated(); playerColor.has_value())
return *playerColor;
}

switch (playerPawn.teamNumber()) {
case TeamNumber::TT: return cs2::Color{255, 217, 128};
case TeamNumber::CT: return cs2::Color{128, 191, 255};
default: return cs2::kColorWhite;
}
}

HookContext& hookContext;
};
6 changes: 6 additions & 0 deletions Source/Features/Visuals/ModelGlow/ModelGlowState.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include <cstdint>
#include <CS2/Classes/Entities/C_CSPlayerPawn.h>

enum class PlayerModelGlowColorType : std::uint8_t {
PlayerOrTeamColor,
TeamColor,
};

struct ModelGlowState {
enum class State : std::uint8_t {
Enabled,
Expand All @@ -12,6 +17,7 @@ struct ModelGlowState {

State masterSwitch{State::Disabled};
State playerModelGlow{State::Enabled};
PlayerModelGlowColorType playerModelGlowColorType{PlayerModelGlowColorType::PlayerOrTeamColor};
bool showOnlyEnemies{true};

std::uint64_t(*originalPlayerPawnSceneObjectUpdater)(cs2::C_CSPlayerPawn* playerPawn, void*, bool){nullptr};
Expand Down
8 changes: 8 additions & 0 deletions Source/Features/Visuals/ModelGlow/ModelGlowToggle.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class ModelGlowToggle {
}
}

void updatePlayerModelGlowColor(char option) noexcept
{
switch (option) {
case '0': state().playerModelGlowColorType = PlayerModelGlowColorType::PlayerOrTeamColor; break;
case '1': state().playerModelGlowColorType = PlayerModelGlowColorType::TeamColor; break;
}
}

private:
[[nodiscard]] auto& state() const noexcept
{
Expand Down
21 changes: 18 additions & 3 deletions Source/GameClasses/PlayerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,29 @@ class PlayerController {
}

[[nodiscard]] std::optional<cs2::Color> getPlayerColor() const noexcept
{
return getPlayerColor(cs2::kPlayerColors);
}

[[nodiscard]] std::optional<cs2::Color> getPlayerColorSaturated() const noexcept
{
return getPlayerColor(cs2::kPlayerColorsSaturated);
}

[[nodiscard]] std::optional<cs2::Color> getPlayerColorHalfSaturated() const noexcept
{
return getPlayerColor(cs2::kPlayerColorsHalfSaturated);
}

private:
[[nodiscard]] std::optional<cs2::Color> getPlayerColor(std::span<const cs2::Color> playerColors) const noexcept
{
const auto playerColorIndex = hookContext.clientPatternSearchResults().template get<OffsetToPlayerColor>().of(playerControllerPointer).get();
if (playerColorIndex && *playerColorIndex >= 0 && std::cmp_less(*playerColorIndex, cs2::kPlayerColors.size()))
return cs2::kPlayerColors[*playerColorIndex];
if (playerColorIndex && *playerColorIndex >= 0 && std::cmp_less(*playerColorIndex, playerColors.size()))
return playerColors[*playerColorIndex];
return {};
}

private:
HookContext& hookContext;
cs2::CCSPlayerController* playerControllerPointer;
};
2 changes: 2 additions & 0 deletions Source/UI/Panorama/CreateGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ $.Osiris = (function () {

var playerModelGlow = createSection(modelGlowTab, 'Players');
createDropDown(playerModelGlow, "Glow Player Models", 'visuals', 'player_model_glow', ['Enemies', 'All Players', 'Off'], 0);
separator(playerModelGlow);
createDropDown(playerModelGlow, "Player Model Glow Color", 'visuals', 'player_model_glow_color', ['Player / Team Color', 'Team Color'], 0);

$.Osiris.navigateToSubTab('visuals', 'player_info');

Expand Down
2 changes: 2 additions & 0 deletions Source/UI/Panorama/SetCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ struct SetCommandHandler {
features.visualFeatures().modelGlowToggle().updateMasterSwitch(parser.getChar());
} else if (feature == "player_model_glow") {
features.visualFeatures().modelGlowToggle().updatePlayerModelGlowToggle(parser.getChar());
} else if (feature == "player_model_glow_color") {
features.visualFeatures().modelGlowToggle().updatePlayerModelGlowColor(parser.getChar());
}
}

Expand Down

0 comments on commit 1554631

Please sign in to comment.