Skip to content

Commit

Permalink
Implement outline glow for defuse kits on ground nearby
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Sep 18, 2024
1 parent 252bfc8 commit aef2a8a
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Source/CS2/Classes/Entities/CBaseAnimGraph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <Platform/Macros/PlatformSpecific.h>
#include "C_BaseEntity.h"

namespace cs2
{

struct CBaseAnimGraph : C_BaseEntity {
static constexpr auto kMangledTypeName{WIN64_LINUX(".?AVCBaseAnimGraph@@", "14CBaseAnimGraph")};
};

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

#include <utility>

#include "DefuseKitOutlineGlowContext.h"
#include "DefuseKitOutlineGlowParams.h"

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

void applyGlowToDefuseKit(auto&& defuseKit) const noexcept
{
if (context.state().enabled) {
using namespace defuse_kit_outline_glow_params;
defuseKit.applyGlowRecursively(kColor, kRange);
}
}

private:
Context context;
};

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

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

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

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

#include <CS2/Classes/Color.h>

namespace defuse_kit_outline_glow_params
{
constexpr cs2::Color kColor{127, 247, 255, 102};
constexpr auto kRange = 800;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

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

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

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

private:
Context context;
};

template <typename HookContext>
DefuseKitOutlineGlowToggle(HookContext&) -> DefuseKitOutlineGlowToggle<DefuseKitOutlineGlowContext<HookContext>>;
2 changes: 2 additions & 0 deletions Source/Features/Visuals/OutlineGlow/OutlineGlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class OutlineGlow {

if (entityTypeInfo.typeIndex == utils::typeIndex<cs2::C_CSPlayerPawn, KnownEntityTypes>())
context.applyGlowToPlayer(entity);
else if (entityTypeInfo.typeIndex == utils::typeIndex<cs2::CBaseAnimGraph, KnownEntityTypes>())
context.applyGlowToDefuseKit(entity);
else if (entityTypeInfo.isWeapon())
context.applyGlowToWeapon(entityTypeInfo, entity);
}
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 @@ -3,6 +3,7 @@
#include <GameClasses/PlayerPawn.h>
#include <OutlineGlow/GlowSceneObjects.h>

#include "DefuseKitOutlineGlow/DefuseKitOutlineGlow.h"
#include "PlayerOutlineGlow/PlayerOutlineGlow.h"
#include "WeaponOutlineGlow/WeaponOutlineGlow.h"

Expand All @@ -29,6 +30,11 @@ class OutlineGlowContext {
hookContext.template make<WeaponOutlineGlow>().applyGlowToWeapon(entityTypeInfo, hookContext.template make<BaseEntity>(static_cast<cs2::C_CSWeaponBase*>(&entity)));
}

