Skip to content

Commit

Permalink
Glow smoke grenade projectile only until smoke effect begins
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Sep 23, 2024
1 parent 9a2b3b4 commit 543678a
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Source/CS2/Classes/Entities/GrenadeProjectiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct C_HEGrenadeProjectile : C_BaseCSGrenadeProjectile {

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

using m_bDidSmokeEffect = bool;
};

struct C_MolotovProjectile : C_BaseCSGrenadeProjectile {
Expand Down
6 changes: 6 additions & 0 deletions Source/FeatureHelpers/EntityClassifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ struct EntityTypeInfo {
return EntityBaseTypeInfo<cs2::C_BaseCSGrenadeProjectile>::isBaseOf(typeIndex);
}

template <typename EntityType>
[[nodiscard]] constexpr bool is() const noexcept
{
return typeIndex == indexOf<EntityType>();
}

template <typename EntityType>
[[nodiscard]] static constexpr auto indexOf() noexcept
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class GrenadeProjectileOutlineGlow {

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));
}
auto&& condition = context.condition();
if (!condition.shouldRun() || !condition.shouldGlowGrenadeProjectile(entityTypeInfo, grenadeProjectile))
return;

using namespace grenade_projectile_outline_glow_params;
grenadeProjectile.applyGlowRecursively(getColor(entityTypeInfo).setAlpha(kColorAlpha));
}

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

#include <utility>

#include <FeatureHelpers/EntityClassifier.h>
#include <GameClasses/SmokeGrenadeProjectile.h>

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

[[nodiscard]] bool shouldRun() const noexcept
{
return context.state().enabled;
}

[[nodiscard]] bool shouldGlowGrenadeProjectile(EntityTypeInfo entityTypeInfo, auto&& grenadeProjectile) const noexcept
{
return !entityTypeInfo.is<cs2::C_SmokeGrenadeProjectile>() || !grenadeProjectile.template as<SmokeGrenadeProjectile>().didSmokeEffect().valueOr(false);
}

private:
Context context;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "GrenadeProjectileOutlineGlowCondition.h"

