Skip to content

Commit

Permalink
Implement outline glow for grenade projectiles
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Sep 20, 2024
1 parent 02cf76b commit 8f7ba72
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 16 deletions.
11 changes: 11 additions & 0 deletions Source/CS2/Classes/Entities/C_BaseCSGrenadeProjectile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "C_BaseEntity.h"

namespace cs2
{

struct C_BaseCSGrenadeProjectile : C_BaseEntity {
};

}
25 changes: 25 additions & 0 deletions Source/CS2/Classes/Entities/GrenadeProjectiles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

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

namespace cs2
{

struct C_HEGrenadeProjectile : C_BaseCSGrenadeProjectile {
static constexpr auto kMangledTypeName{WIN64_LINUX(".?AVC_HEGrenadeProjectile@@", "21C_HEGrenadeProjectile")};
};

struct C_SmokeGrenadeProjectile : C_BaseCSGrenadeProjectile {
static constexpr auto kMangledTypeName{WIN64_LINUX(".?AVC_SmokeGrenadeProjectile@@", "24C_SmokeGrenadeProjectile")};
};

struct C_MolotovProjectile : C_BaseCSGrenadeProjectile {
static constexpr auto kMangledTypeName{WIN64_LINUX(".?AVC_MolotovProjectile@@", "19C_MolotovProjectile")};
};

struct C_FlashbangProjectile : C_BaseCSGrenadeProjectile {
static constexpr auto kMangledTypeName{WIN64_LINUX(".?AVC_FlashbangProjectile@@", "21C_FlashbangProjectile")};
};

}
40 changes: 30 additions & 10 deletions Source/FeatureHelpers/EntityClassifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,44 @@
#include <tuple>

#include <GameDependencies/EntitiesVMTs.h>
#include <Utils/TypeIndex.h>

