From aef2a8af8c1d29bffe3ee65390a9f41eec0f5607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Krupi=C5=84ski?= Date: Wed, 18 Sep 2024 20:14:13 +0200 Subject: [PATCH] Implement outline glow for defuse kits on ground nearby --- Source/CS2/Classes/Entities/CBaseAnimGraph.h | 13 ++++++++ .../DefuseKitOutlineGlow.h | 30 +++++++++++++++++++ .../DefuseKitOutlineGlowContext.h | 18 +++++++++++ .../DefuseKitOutlineGlowParams.h | 9 ++++++ .../DefuseKitOutlineGlowState.h | 5 ++++ .../DefuseKitOutlineGlowToggle.h | 25 ++++++++++++++++ .../Visuals/OutlineGlow/OutlineGlow.h | 2 ++ .../Visuals/OutlineGlow/OutlineGlowContext.h | 6 ++++ Source/Features/Visuals/VisualFeatures.h | 6 ++++ .../Features/Visuals/VisualFeaturesStates.h | 2 ++ Source/GameClasses/BaseEntity.h | 6 ++++ Source/GameDependencies/EntitiesVMTs.h | 5 +++- Source/Osiris.vcxproj | 6 ++++ Source/Osiris.vcxproj.filters | 21 +++++++++++++ Source/UI/Panorama/CreateGUI.js | 3 ++ Source/UI/Panorama/SetCommandHandler.h | 2 ++ 16 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 Source/CS2/Classes/Entities/CBaseAnimGraph.h create mode 100644 Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlow.h create mode 100644 Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowContext.h create mode 100644 Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowParams.h create mode 100644 Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowState.h create mode 100644 Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h diff --git a/Source/CS2/Classes/Entities/CBaseAnimGraph.h b/Source/CS2/Classes/Entities/CBaseAnimGraph.h new file mode 100644 index 00000000000..467eafbc0b5 --- /dev/null +++ b/Source/CS2/Classes/Entities/CBaseAnimGraph.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include "C_BaseEntity.h" + +namespace cs2 +{ + +struct CBaseAnimGraph : C_BaseEntity { + static constexpr auto kMangledTypeName{WIN64_LINUX(".?AVCBaseAnimGraph@@", "14CBaseAnimGraph")}; +}; + +} diff --git a/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlow.h b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlow.h new file mode 100644 index 00000000000..2f79733882e --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlow.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include "DefuseKitOutlineGlowContext.h" +#include "DefuseKitOutlineGlowParams.h" + +template +class DefuseKitOutlineGlow { +public: + template + DefuseKitOutlineGlow(Args&&... args) noexcept + : context{std::forward(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 +DefuseKitOutlineGlow(HookContext&) -> DefuseKitOutlineGlow>; diff --git a/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowContext.h b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowContext.h new file mode 100644 index 00000000000..eff55b167a0 --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowContext.h @@ -0,0 +1,18 @@ +#pragma once + +template +class DefuseKitOutlineGlowContext { +public: + explicit DefuseKitOutlineGlowContext(HookContext& hookContext) noexcept + : hookContext{hookContext} + { + } + + [[nodiscard]] auto& state() const noexcept + { + return hookContext.featuresStates().visualFeaturesStates.defuseKitOutlineGlowState; + } + +private: + HookContext& hookContext; +}; diff --git a/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowParams.h b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowParams.h new file mode 100644 index 00000000000..956eb6011a2 --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowParams.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace defuse_kit_outline_glow_params +{ + constexpr cs2::Color kColor{127, 247, 255, 102}; + constexpr auto kRange = 800; +} diff --git a/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowState.h b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowState.h new file mode 100644 index 00000000000..f8755c11518 --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowState.h @@ -0,0 +1,5 @@ +#pragma once + +struct DefuseKitOutlineGlowState { + bool enabled{true}; +}; diff --git a/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h new file mode 100644 index 00000000000..4cdaa6669f9 --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include "DefuseKitOutlineGlowContext.h" + +template +class DefuseKitOutlineGlowToggle : public FeatureToggle> { +public: + template + DefuseKitOutlineGlowToggle(Args&&... args) noexcept + : context{std::forward(args)...} + { + } + + [[nodiscard]] auto& enabledVariable(typename DefuseKitOutlineGlowToggle::ToggleMethod) const noexcept + { + return context.state().enabled; + } + +private: + Context context; +}; + +template +DefuseKitOutlineGlowToggle(HookContext&) -> DefuseKitOutlineGlowToggle>; diff --git a/Source/Features/Visuals/OutlineGlow/OutlineGlow.h b/Source/Features/Visuals/OutlineGlow/OutlineGlow.h index 0b5b9e173f8..d1f5570410d 100644 --- a/Source/Features/Visuals/OutlineGlow/OutlineGlow.h +++ b/Source/Features/Visuals/OutlineGlow/OutlineGlow.h @@ -19,6 +19,8 @@ class OutlineGlow { if (entityTypeInfo.typeIndex == utils::typeIndex()) context.applyGlowToPlayer(entity); + else if (entityTypeInfo.typeIndex == utils::typeIndex()) + context.applyGlowToDefuseKit(entity); else if (entityTypeInfo.isWeapon()) context.applyGlowToWeapon(entityTypeInfo, entity); } diff --git a/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h b/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h index e69a5c52598..66371728e0e 100644 --- a/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h +++ b/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h @@ -3,6 +3,7 @@ #include #include +#include "DefuseKitOutlineGlow/DefuseKitOutlineGlow.h" #include "PlayerOutlineGlow/PlayerOutlineGlow.h" #include "WeaponOutlineGlow/WeaponOutlineGlow.h" @@ -29,6 +30,11 @@ class OutlineGlowContext { hookContext.template make().applyGlowToWeapon(entityTypeInfo, hookContext.template make(static_cast(&entity))); } + void applyGlowToDefuseKit(auto& entity) const noexcept + { + hookContext.template make().applyGlowToDefuseKit(hookContext.template make(static_cast(&entity))); + } + [[nodiscard]] auto& viewRenderHook() const noexcept { return hookContext.hooks().viewRenderHook; diff --git a/Source/Features/Visuals/VisualFeatures.h b/Source/Features/Visuals/VisualFeatures.h index a0924070d63..66e955f92b9 100644 --- a/Source/Features/Visuals/VisualFeatures.h +++ b/Source/Features/Visuals/VisualFeatures.h @@ -2,6 +2,7 @@ #include #include "PlayerInformationThroughWalls/PlayerInformationThroughWalls.h" +#include "OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h" #include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowToggle.h" #include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowToggle.h" #include "OutlineGlow/OutlineGlowToggle.h" @@ -80,6 +81,11 @@ struct VisualFeatures { return hookDependencies.make(); } + [[nodiscard]] decltype(auto) defuseKitOutlineGlowToggle() const noexcept + { + return hookDependencies.make(); + } + HookDependencies& hookDependencies; VisualFeaturesStates& states; ViewRenderHook& viewRenderHook; diff --git a/Source/Features/Visuals/VisualFeaturesStates.h b/Source/Features/Visuals/VisualFeaturesStates.h index af2fe50d2a4..d76ddbcfeb1 100644 --- a/Source/Features/Visuals/VisualFeaturesStates.h +++ b/Source/Features/Visuals/VisualFeaturesStates.h @@ -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" @@ -10,4 +11,5 @@ struct VisualFeaturesStates { OutlineGlowState outlineGlowState; PlayerOutlineGlowState playerOutlineGlowState; WeaponOutlineGlowState weaponOutlineGlowState; + DefuseKitOutlineGlowState defuseKitOutlineGlowState; }; diff --git a/Source/GameClasses/BaseEntity.h b/Source/GameClasses/BaseEntity.h index 89d0e9b1f9d..79dd90de3fb 100644 --- a/Source/GameClasses/BaseEntity.h +++ b/Source/GameClasses/BaseEntity.h @@ -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){ diff --git a/Source/GameDependencies/EntitiesVMTs.h b/Source/GameDependencies/EntitiesVMTs.h index 444006676b8..14238bcb3b6 100644 --- a/Source/GameDependencies/EntitiesVMTs.h +++ b/Source/GameDependencies/EntitiesVMTs.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -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 { diff --git a/Source/Osiris.vcxproj b/Source/Osiris.vcxproj index 3822228ddd4..74e37ac38b1 100644 --- a/Source/Osiris.vcxproj +++ b/Source/Osiris.vcxproj @@ -35,6 +35,7 @@ + @@ -161,6 +162,11 @@ + + + + + diff --git a/Source/Osiris.vcxproj.filters b/Source/Osiris.vcxproj.filters index ed689838053..b0e59095dad 100644 --- a/Source/Osiris.vcxproj.filters +++ b/Source/Osiris.vcxproj.filters @@ -172,6 +172,9 @@ {8c999ef8-d7ae-4f2b-bc29-f9ed28e806db} + + {ab8f4d2e-4353-44f9-ac25-425ae8cbe905} + @@ -1460,6 +1463,24 @@ Features\Visuals\OutlineGlow\WeaponOutlineGlow + + CS2\Classes\Entities + + + Features\Visuals\OutlineGlow\DefuseKitOutlineGlow + + + Features\Visuals\OutlineGlow\DefuseKitOutlineGlow + + + Features\Visuals\OutlineGlow\DefuseKitOutlineGlow + + + Features\Visuals\OutlineGlow\DefuseKitOutlineGlow + + + Features\Visuals\OutlineGlow\DefuseKitOutlineGlow + diff --git a/Source/UI/Panorama/CreateGUI.js b/Source/UI/Panorama/CreateGUI.js index c562677fd94..b7e53e21006 100644 --- a/Source/UI/Panorama/CreateGUI.js +++ b/Source/UI/Panorama/CreateGUI.js @@ -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'); diff --git a/Source/UI/Panorama/SetCommandHandler.h b/Source/UI/Panorama/SetCommandHandler.h index e498d7d8bf1..a81aadc3928 100644 --- a/Source/UI/Panorama/SetCommandHandler.h +++ b/Source/UI/Panorama/SetCommandHandler.h @@ -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()); } }