Skip to content

Commit

Permalink
Implement outline glow for ticking bomb
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Sep 25, 2024
1 parent 9598a6e commit 19ed3bf
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Source/CS2/Classes/CPlantedC4.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

#include <cstdint>

#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;
Expand Down
4 changes: 3 additions & 1 deletion Source/CS2/Constants/EntityTypeNames.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <CS2/Classes/Entities/WeaponEntities.h>
#include <CS2/Classes/CPlantedC4.h>
#include <Platform/Macros/PlatformSpecific.h>
#include <Utils/TypedStaticStringPool.h>

Expand Down Expand Up @@ -51,6 +52,7 @@ constexpr auto kEntityTypeNames = TypedStaticStringPool{}
.add<C_SmokeGrenadeProjectile>(WIN64_LINUX(".?AVC_SmokeGrenadeProjectile@@", "24C_SmokeGrenadeProjectile"))
.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<C_C4>(WIN64_LINUX(".?AVC_C4@@", "4C_C4"))
.add<CPlantedC4>(WIN64_LINUX(".?AVC_PlantedC4@@", "11C_PlantedC4"));

}
2 changes: 1 addition & 1 deletion Source/Features/Hud/BombTimer/BombTimerContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Source/Features/Visuals/OutlineGlow/OutlineGlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class OutlineGlow {
context.applyGlowToPlayer(entity);
else if (entityTypeInfo.typeIndex == utils::typeIndex<cs2::CBaseAnimGraph, KnownEntityTypes>())
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.isGrenadeProjectile())
Expand Down
7 changes: 7 additions & 0 deletions Source/Features/Visuals/OutlineGlow/OutlineGlowContext.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <GameClasses/PlayerPawn.h>
#include <GameClasses/PlantedC4.h>
#include <OutlineGlow/GlowSceneObjects.h>

#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 <typename HookContext>
Expand Down Expand Up @@ -47,6 +49,11 @@ class OutlineGlowContext {
hookContext.template make<DroppedBombOutlineGlow>().applyGlowToBomb(hookContext.template make<BaseEntity>(static_cast<cs2::C_C4*>(&entity)));
}

void applyGlowToPlantedBomb(auto& entity) const noexcept
{
hookContext.template make<TickingBombOutlineGlow>().applyGlowToPlantedBomb(PlantedC4{PlantedC4Base{static_cast<cs2::CPlantedC4*>(&entity)}, hookContext});
}

[[nodiscard]] auto& viewRenderHook() const noexcept
{
return hookContext.hooks().viewRenderHook;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <utility>

#include "TickingBombOutlineGlowContext.h"
#include "TickingBombOutlineGlowParams.h"

template <typename Context>
class TickingBombOutlineGlow {
public:
template <typename... Args>
TickingBombOutlineGlow(Args&&... args) noexcept
: context{std::forward<Args>(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 <typename HookContext>
TickingBombOutlineGlow(HookContext&) -> TickingBombOutlineGlow<TickingBombOutlineGlowContext<HookContext>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <utility>

template <typename Context>
class TickingBombOutlineGlowCondition {
public:
template <typename... Args>
TickingBombOutlineGlowCondition(Args&&... args) noexcept
: context{std::forward<Args>(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;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "TickingBombOutlineGlowCondition.h"

template <typename HookContext>
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<TickingBombOutlineGlowCondition<TickingBombOutlineGlowContext>>();
}

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 ticking_bomb_outline_glow_params
{
constexpr cs2::Color kColor{255, 128, 128, 102};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

#include <utility>

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

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

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

private:
Context context;
};

template <typename HookContext>
TickingBombOutlineGlowToggle(HookContext&) -> TickingBombOutlineGlowToggle<TickingBombOutlineGlowContext<HookContext>>;
6 changes: 6 additions & 0 deletions Source/Features/Visuals/VisualFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -106,6 +107,11 @@ struct VisualFeatures {
return hookContext.template make<DroppedBombOutlineGlowToggle>();
}

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

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 @@ -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"

Expand All @@ -16,4 +17,5 @@ struct VisualFeaturesStates {
DefuseKitOutlineGlowState defuseKitOutlineGlowState;
GrenadeProjectileOutlineGlowState grenadeProjectileOutlineGlowState;
DroppedBombOutlineGlowState droppedBombOutlineGlowState;
TickingBombOutlineGlowState tickingBombOutlineGlowState;
};
13 changes: 9 additions & 4 deletions Source/GameClasses/PlantedC4.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@ struct PlantedC4Base {

template <typename Dependencies>
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<BaseEntity>(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
Expand Down Expand Up @@ -82,5 +87,5 @@ struct PlantedC4 {

private:
PlantedC4Base base;
Dependencies dependencies;
Dependencies& dependencies;
};
6 changes: 6 additions & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@
<ClInclude Include="Features\Visuals\OutlineGlow\PlayerOutlineGlow\PlayerOutlineGlowContext.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\PlayerOutlineGlow\PlayerOutlineGlowState.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\PlayerOutlineGlow\PlayerOutlineGlowToggle.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlow.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowCondition.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowContext.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowParams.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowState.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowToggle.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\WeaponOutlineGlow\WeaponOutlineGlow.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\WeaponOutlineGlow\WeaponOutlineGlowCondition.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\WeaponOutlineGlow\WeaponOutlineGlowContext.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 @@ -181,6 +181,9 @@
<Filter Include="Features\Visuals\OutlineGlow\DroppedBombOutlineGlow">
<UniqueIdentifier>{4cacd578-512d-4917-912c-c98f07a6d19b}</UniqueIdentifier>
</Filter>
<Filter Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow">
<UniqueIdentifier>{845ab4cc-9e82-4b6d-8e55-170788a073b5}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CS2\Classes\C_CSGameRules.h">
Expand Down Expand Up @@ -1565,6 +1568,24 @@
<ClInclude Include="GameClasses\BaseWeapon.h">
<Filter>GameClasses</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlow.h">
<Filter>Features\Visuals\OutlineGlow\TickingBombOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowCondition.h">
<Filter>Features\Visuals\OutlineGlow\TickingBombOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowContext.h">
<Filter>Features\Visuals\OutlineGlow\TickingBombOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowParams.h">
<Filter>Features\Visuals\OutlineGlow\TickingBombOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowState.h">
<Filter>Features\Visuals\OutlineGlow\TickingBombOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\TickingBombOutlineGlow\TickingBombOutlineGlowToggle.h">
<Filter>Features\Visuals\OutlineGlow\TickingBombOutlineGlow</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="UI\Panorama\CreateGUI.js">
Expand Down
2 changes: 2 additions & 0 deletions Source/UI/Panorama/CreateGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
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 @@ -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());
}
}

Expand Down

0 comments on commit 19ed3bf

Please sign in to comment.