struct EntityTypeInfo {
std::uint8_t typeIndex;

[[nodiscard]] bool isWeapon() const noexcept
[[nodiscard]] constexpr bool isWeapon() const noexcept
{
if (typeIndex < kIsWeapon.size())
return kIsWeapon[typeIndex];
return false;
return EntityBaseTypeInfo<cs2::C_CSWeaponBase>::isBaseOf(typeIndex);
}

[[nodiscard]] constexpr bool isGrenadeProjectile() const noexcept
{
return EntityBaseTypeInfo<cs2::C_BaseCSGrenadeProjectile>::isBaseOf(typeIndex);
}

template <typename EntityType>
[[nodiscard]] static constexpr auto indexOf() noexcept
{
return utils::typeIndex<EntityType, KnownEntityTypes>();
}

private:
static constexpr auto kIsWeapon{
[]<typename... EntityTypes>(std::type_identity<std::tuple<EntityTypes...>>) {
return std::array<bool, sizeof...(EntityTypes)>{
std::is_base_of_v<cs2::C_CSWeaponBase, EntityTypes>...
};
}(std::type_identity<KnownEntityTypes>{})
template <typename BaseEntityType>
struct EntityBaseTypeInfo {
[[nodiscard]] static constexpr bool isBaseOf(std::uint8_t typeIndex) noexcept
{
if (typeIndex < kIsBase.size())
return kIsBase[typeIndex];
return false;
}

static constexpr auto kIsBase{
[]<typename... EntityTypes>(std::type_identity<std::tuple<EntityTypes...>>) {
return std::array<bool, sizeof...(EntityTypes)>{
std::is_base_of_v<BaseEntityType, EntityTypes>...
};
}(std::type_identity<KnownEntityTypes>{})
};
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <utility>

#include <CS2/Constants/ColorConstants.h>

#include "GrenadeProjectileOutlineGlowContext.h"
#include "GrenadeProjectileOutlineGlowParams.h"

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

void applyGlowToGrenadeProjectile(EntityTypeInfo entityTypeInfo, auto&& grenadeProjectile) const noexcept
{
if (context.state().enabled) {
using namespace grenade_projectile_outline_glow_params;
grenadeProjectile.applyGlowRecursively(getColor(entityTypeInfo).setAlpha(kColorAlpha));
}
}

private:
[[nodiscard]] cs2::Color getColor(EntityTypeInfo entityTypeInfo) const noexcept
{
using namespace grenade_projectile_outline_glow_params;

switch (entityTypeInfo.typeIndex) {
case EntityTypeInfo::indexOf<cs2::C_FlashbangProjectile>(): return kFlashbangColor;
case EntityTypeInfo::indexOf<cs2::C_HEGrenadeProjectile>(): return kHEGrenadeColor;
case EntityTypeInfo::indexOf<cs2::C_MolotovProjectile>(): return kMolotovColor;
case EntityTypeInfo::indexOf<cs2::C_SmokeGrenadeProjectile>(): return kSmokeGrenadeColor;
default: return kFallbackColor;
}
}

Context context;
};

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

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

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

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

#include <CS2/Classes/Color.h>

namespace grenade_projectile_outline_glow_params
{
constexpr auto kColorAlpha = 102;

constexpr cs2::Color kMolotovColor{255, 223, 128};
constexpr cs2::Color kFlashbangColor{128, 172, 255};
constexpr cs2::Color kHEGrenadeColor{255, 128, 128};
constexpr cs2::Color kSmokeGrenadeColor{128, 255, 128};
constexpr cs2::Color kFallbackColor{cs2::kColorWhite};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

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

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

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

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

private:
Context context;
};

template <typename HookContext>
GrenadeProjectileOutlineGlowToggle(HookContext&) -> GrenadeProjectileOutlineGlowToggle<GrenadeProjectileOutlineGlowContext<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 @@ -21,6 +21,8 @@ class OutlineGlow {
context.applyGlowToPlayer(entity);
else if (entityTypeInfo.typeIndex == utils::typeIndex<cs2::CBaseAnimGraph, KnownEntityTypes>())
context.applyGlowToDefuseKit(entity);
else if (entityTypeInfo.isGrenadeProjectile())
context.applyGlowToGrenadeProjectile(entityTypeInfo, 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 @@ -4,6 +4,7 @@
#include <OutlineGlow/GlowSceneObjects.h>

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

Expand Down Expand Up @@ -35,6 +36,11 @@ class OutlineGlowContext {
hookContext.template make<DefuseKitOutlineGlow>().applyGlowToDefuseKit(hookContext.template make<BaseEntity>(static_cast<cs2::CBaseAnimGraph*>(&entity)));
}

void applyGlowToGrenadeProjectile(EntityTypeInfo entityTypeInfo, auto& entity) const noexcept
{
hookContext.template make<GrenadeProjectileOutlineGlow>().applyGlowToGrenadeProjectile(entityTypeInfo, hookContext.template make<BaseEntity>(static_cast<cs2::C_BaseCSGrenadeProjectile*>(&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 @@ -3,6 +3,7 @@
#include <FeatureHelpers/FeatureHelpers.h>
#include "PlayerInformationThroughWalls/PlayerInformationThroughWalls.h"
#include "OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowToggle.h"
#include "OutlineGlow/GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlowToggle.h"
#include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowToggle.h"
#include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowToggle.h"
#include "OutlineGlow/OutlineGlowToggle.h"
Expand Down Expand Up @@ -86,6 +87,11 @@ struct VisualFeatures {
return hookDependencies.make<DefuseKitOutlineGlowToggle>();
}

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

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
Expand Up @@ -2,6 +2,7 @@

#include "PlayerInformationThroughWalls/PlayerInformationThroughWallsState.h"
#include "OutlineGlow/DefuseKitOutlineGlow/DefuseKitOutlineGlowState.h"
#include "OutlineGlow/GrenadeProjectileOutlineGlow/GrenadeProjectileOutlineGlowState.h"
#include "OutlineGlow/PlayerOutlineGlow/PlayerOutlineGlowState.h"
#include "OutlineGlow/WeaponOutlineGlow/WeaponOutlineGlowState.h"
#include "OutlineGlow/OutlineGlowState.h"
Expand All @@ -12,4 +13,5 @@ struct VisualFeaturesStates {
PlayerOutlineGlowState playerOutlineGlowState;
WeaponOutlineGlowState weaponOutlineGlowState;
DefuseKitOutlineGlowState defuseKitOutlineGlowState;
GrenadeProjectileOutlineGlowState grenadeProjectileOutlineGlowState;
};
13 changes: 7 additions & 6 deletions Source/GameDependencies/EntitiesVMTs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <CS2/Classes/Entities/CBaseAnimGraph.h>
#include <CS2/Classes/Entities/C_CSPlayerPawn.h>
#include <CS2/Classes/Entities/CCSPlayerController.h>
#include <CS2/Classes/Entities/GrenadeProjectiles.h>
#include <CS2/Classes/Entities/WeaponEntities.h>
#include <Platform/VmtFinder.h>
#include <Utils/TypeIndex.h>
Expand Down Expand Up @@ -56,7 +57,12 @@ using KnownEntityTypes = std::tuple<
cs2::C_IncendiaryGrenade,
cs2::C_DecoyGrenade,

cs2::CBaseAnimGraph
cs2::CBaseAnimGraph,

cs2::C_HEGrenadeProjectile,
cs2::C_SmokeGrenadeProjectile,
cs2::C_MolotovProjectile,
cs2::C_FlashbangProjectile
>;

struct EntitiesVMTs {
Expand All @@ -65,11 +71,6 @@ struct EntitiesVMTs {
initVmts(clientVmtFinder, std::type_identity<KnownEntityTypes>{});
}

[[nodiscard]] bool isPlayerPawn(const void* vmt) const noexcept
{
return vmt && vmt == getVmt<cs2::C_CSPlayerPawn>();
}

std::array<const void*, std::tuple_size_v<KnownEntityTypes>> vmts{};

private:
Expand Down
7 changes: 7 additions & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
<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_BaseCSGrenadeProjectile.h" />
<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\GrenadeProjectiles.h" />
<ClInclude Include="CS2\Classes\Entities\WeaponEntities.h" />
<ClInclude Include="CS2\Classes\EntitySystem\CConcreteEntityList.h" />
<ClInclude Include="CS2\Classes\EntitySystem\CEntityHandle.h" />
Expand Down Expand Up @@ -167,6 +169,11 @@
<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\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlow.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowContext.h" />
<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\OutlineGlow.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\OutlineGlowContext.h" />
<ClInclude Include="Features\Visuals\OutlineGlow\OutlineGlowState.h" />
Expand Down
24 changes: 24 additions & 0 deletions Source/Osiris.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
<Filter Include="Features\Visuals\OutlineGlow\DefuseKitOutlineGlow">
<UniqueIdentifier>{ab8f4d2e-4353-44f9-ac25-425ae8cbe905}</UniqueIdentifier>
</Filter>
<Filter Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow">
<UniqueIdentifier>{88aa3de7-03b7-49bc-a280-76714e28a62a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CS2\Classes\C_CSGameRules.h">
Expand Down Expand Up @@ -1490,6 +1493,27 @@
<ClInclude Include="GameDependencies\SceneObjectDeps.h">
<Filter>GameDependencies</Filter>
</ClInclude>
<ClInclude Include="CS2\Classes\Entities\C_BaseCSGrenadeProjectile.h">
<Filter>CS2\Classes\Entities</Filter>
</ClInclude>
<ClInclude Include="CS2\Classes\Entities\GrenadeProjectiles.h">
<Filter>CS2\Classes\Entities</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowContext.h">
<Filter>Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowParams.h">
<Filter>Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowState.h">
<Filter>Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowToggle.h">
<Filter>Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlow.h">
<Filter>Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow</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 @@ -313,6 +313,9 @@ $.Osiris = (function () {
var defuseKitOutlineGlow = createSection(outlineGlowTab, 'Defuse Kit Outline Glow');
createYesNoDropDown(defuseKitOutlineGlow, "Glow Defuse Kits on Ground Nearby", 'visuals', 'defuse_kit_outline_glow', 0);

var grenadeProjectileOutlineGlow = createSection(outlineGlowTab, 'Grenade Projectile Outline Glow');
createYesNoDropDown(grenadeProjectileOutlineGlow, "Glow Grenade Projectiles", 'visuals', 'grenade_proj_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 @@ -87,6 +87,8 @@ struct SetCommandHandler {
handleTogglableFeature(features.visualFeatures().weaponOutlineGlowToggle());
} else if (feature == "defuse_kit_outline_glow") {
handleTogglableFeature(features.visualFeatures().defuseKitOutlineGlowToggle());
} else if (feature == "grenade_proj_outline_glow") {
handleTogglableFeature(features.visualFeatures().grenadeProjectileOutlineGlowToggle());
}
}

Expand Down

0 comments on commit 8f7ba72

Please sign in to comment.