From cd0da67834af4d1745c5359d520c287cbac31427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Krupi=C5=84ski?= Date: Wed, 25 Sep 2024 21:55:35 +0200 Subject: [PATCH] Implement outline glow for ticking bomb (#4344) --- Source/CS2/Classes/CPlantedC4.h | 4 ++- Source/CS2/Constants/EntityTypeNames.h | 4 ++- .../Features/Hud/BombTimer/BombTimerContext.h | 2 +- .../Visuals/OutlineGlow/OutlineGlow.h | 2 ++ .../Visuals/OutlineGlow/OutlineGlowContext.h | 7 ++++ .../TickingBombOutlineGlow.h | 32 +++++++++++++++++++ .../TickingBombOutlineGlowCondition.h | 26 +++++++++++++++ .../TickingBombOutlineGlowContext.h | 25 +++++++++++++++ .../TickingBombOutlineGlowParams.h | 8 +++++ .../TickingBombOutlineGlowState.h | 5 +++ .../TickingBombOutlineGlowToggle.h | 27 ++++++++++++++++ Source/Features/Visuals/VisualFeatures.h | 6 ++++ .../Features/Visuals/VisualFeaturesStates.h | 2 ++ Source/GameClasses/PlantedC4.h | 13 +++++--- Source/Osiris.vcxproj | 6 ++++ Source/Osiris.vcxproj.filters | 21 ++++++++++++ Source/UI/Panorama/CreateGUI.js | 2 ++ Source/UI/Panorama/SetCommandHandler.h | 2 ++ 18 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlow.h create mode 100644 Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowCondition.h create mode 100644 Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowContext.h create mode 100644 Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowParams.h create mode 100644 Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowState.h create mode 100644 Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowToggle.h diff --git a/Source/CS2/Classes/CPlantedC4.h b/Source/CS2/Classes/CPlantedC4.h index f226a123109..9c3e712eb42 100644 --- a/Source/CS2/Classes/CPlantedC4.h +++ b/Source/CS2/Classes/CPlantedC4.h @@ -2,10 +2,12 @@ #include +#include "Entities/C_BaseEntity.h" + namespace cs2 { -struct CPlantedC4 { +struct CPlantedC4 : C_BaseEntity { using m_nBombSite = int; using m_bBombTicking = bool; using m_hBombDefuser = std::uint32_t; diff --git a/Source/CS2/Constants/EntityTypeNames.h b/Source/CS2/Constants/EntityTypeNames.h index 43dc7074c13..1ec495aba09 100644 --- a/Source/CS2/Constants/EntityTypeNames.h +++ b/Source/CS2/Constants/EntityTypeNames.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -51,6 +52,7 @@ constexpr auto kEntityTypeNames = TypedStaticStringPool{} .add(WIN64_LINUX(".?AVC_SmokeGrenadeProjectile@@", "24C_SmokeGrenadeProjectile")) .add(WIN64_LINUX(".?AVC_MolotovProjectile@@", "19C_MolotovProjectile")) .add(WIN64_LINUX(".?AVC_FlashbangProjectile@@", "21C_FlashbangProjectile")) - .add(WIN64_LINUX(".?AVC_C4@@", "4C_C4")); + .add(WIN64_LINUX(".?AVC_C4@@", "4C_C4")) + .add(WIN64_LINUX(".?AVC_PlantedC4@@", "11C_PlantedC4")); } diff --git a/Source/Features/Hud/BombTimer/BombTimerContext.h b/Source/Features/Hud/BombTimer/BombTimerContext.h index 571e7823f81..94fa41ed38b 100644 --- a/Source/Features/Hud/BombTimer/BombTimerContext.h +++ b/Source/Features/Hud/BombTimer/BombTimerContext.h @@ -24,7 +24,7 @@ struct BombTimerContext { [[nodiscard]] bool hasTickingC4() const noexcept { const auto plantedC4{_context.plantedC4()}; - return plantedC4 && plantedC4->isTicking(); + return plantedC4 && plantedC4->isTicking().valueOr(true) && plantedC4->getTimeToExplosion().greaterThan(0.0f).valueOr(false); } [[nodiscard]] auto tickingC4() const noexcept diff --git a/Source/Features/Visuals/OutlineGlow/OutlineGlow.h b/Source/Features/Visuals/OutlineGlow/OutlineGlow.h index 140b2d3137f..4bdfe44c545 100644 --- a/Source/Features/Visuals/OutlineGlow/OutlineGlow.h +++ b/Source/Features/Visuals/OutlineGlow/OutlineGlow.h @@ -21,6 +21,8 @@ class OutlineGlow { context.applyGlowToPlayer(entity); else if (entityTypeInfo.typeIndex == utils::typeIndex()) context.applyGlowToDefuseKit(entity); + else if (entityTypeInfo.is()) + context.applyGlowToPlantedBomb(entity); else if (entityTypeInfo.is()) context.applyGlowToBomb(entity); else if (entityTypeInfo.isGrenadeProjectile()) diff --git a/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h b/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h index 6636462369c..b650cc3e795 100644 --- a/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h +++ b/Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h @@ -1,12 +1,14 @@ #pragma once #include +#include #include #include "DefuseKitOutlineGlow/DefuseKitOutlineGlow.h" #include "DroppedBombOutlineGlow/DroppedBombOutlineGlow.h" #include "GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlow.h" #include "PlayerOutlineGlow/PlayerOutlineGlow.h" +#include "TickingBombOutlineGlow/TickingBombOutlineGlow.h" #include "WeaponOutlineGlow/WeaponOutlineGlow.h" template @@ -47,6 +49,11 @@ class OutlineGlowContext { hookContext.template make().applyGlowToBomb(hookContext.template make(static_cast(&entity))); } + void applyGlowToPlantedBomb(auto& entity) const noexcept + { + hookContext.template make().applyGlowToPlantedBomb(PlantedC4{PlantedC4Base{static_cast(&entity)}, hookContext}); + } + [[nodiscard]] auto& viewRenderHook() const noexcept { return hookContext.hooks().viewRenderHook; diff --git a/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlow.h b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlow.h new file mode 100644 index 00000000000..d2a3abd6516 --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlow.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include "TickingBombOutlineGlowContext.h" +#include "TickingBombOutlineGlowParams.h" + +template +class TickingBombOutlineGlow { +public: + template + TickingBombOutlineGlow(Args&&... args) noexcept + : context{std::forward(args)...} + { + } + + void applyGlowToPlantedBomb(auto&& plantedBomb) const noexcept + { + auto&& condition = context.condition(); + if (!condition.shouldRun() || !condition.shouldGlowPlantedBomb(plantedBomb)) + return; + + using namespace ticking_bomb_outline_glow_params; + plantedBomb.baseEntity().applyGlowRecursively(kColor); + } + +private: + Context context; +}; + +template +TickingBombOutlineGlow(HookContext&) -> TickingBombOutlineGlow>; diff --git a/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowCondition.h b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowCondition.h new file mode 100644 index 00000000000..181d1c4a396 --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowCondition.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +template +class TickingBombOutlineGlowCondition { +public: + template + TickingBombOutlineGlowCondition(Args&&... args) noexcept + : context{std::forward(args)...} + { + } + + [[nodiscard]] bool shouldRun() const noexcept + { + return context.state().enabled; + } + + [[nodiscard]] bool shouldGlowPlantedBomb(auto&& plantedBomb) const noexcept + { + return plantedBomb.isTicking().valueOr(true); + } + +private: + Context context; +}; diff --git a/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowContext.h b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowContext.h new file mode 100644 index 00000000000..e1279bc2bf4 --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowContext.h @@ -0,0 +1,25 @@ +#pragma once + +#include "TickingBombOutlineGlowCondition.h" + +template +class TickingBombOutlineGlowContext { +public: + explicit TickingBombOutlineGlowContext(HookContext& hookContext) noexcept + : hookContext{hookContext} + { + } + + [[nodiscard]] auto& state() const noexcept + { + return hookContext.featuresStates().visualFeaturesStates.tickingBombOutlineGlowState; + } + + [[nodiscard]] decltype(auto) condition() const noexcept + { + return hookContext.template make>(); + } + +private: + HookContext& hookContext; +}; diff --git a/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowParams.h b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowParams.h new file mode 100644 index 00000000000..e1dd2ed34dc --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowParams.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace ticking_bomb_outline_glow_params +{ + constexpr cs2::Color kColor{255, 128, 128, 102}; +} diff --git a/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowState.h b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowState.h new file mode 100644 index 00000000000..3f71dbb2c3d --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowState.h @@ -0,0 +1,5 @@ +#pragma once + +struct TickingBombOutlineGlowState { + bool enabled{true}; +}; diff --git a/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowToggle.h b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowToggle.h new file mode 100644 index 00000000000..7c40ea02d9b --- /dev/null +++ b/Source/Features/Visuals/OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowToggle.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include +#include "TickingBombOutlineGlowContext.h" + +template +class TickingBombOutlineGlowToggle : public FeatureToggle> { +public: + template + TickingBombOutlineGlowToggle(Args&&... args) noexcept + : context{std::forward(args)...} + { + } + + [[nodiscard]] auto& enabledVariable(typename TickingBombOutlineGlowToggle::ToggleMethod) const noexcept + { + return context.state().enabled; + } + +private: + Context context; +}; + +template +TickingBombOutlineGlowToggle(HookContext&) -> TickingBombOutlineGlowToggle>; diff --git a/Source/Features/Visuals/VisualFeatures.h b/Source/Features/Visuals/VisualFeatures.h index dd561534596..f443675c706 100644 --- a/Source/Features/Visuals/VisualFeatures.h +++ b/Source/Features/Visuals/VisualFeatures.h @@ -6,6 +6,7 @@ #include "OutlineGlow/DroppedBombOutlineGlow/DroppedBombOutlineGlowToggle.h" #include "OutlineGlow/GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlowToggle.h" #include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowToggle.h" +#include "OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowToggle.h" #include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowToggle.h" #include "OutlineGlow/OutlineGlowToggle.h" #include "VisualFeaturesStates.h" @@ -106,6 +107,11 @@ struct VisualFeatures { return hookContext.template make(); } + [[nodiscard]] decltype(auto) tickingBombOutlineGlowToggle() const noexcept + { + return hookContext.template make(); + } + HookContext& hookContext; VisualFeaturesStates& states; ViewRenderHook& viewRenderHook; diff --git a/Source/Features/Visuals/VisualFeaturesStates.h b/Source/Features/Visuals/VisualFeaturesStates.h index 089d1f1269b..0f80ce21bdf 100644 --- a/Source/Features/Visuals/VisualFeaturesStates.h +++ b/Source/Features/Visuals/VisualFeaturesStates.h @@ -5,6 +5,7 @@ #include "OutlineGlow/DroppedBombOutlineGlow/DroppedBombOutlineGlowState.h" #include "OutlineGlow/GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlowState.h" #include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowState.h" +#include "OutlineGlow/TickingBombOutlineGlow/TickingBombOutlineGlowState.h" #include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowState.h" #include "OutlineGlow/OutlineGlowState.h" @@ -16,4 +17,5 @@ struct VisualFeaturesStates { DefuseKitOutlineGlowState defuseKitOutlineGlowState; GrenadeProjectileOutlineGlowState grenadeProjectileOutlineGlowState; DroppedBombOutlineGlowState droppedBombOutlineGlowState; + TickingBombOutlineGlowState tickingBombOutlineGlowState; }; diff --git a/Source/GameClasses/PlantedC4.h b/Source/GameClasses/PlantedC4.h index 4c12ebc878f..6dc61cca978 100644 --- a/Source/GameClasses/PlantedC4.h +++ b/Source/GameClasses/PlantedC4.h @@ -39,20 +39,25 @@ struct PlantedC4Base { template struct PlantedC4 { - explicit PlantedC4(PlantedC4Base base, Dependencies dependencies) noexcept + explicit PlantedC4(PlantedC4Base base, Dependencies& dependencies) noexcept : base{base} , dependencies{dependencies} { } + [[nodiscard]] decltype(auto) baseEntity() const noexcept + { + return dependencies.template make(base.thisptr); + } + [[nodiscard]] auto getTimeToExplosion() const noexcept { return base.blowTime().toOptional() - dependencies.globalVars().curtime(); } - [[nodiscard]] bool isTicking() const noexcept + [[nodiscard]] auto isTicking() const noexcept { - return base.ticking().valueOr(true) && getTimeToExplosion().greaterThan(0.0f).valueOr(false); + return base.ticking().toOptional(); } [[nodiscard]] bool isBeingDefused() const noexcept @@ -82,5 +87,5 @@ struct PlantedC4 { private: PlantedC4Base base; - Dependencies dependencies; + Dependencies& dependencies; }; diff --git a/Source/Osiris.vcxproj b/Source/Osiris.vcxproj index 9b452544e59..9d9adbe90d8 100644 --- a/Source/Osiris.vcxproj +++ b/Source/Osiris.vcxproj @@ -195,6 +195,12 @@ + + + + + + diff --git a/Source/Osiris.vcxproj.filters b/Source/Osiris.vcxproj.filters index b4a7dba7992..8c2b28d7aac 100644 --- a/Source/Osiris.vcxproj.filters +++ b/Source/Osiris.vcxproj.filters @@ -181,6 +181,9 @@ {4cacd578-512d-4917-912c-c98f07a6d19b} + + {845ab4cc-9e82-4b6d-8e55-170788a073b5} + @@ -1565,6 +1568,24 @@ GameClasses + + Features\Visuals\OutlineGlow\TickingBombOutlineGlow + + + Features\Visuals\OutlineGlow\TickingBombOutlineGlow + + + Features\Visuals\OutlineGlow\TickingBombOutlineGlow + + + Features\Visuals\OutlineGlow\TickingBombOutlineGlow + + + Features\Visuals\OutlineGlow\TickingBombOutlineGlow + + + Features\Visuals\OutlineGlow\TickingBombOutlineGlow + diff --git a/Source/UI/Panorama/CreateGUI.js b/Source/UI/Panorama/CreateGUI.js index b29232c27e6..f03940ca29b 100644 --- a/Source/UI/Panorama/CreateGUI.js +++ b/Source/UI/Panorama/CreateGUI.js @@ -315,6 +315,8 @@ $.Osiris = (function () { var bombAndDefuseKitOutlineGlow = createSection(outlineGlowTab, 'Bomb & Defuse Kit'); createYesNoDropDown(bombAndDefuseKitOutlineGlow, "Glow Dropped Bomb", 'visuals', 'dropped_bomb_outline_glow', 0); $.CreatePanel('Panel', bombAndDefuseKitOutlineGlow, '', { class: "horizontal-separator" }); + createYesNoDropDown(bombAndDefuseKitOutlineGlow, "Glow Ticking Bomb", 'visuals', 'ticking_bomb_outline_glow', 0); + $.CreatePanel('Panel', bombAndDefuseKitOutlineGlow, '', { class: "horizontal-separator" }); createYesNoDropDown(bombAndDefuseKitOutlineGlow, "Glow Defuse Kits on Ground Nearby", 'visuals', 'defuse_kit_outline_glow', 0); $.Osiris.navigateToSubTab('visuals', 'player_info'); diff --git a/Source/UI/Panorama/SetCommandHandler.h b/Source/UI/Panorama/SetCommandHandler.h index 2348180be1a..d07cf1bd7a0 100644 --- a/Source/UI/Panorama/SetCommandHandler.h +++ b/Source/UI/Panorama/SetCommandHandler.h @@ -92,6 +92,8 @@ struct SetCommandHandler { handleTogglableFeature(features.visualFeatures().grenadeProjectileOutlineGlowToggle()); } else if (feature == "dropped_bomb_outline_glow") { handleTogglableFeature(features.visualFeatures().droppedBombOutlineGlowToggle()); + } else if (feature == "ticking_bomb_outline_glow") { + handleTogglableFeature(features.visualFeatures().tickingBombOutlineGlowToggle()); } }