Skip to content

Commit

Permalink
Implement outline glow for hostages (#4345)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Sep 26, 2024
1 parent 2b5c3db commit c000779
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Source/CS2/Classes/Entities/C_Hostage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <cstdint>

#include "C_BaseEntity.h"

namespace cs2
{

struct C_Hostage : C_BaseEntity {
};

}
5 changes: 4 additions & 1 deletion Source/CS2/Constants/EntityTypeNames.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <CS2/Classes/Entities/C_CSPlayerPawn.h>
#include <CS2/Classes/Entities/C_Hostage.h>
#include <CS2/Classes/Entities/WeaponEntities.h>
#include <CS2/Classes/CPlantedC4.h>
#include <Platform/Macros/PlatformSpecific.h>
Expand Down Expand Up @@ -53,6 +55,7 @@ constexpr auto kEntityTypeNames = TypedStaticStringPool{}
.add<C_MolotovProjectile>(WIN64_LINUX(".?AVC_MolotovProjectile@@", "19C_MolotovProjectile"))
.add<C_FlashbangProjectile>(WIN64_LINUX(".?AVC_FlashbangProjectile@@", "21C_FlashbangProjectile"))
.add<C_C4>(WIN64_LINUX(".?AVC_C4@@", "4C_C4"))
.add<CPlantedC4>(WIN64_LINUX(".?AVC_PlantedC4@@", "11C_PlantedC4"));
.add<CPlantedC4>(WIN64_LINUX(".?AVC_PlantedC4@@", "11C_PlantedC4"))
.add<C_Hostage>(WIN64_LINUX(".?AVC_Hostage@@", "9C_Hostage"));

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <utility>

#include "HostageOutlineGlowContext.h"
#include "HostageOutlineGlowParams.h"


template <typename Context>
class HostageOutlineGlow {
public:
template <typename... Args>
HostageOutlineGlow(Args&&... args) noexcept
: context{std::forward<Args>(args)...}
{
}

void applyGlowToHostage(auto&& hostage) const noexcept
{
if (context.state().enabled) {
using namespace hostage_outline_glow_params;
hostage.applyGlowRecursively(kColor);
}
}

private:
Context context;
};

template <typename HookContext>
HostageOutlineGlow(HookContext&) -> HostageOutlineGlow<HostageOutlineGlowContext<HookContext>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

template <typename HookContext>
class HostageOutlineGlowContext {
public:
explicit HostageOutlineGlowContext(HookContext& hookContext) noexcept
: hookContext{hookContext}
{
}

[[nodiscard]] auto& state() const noexcept
{
return hookContext.featuresStates().visualFeaturesStates.hostageOutlineGlowState;
}

private:
HookContext& hookContext;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <CS2/Classes/Color.h>

namespace hostage_outline_glow_params
{
constexpr cs2::Color kColor{255, 234, 128, 102};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

struct HostageOutlineGlowState {
bool enabled{true};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <FeatureHelpers/FeatureToggle.h>
#include "HostageOutlineGlowContext.h"

template <typename Context>
class HostageOutlineGlowToggle : public FeatureToggle<HostageOutlineGlowToggle<Context>> {
public:
template <typename... Args>
HostageOutlineGlowToggle(Args&&... args) noexcept
: context{std::forward<Args>(args)...}
{
}

[[nodiscard]] auto& enabledVariable(typename HostageOutlineGlowToggle::ToggleMethod) const noexcept
{
return context.state().enabled;
}

private:
Context context;
};

template <typename HookContext>
HostageOutlineGlowToggle(HookContext&) -> HostageOutlineGlowToggle<GrenadeProjectileOutlineGlowContext<HookContext>>;
6 changes: 4 additions & 2 deletions Source/Features/Visuals/OutlineGlow/OutlineGlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ class OutlineGlow {
if (!context.state().enabled)
return;

if (entityTypeInfo.typeIndex == utils::typeIndex<cs2::C_CSPlayerPawn, KnownEntityTypes>())
if (entityTypeInfo.is<cs2::C_CSPlayerPawn>())
context.applyGlowToPlayer(entity);
else if (entityTypeInfo.typeIndex == utils::typeIndex<cs2::CBaseAnimGraph, KnownEntityTypes>())
else if (entityTypeInfo.is<cs2::CBaseAnimGraph>())
context.applyGlowToDefuseKit(entity);
else if (entityTypeInfo.is<cs2::CPlantedC4>())
context.applyGlowToPlantedBomb(entity);
else if (entityTypeInfo.is<cs2::C_C4>())
context.applyGlowToBomb(entity);
else if (entityTypeInfo.is<cs2::C_Hostage>())
context.applyGlowToHostage(entity);
else if (entityTypeInfo.isGrenadeProjectile())
context.applyGlowToGrenadeProjectile(entityTypeInfo, entity);
else if (entityTypeInfo.isWeapon())
Expand Down
6 changes: 6 additions & 0 deletions Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DefuseKitOutlineGlow/DefuseKitOutlineGlow.h"
#include "DroppedBombOutlineGlow/DroppedBombOutlineGlow.h"
#include "GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlow.h"
#include "HostageOutlineGlow/HostageOutlineGlow.h"
#include "PlayerOutlineGlow/PlayerOutlineGlow.h"
#include "TickingBombOutlineGlow/TickingBombOutlineGlow.h"
#include "WeaponOutlineGlow/WeaponOutlineGlow.h"
Expand Down Expand Up @@ -54,6 +55,11 @@ class OutlineGlowContext {
hookContext.template make<TickingBombOutlineGlow>().applyGlowToPlantedBomb(PlantedC4{PlantedC4Base{static_cast<cs2::CPlantedC4*>(&entity)}, hookContext});
}

void applyGlowToHostage(auto& entity) const noexcept
{
hookContext.template make<HostageOutlineGlow>().applyGlowToHostage(hookContext.template make<BaseEntity>(static_cast<cs2::C_Hostage*>(&entity)));
}

[[nodiscard]] auto& viewRenderHook() const noexcept
{
return hookContext.hooks().viewRenderHook;
Expand Down
6 changes: 6 additions & 0 deletions Source/Features/Visuals/VisualFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h"
#include "OutlineGlow/DroppedBombOutlineGlow/DroppedBombOutlineGlowToggle.h"
#include "OutlineGlow/GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlowToggle.h"
#include "OutlineGlow/HostageOutlineGlow/HostageOutlineGlowToggle.h"
#include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowToggle.h"
#include "OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowToggle.h"
#include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowToggle.h"
Expand Down Expand Up @@ -112,6 +113,11 @@ struct VisualFeatures {
return hookContext.template make<TickingBombOutlineGlowToggle>();
}

[[nodiscard]] decltype(auto) hostageOutlineGlowToggle() const noexcept
{
return hookContext.template make<HostageOutlineGlowToggle>();
}

HookContext& hookContext;
VisualFeaturesStates& states;
ViewRenderHook& viewRenderHook;
Expand Down
2 changes: 2 additions & 0 deletions Source/Features/Visuals/VisualFeaturesStates.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowState.h"
#include "OutlineGlow/DroppedBombOutlineGlow/DroppedBombOutlineGlowState.h"
#include "OutlineGlow/GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlowState.h"
#include "OutlineGlow/HostageOutlineGlow/HostageOutlineGlowState.h"
#include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowState.h"
#include "OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowState.h"
#include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowState.h"
Expand All @@ -18,4 +19,5 @@ struct VisualFeaturesStates {
GrenadeProjectileOutlineGlowState grenadeProjectileOutlineGlowState;
DroppedBombOutlineGlowState droppedBombOutlineGlowState;
TickingBombOutlineGlowState tickingBombOutlineGlowState;
HostageOutlineGlowState hostageOutlineGlowState;
};
6 changes: 6 additions & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<ClInclude Include="CS2\Classes\Entities\C_BaseEntity.h" />
<ClInclude Include="CS2\Classes\Entities\C_CSPlayerPawn.h" />
<ClInclude Include="CS2\Classes\Entities\C_CSWeaponBase.h" />
<ClInclude Include="CS2\Classes\Entities\C_Hostage.h" />
<ClInclude Include="CS2\Classes\Entities\GrenadeProjectiles.h" />
<ClInclude Include="CS2\Classes\Entities\WeaponEntities.h" />
<ClInclude Include="CS2\Classes\EntitySystem\CConcreteEntityList.h" />
Expand Down Expand Up @@ -184,6 +185,11 @@
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowParams.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowState.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowToggle.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlow.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowContext.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowParams.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowState.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowToggle.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\OutlineGlow.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\OutlineGlowContext.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\OutlineGlowState.h" />
Expand Down
21 changes: 21 additions & 0 deletions Source/Osiris.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@
<Filter Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow">
<UniqueIdentifier>{845ab4cc-9e82-4b6d-8e55-170788a073b5}</UniqueIdentifier>
</Filter>
<Filter Include="Features\Visuals\OutlineGlow\HostageOutlineGlow">
<UniqueIdentifier>{ae772213-696b-492e-be38-31b9e68b96f5}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CS2\Classes\C_CSGameRules.h">
Expand Down Expand Up @@ -1586,6 +1589,24 @@
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowToggle.h">
<Filter>Features\Visuals\OutlineGlow\TickingBombOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlow.h">
<Filter>Features\Visuals\OutlineGlow\HostageOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowContext.h">
<Filter>Features\Visuals\OutlineGlow\HostageOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowParams.h">
<Filter>Features\Visuals\OutlineGlow\HostageOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowState.h">
<Filter>Features\Visuals\OutlineGlow\HostageOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\HostageOutlineGlow\HostageOutlineGlowToggle.h">
<Filter>Features\Visuals\OutlineGlow\HostageOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="CS2\Classes\Entities\C_Hostage.h">
<Filter>CS2\Classes\Entities</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="UI\Panorama\CreateGUI.js">
Expand Down
3 changes: 3 additions & 0 deletions Source/UI/Panorama/CreateGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ $.Osiris = (function () {
$.CreatePanel('Panel', bombAndDefuseKitOutlineGlow, '', { class: "horizontal-separator" });
createYesNoDropDown(bombAndDefuseKitOutlineGlow, "Glow Defuse Kits on Ground Nearby", 'visuals', 'defuse_kit_outline_glow', 0);

var hostageOutlineGlow = createSection(outlineGlowTab, 'Hostages');
createYesNoDropDown(hostageOutlineGlow, "Glow Hostages", 'visuals', 'hostage_outline_glow', 0);

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

var sound = createTab('sound');
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 @@ -94,6 +94,8 @@ struct SetCommandHandler {
handleTogglableFeature(features.visualFeatures().droppedBombOutlineGlowToggle());
} else if (feature == "ticking_bomb_outline_glow") {
handleTogglableFeature(features.visualFeatures().tickingBombOutlineGlowToggle());
} else if (feature == "hostage_outline_glow") {
handleTogglableFeature(features.visualFeatures().hostageOutlineGlowToggle());
}
}

Expand Down

0 comments on commit c000779

Please sign in to comment.