template <typename HookContext>
class GrenadeProjectileOutlineGlowContext {
public:
Expand All @@ -13,6 +15,11 @@ class GrenadeProjectileOutlineGlowContext {
return hookContext.featuresStates().visualFeaturesStates.grenadeProjectileOutlineGlowState;
}

[[nodiscard]] decltype(auto) condition() const noexcept
{
return hookContext.template make<GrenadeProjectileOutlineGlowCondition<GrenadeProjectileOutlineGlowContext>>();
}

private:
HookContext& hookContext;
};
6 changes: 6 additions & 0 deletions Source/GameClasses/BaseEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class BaseEntity {
{
}

template <template <typename> typename T>
[[nodiscard]] decltype(auto) as() const noexcept
{
return hookContext.template make<T>(static_cast<typename T<HookContext>::RawType*>(entity));
}

[[nodiscard]] decltype(auto) renderComponent() const noexcept
{
return hookContext.template make<RenderComponent>(deps().offsetToRenderComponent.of(entity).valueOr(nullptr));
Expand Down
11 changes: 11 additions & 0 deletions Source/GameClasses/OffsetTypes/SmokeGrenadeProjectileOffset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <cstdint>

#include <CS2/Classes/Entities/GrenadeProjectiles.h>
#include <Utils/FieldOffset.h>

template <typename FieldType, typename OffsetType>
using SmokeGrenadeProjectileOffset = FieldOffset<cs2::C_SmokeGrenadeProjectile, FieldType, OffsetType>;

using OffsetToDidSmokeEffect = SmokeGrenadeProjectileOffset<cs2::C_SmokeGrenadeProjectile::m_bDidSmokeEffect, std::int32_t>;
24 changes: 24 additions & 0 deletions Source/GameClasses/SmokeGrenadeProjectile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <CS2/Classes/Entities/GrenadeProjectiles.h>

template <typename HookContext>
class SmokeGrenadeProjectile {
public:
SmokeGrenadeProjectile(HookContext& hookContext, cs2::C_SmokeGrenadeProjectile* smokeGrenadeProjectile) noexcept
: hookContext{hookContext}
, smokeGrenadeProjectile{smokeGrenadeProjectile}
{
}

using RawType = cs2::C_SmokeGrenadeProjectile;

[[nodiscard]] auto didSmokeEffect() const noexcept
{
return hookContext.gameDependencies().smokeGrenadeProjectileDeps.offsetToDidSmokeEffect.of(smokeGrenadeProjectile).toOptional();
}

private:
HookContext& hookContext;
cs2::C_SmokeGrenadeProjectile* smokeGrenadeProjectile;
};
3 changes: 3 additions & 0 deletions Source/GameDependencies/GameDependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "SceneObjectDeps.h"
#include "SceneObjectUpdaterDeps.h"
#include "SceneSystemDeps.h"
#include "SmokeGrenadeProjectileDeps.h"
#include "TopLevelWindowDeps.h"
#include "WeaponDeps.h"
#include "WeaponServicesDeps.h"
Expand Down Expand Up @@ -67,6 +68,7 @@ struct GameDependencies {
, sceneObjectDeps{memoryPatterns.sceneObjectPatterns()}
, sceneObjectUpdaterDeps{memoryPatterns.sceneObjectUpdaterPatterns()}
, sceneSystemDeps{memoryPatterns.sceneSystemPatterns()}
, smokeGrenadeProjectileDeps{memoryPatterns.smokeGrenadeProjectilePatterns()}
, topLevelWindowDeps{memoryPatterns.topLevelWindowPatterns()}
, weaponDeps{memoryPatterns.weaponPatterns()}
, weaponServicesDeps{memoryPatterns.weaponServicesPatterns()}
Expand Down Expand Up @@ -113,6 +115,7 @@ struct GameDependencies {
SceneObjectDeps sceneObjectDeps;
SceneObjectUpdaterDeps sceneObjectUpdaterDeps;
SceneSystemDeps sceneSystemDeps;
SmokeGrenadeProjectileDeps smokeGrenadeProjectileDeps;
TopLevelWindowDeps topLevelWindowDeps;
WeaponDeps weaponDeps;
WeaponServicesDeps weaponServicesDeps;
Expand Down
13 changes: 13 additions & 0 deletions Source/GameDependencies/SmokeGrenadeProjectileDeps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <GameClasses/OffsetTypes/SmokeGrenadeProjectileOffset.h>

struct SmokeGrenadeProjectileDeps {
template <typename SmokeGrenadeProjectilePatterns>
explicit SmokeGrenadeProjectileDeps(const SmokeGrenadeProjectilePatterns& smokeGrenadeProjectilePatterns) noexcept
: offsetToDidSmokeEffect{smokeGrenadeProjectilePatterns.offsetToDidSmokeEffect()}
{
}

OffsetToDidSmokeEffect offsetToDidSmokeEffect;
};
1 change: 1 addition & 0 deletions Source/MemoryPatterns/Linux/LinuxPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "SceneObjectUpdaterPatternsLinux.h"
#include "SceneSystemPatternsLinux.h"
#include "SdlPatternsLinux.h"
#include "SmokeGrenadeProjectilePatternsLinux.h"
#include "SoundSystemPatternsLinux.h"
#include "TopLevelWindowPatternsLinux.h"
#include "WeaponPatternsLinux.h"
Expand Down
14 changes: 14 additions & 0 deletions Source/MemoryPatterns/Linux/SmokeGrenadeProjectilePatternsLinux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <GameClasses/OffsetTypes/SmokeGrenadeProjectileOffset.h>
#include <MemorySearch/BytePatternLiteral.h>

template <typename PatternFinders>
struct SmokeGrenadeProjectilePatterns {
const PatternFinders& patternFinders;

[[nodiscard]] OffsetToDidSmokeEffect offsetToDidSmokeEffect() const noexcept
{
return patternFinders.clientPatternFinder("85 F6 75 ? 80 BF ? ? ? ?"_pat).add(6).template readOffset<OffsetToDidSmokeEffect>();
}
};
1 change: 1 addition & 0 deletions Source/MemoryPatterns/MemoryPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct MemoryPatterns {
MEMORY_PATTERNS(SceneObjectUpdaterPatterns, sceneObjectUpdaterPatterns)
MEMORY_PATTERNS(SceneSystemPatterns, sceneSystemPatterns)
MEMORY_PATTERNS(SdlPatterns, sdlPatterns)
MEMORY_PATTERNS(SmokeGrenadeProjectilePatterns, smokeGrenadeProjectilePatterns)
MEMORY_PATTERNS(SoundSystemPatterns, soundSystemPatterns)
MEMORY_PATTERNS(TopLevelWindowPatterns, topLevelWindowPatterns)
MEMORY_PATTERNS(WeaponPatterns, weaponPatterns)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <GameClasses/OffsetTypes/SmokeGrenadeProjectileOffset.h>
#include <MemorySearch/BytePatternLiteral.h>

template <typename PatternFinders>
struct SmokeGrenadeProjectilePatterns {
const PatternFinders& patternFinders;

[[nodiscard]] OffsetToDidSmokeEffect offsetToDidSmokeEffect() const noexcept
{
return patternFinders.clientPatternFinder("85 D2 75 ? 38 91 ? ? ? ?"_pat).add(6).template readOffset<OffsetToDidSmokeEffect>();
}
};
1 change: 1 addition & 0 deletions Source/MemoryPatterns/Windows/WindowsPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "SceneObjectUpdaterPatternsWindows.h"
#include "SceneSystemPatternsWindows.h"
#include "SdlPatternWindows.h"
#include "SmokeGrenadeProjectilePatternsWindows.h"
#include "SoundSystemPatternsWindows.h"
#include "TopLevelWindowPatternsWindows.h"
#include "WeaponPatternsWindows.h"
Expand Down
5 changes: 5 additions & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<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\GrenadeProjectileOutlineGlowCondition.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" />
Expand Down Expand Up @@ -217,6 +218,7 @@
<ClInclude Include="GameClasses\OffsetTypes\RenderComponentOffset.h" />
<ClInclude Include="GameClasses\OffsetTypes\SceneObjectOffset.h" />
<ClInclude Include="GameClasses\OffsetTypes\SceneObjectUpdaterOffset.h" />
<ClInclude Include="GameClasses\OffsetTypes\SmokeGrenadeProjectileOffset.h" />
<ClInclude Include="GameClasses\PlayerController.h" />
<ClInclude Include="GameClasses\FileNameSymbolTable.h" />
<ClInclude Include="GameClasses\FileSystem.h" />
Expand Down Expand Up @@ -268,6 +270,7 @@
<ClInclude Include="GameClasses\SceneObjectUpdater.h" />
<ClInclude Include="GameClasses\SceneObjectUpdaters.h" />
<ClInclude Include="GameClasses\SceneSystem.h" />
<ClInclude Include="GameClasses\SmokeGrenadeProjectile.h" />
<ClInclude Include="GameClasses\TopLevelWindow.h" />
<ClInclude Include="GameDependencies\ConVarDeps.h" />
<ClInclude Include="GameDependencies\ConVars.h" />
Expand Down Expand Up @@ -300,6 +303,7 @@
<ClInclude Include="GameDependencies\SceneObjectDeps.h" />
<ClInclude Include="GameDependencies\SceneObjectUpdaterDeps.h" />
<ClInclude Include="GameDependencies\SceneSystemDeps.h" />
<ClInclude Include="GameDependencies\SmokeGrenadeProjectileDeps.h" />
<ClInclude Include="GameDependencies\TopLevelWindowDeps.h" />
<ClInclude Include="GameDependencies\WeaponDeps.h" />
<ClInclude Include="GameDependencies\WeaponServicesDeps.h" />
Expand Down Expand Up @@ -360,6 +364,7 @@
<ClInclude Include="MemoryPatterns\Windows\SceneObjectUpdaterPatternsWindows.h" />
<ClInclude Include="MemoryPatterns\Windows\SceneSystemPatternsWindows.h" />
<ClInclude Include="MemoryPatterns\Windows\SdlPatternWindows.h" />
<ClInclude Include="MemoryPatterns\Windows\SmokeGrenadeProjectilePatternsWindows.h" />
<ClInclude Include="MemoryPatterns\Windows\SoundSystemPatternsWindows.h" />
<ClInclude Include="MemoryPatterns\Windows\TopLevelWindowPatternsWindows.h" />
<ClInclude Include="MemoryPatterns\Windows\WeaponPatternsWindows.h" />
Expand Down
15 changes: 15 additions & 0 deletions Source/Osiris.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,21 @@
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlow.h">
<Filter>Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow</Filter>
</ClInclude>
<ClInclude Include="GameClasses\OffsetTypes\SmokeGrenadeProjectileOffset.h">
<Filter>GameClasses\OffsetTypes</Filter>
</ClInclude>
<ClInclude Include="GameDependencies\SmokeGrenadeProjectileDeps.h">
<Filter>GameDependencies</Filter>
</ClInclude>
<ClInclude Include="MemoryPatterns\Windows\SmokeGrenadeProjectilePatternsWindows.h">
<Filter>MemoryPatterns\Windows</Filter>
</ClInclude>
<ClInclude Include="GameClasses\SmokeGrenadeProjectile.h">
<Filter>GameClasses</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow\GrenadeProjectileOutlineGlowCondition.h">
<Filter>Features\Visuals\OutlineGlow\GrenadeProjectileOutlineGlow</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="UI\Panorama\CreateGUI.js">
Expand Down

0 comments on commit 543678a

Please sign in to comment.