void applyGlowToDefuseKit(auto& entity) const noexcept
{
hookContext.template make<DefuseKitOutlineGlow>().applyGlowToDefuseKit(hookContext.template make<BaseEntity>(static_cast<cs2::CBaseAnimGraph*>(&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 @@ -2,6 +2,7 @@

#include <FeatureHelpers/FeatureHelpers.h>
#include "PlayerInformationThroughWalls/PlayerInformationThroughWalls.h"
#include "OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h"
#include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowToggle.h"
#include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowToggle.h"
#include "OutlineGlow/OutlineGlowToggle.h"
Expand Down Expand Up @@ -80,6 +81,11 @@ struct VisualFeatures {
return hookDependencies.make<WeaponOutlineGlowToggle>();
}

[[nodiscard]] decltype(auto) defuseKitOutlineGlowToggle() const noexcept
{
return hookDependencies.make<DefuseKitOutlineGlowToggle>();
}

HookDependencies& hookDependencies;
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
@@ -1,6 +1,7 @@
#pragma once

#include "PlayerInformationThroughWalls/PlayerInformationThroughWallsState.h"
#include "OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowState.h"
#include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowState.h"
#include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowState.h"
#include "OutlineGlow/OutlineGlowState.h"
Expand All @@ -10,4 +11,5 @@ struct VisualFeaturesStates {
OutlineGlowState outlineGlowState;
PlayerOutlineGlowState playerOutlineGlowState;
WeaponOutlineGlowState weaponOutlineGlowState;
DefuseKitOutlineGlowState defuseKitOutlineGlowState;
};
6 changes: 6 additions & 0 deletions Source/GameClasses/BaseEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class BaseEntity {
return cs2::CEntityHandle{cs2::INVALID_EHANDLE_INDEX};
}

void applyGlowRecursively(cs2::Color color, int glowRange = 0) const noexcept
{
applyGlow(color, glowRange);
forEachChild([color, glowRange](auto&& entity) { entity.applyGlow(color, glowRange); });
}

void applyGlow(cs2::Color color, int glowRange = 0) const noexcept
{
renderComponent().sceneObjectUpdaters().forEachSceneObject([this, color, glowRange](auto&& sceneObject){
Expand Down
5 changes: 4 additions & 1 deletion Source/GameDependencies/EntitiesVMTs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <tuple>
#include <type_traits>

#include <CS2/Classes/Entities/CBaseAnimGraph.h>
#include <CS2/Classes/Entities/C_CSPlayerPawn.h>
#include <CS2/Classes/Entities/CCSPlayerController.h>
#include <CS2/Classes/Entities/WeaponEntities.h>
Expand Down Expand Up @@ -53,7 +54,9 @@ using KnownEntityTypes = std::tuple<
cs2::C_SmokeGrenade,
cs2::C_MolotovGrenade,
cs2::C_IncendiaryGrenade,
cs2::C_DecoyGrenade
cs2::C_DecoyGrenade,

cs2::CBaseAnimGraph
>;

struct EntitiesVMTs {
Expand Down
6 changes: 6 additions & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<ClInclude Include="CS2\Classes\CUtlVector.h" />
<ClInclude Include="CS2\Classes\CViewRender.h" />
<ClInclude Include="CS2\Classes\C_CSGameRules.h" />
<ClInclude Include="CS2\Classes\Entities\CBaseAnimGraph.h" />
<ClInclude Include="CS2\Classes\Entities\CCSPlayerController.h" />
<ClInclude Include="CS2\Classes\Entities\CEntityInstance.h" />
<ClInclude Include="CS2\Classes\Entities\C_BaseEntity.h" />
Expand Down Expand Up @@ -161,6 +162,11 @@
<ClInclude Include="Features\Sound\SoundFeaturesStates.h" />
<ClInclude Include="Features\Sound\WeaponReloadVisualizer.h" />
<ClInclude Include="Features\Sound\WeaponScopeVisualizer.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlow.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowContext.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowParams.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowState.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowToggle.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 @@ -172,6 +172,9 @@
<Filter Include="Features\Visuals\OutlineGlow\PlayerOutlineGlow">
<UniqueIdentifier>{8c999ef8-d7ae-4f2b-bc29-f9ed28e806db}</UniqueIdentifier>
</Filter>
<Filter Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow">
<UniqueIdentifier>{ab8f4d2e-4353-44f9-ac25-425ae8cbe905}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CS2\Classes\C_CSGameRules.h">
Expand Down Expand Up @@ -1460,6 +1463,24 @@
<ClInclude Include="Features\Visuals\OutlineGlow\WeaponOutlineGlow\WeaponOutlineGlowParams.h">
<Filter>Features\Visuals\OutlineGlow\WeaponOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="CS2\Classes\Entities\CBaseAnimGraph.h">
<Filter>CS2\Classes\Entities</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlow.h">
<Filter>Features\Visuals\OutlineGlow\DefuseKitOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowContext.h">
<Filter>Features\Visuals\OutlineGlow\DefuseKitOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowParams.h">
<Filter>Features\Visuals\OutlineGlow\DefuseKitOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowState.h">
<Filter>Features\Visuals\OutlineGlow\DefuseKitOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow\DefuseKitOutlineGlowToggle.h">
<Filter>Features\Visuals\OutlineGlow\DefuseKitOutlineGlow</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 @@ -310,6 +310,9 @@ $.Osiris = (function () {
var weaponOutlineGlow = createSection(outlineGlowTab, 'Weapon Outline Glow');
createYesNoDropDown(weaponOutlineGlow, "Glow Weapons on Ground Nearby", 'visuals', 'weapon_outline_glow', 0);

var defuseKitOutlineGlow = createSection(outlineGlowTab, 'Defuse Kit Outline Glow');
createYesNoDropDown(defuseKitOutlineGlow, "Glow Defuse Kits on Ground Nearby", 'visuals', 'defuse_kit_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 @@ -85,6 +85,8 @@ struct SetCommandHandler {
handleTogglableFeature(features.visualFeatures().outlineGlowToggle());
} else if (feature == "weapon_outline_glow") {
handleTogglableFeature(features.visualFeatures().weaponOutlineGlowToggle());
} else if (feature == "defuse_kit_outline_glow") {
handleTogglableFeature(features.visualFeatures().defuseKitOutlineGlowToggle());
}
}

Expand Down

0 comments on commit aef2a8a

Please sign in to comment.