Skip to content

Commit

Permalink
Include weapons carried by a player in player outline glow
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Sep 2, 2024
1 parent c452c8f commit f78d8cb
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Source/CS2/Classes/CCSPlayer_WeaponServices.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include "EntitySystem/CEntityHandle.h"
#include "CUtlVector.h"

namespace cs2
{

struct CCSPlayer_WeaponServices {
using m_hActiveWeapon = CEntityHandle;
using m_hMyWeapons = CUtlVector<CEntityHandle>;
};

}
16 changes: 14 additions & 2 deletions Source/Features/Visuals/PlayerOutlineGlow/PlayerOutlineGlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ class PlayerOutlineGlow {
if (!condition.shouldRun() || !condition.shouldGlowPlayer(playerPawn))
return;

applyGlow(playerPawn.baseEntity(), getColor(playerPawn));
const auto glowColor = getColor(playerPawn).setAlpha(102);
glowPlayer(playerPawn, glowColor);
glowPlayerWeapons(playerPawn, glowColor);
}

private:
void glowPlayer(auto&& playerPawn, cs2::Color glowColor) const noexcept
{
applyGlow(playerPawn.baseEntity(), glowColor);
}

void glowPlayerWeapons(auto&& playerPawn, cs2::Color glowColor) const noexcept
{
playerPawn.weapons().forEach([this, glowColor](auto&& weapon) { applyGlow(weapon, glowColor); });
}

void applyGlow(auto&& baseEntity, cs2::Color color) const noexcept
{
context.getGlowSceneObjectFor(baseEntity).apply(baseEntity, color.setAlpha(102));
context.getGlowSceneObjectFor(baseEntity).apply(baseEntity, color);
}

[[nodiscard]] cs2::Color getColor(auto&& playerPawn) const noexcept
Expand Down
1 change: 1 addition & 0 deletions Source/GameClasses/OffsetTypes/WeaponServicesOffset.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ template <typename FieldType, typename OffsetType>
using WeaponServicesOffset = FieldOffset<cs2::CCSPlayer_WeaponServices, FieldType, OffsetType>;

using OffsetToActiveWeapon = WeaponServicesOffset<cs2::CCSPlayer_WeaponServices::m_hActiveWeapon, std::int8_t>;
using OffsetToWeapons = WeaponServicesOffset<cs2::CCSPlayer_WeaponServices::m_hMyWeapons, std::int8_t>;
9 changes: 9 additions & 0 deletions Source/GameClasses/PlayerPawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <FeatureHelpers/TeamNumber.h>

#include "BaseEntity.h"
#include "PlayerWeapons.h"

class EntityFromHandleFinder;

Expand All @@ -25,6 +26,14 @@ class PlayerPawn {
return hookContext.template make<BaseEntity>(playerPawn);
}

[[nodiscard]] decltype(auto) weapons() const noexcept
{
const auto weaponServices = hookContext.gameDependencies().playerPawnDeps.offsetToWeaponServices.of(playerPawn).valueOr(nullptr);
if (!weaponServices)
return hookContext.template make<PlayerWeapons>(nullptr);
return hookContext.template make<PlayerWeapons>(hookContext.gameDependencies().weaponServicesDeps.offsetToWeapons.of(weaponServices).get());
}

[[nodiscard]] TeamNumber teamNumber() const noexcept
{
return TeamNumber{hookContext.gameDependencies().entityDeps.offsetToTeamNumber.of(playerPawn).valueOr({})};
Expand Down
38 changes: 38 additions & 0 deletions Source/GameClasses/PlayerWeapons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <CS2/Classes/CUtlVector.h>
#include <CS2/Classes/EntitySystem/CEntityHandle.h>

#include "BaseEntity.h"

class EntityFromHandleFinder;

template <typename HookContext>
class PlayerWeapons {
public:
PlayerWeapons(HookContext& hookContext, cs2::CUtlVector<cs2::CEntityHandle>* weaponHandles) noexcept
: hookContext{hookContext}
, weaponHandles{weaponHandles}
{
}

template <typename F>
void forEach(F f) const noexcept
{
if (!weaponHandles)
return;

if (!hookContext.template requestDependency<EntityFromHandleFinder>())
return;

for (int i = 0; i < weaponHandles->size; ++i) {
auto&& weaponEntity = hookContext.template make<BaseEntity>(static_cast<cs2::C_BaseEntity*>(hookContext.template getDependency<EntityFromHandleFinder>().getEntityFromHandle(weaponHandles->memory[i])));
if (weaponEntity)
f(weaponEntity);
}
}

private:
HookContext& hookContext;
cs2::CUtlVector<cs2::CEntityHandle>* weaponHandles;
};
2 changes: 2 additions & 0 deletions Source/GameDependencies/WeaponServicesDeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ struct WeaponServicesDeps {
template <typename WeaponServicesPatterns>
explicit WeaponServicesDeps(const WeaponServicesPatterns& weaponServicesPatterns) noexcept
: offsetToActiveWeapon{weaponServicesPatterns.offsetToActiveWeapon()}
, offsetToWeapons{weaponServicesPatterns.offsetToWeapons()}
{
}

OffsetToActiveWeapon offsetToActiveWeapon;
OffsetToWeapons offsetToWeapons;
};
5 changes: 5 additions & 0 deletions Source/MemoryPatterns/Linux/WeaponServicesPatternsLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ struct WeaponServicesPatterns {
{
return patternFinders.clientPatternFinder("8B 57 ? 83 FA FF 74 ? 4C 8B 0D"_pat).add(2).template readOffset<OffsetToActiveWeapon>();
}

[[nodiscard]] OffsetToWeapons offsetToWeapons() const noexcept
{
return patternFinders.clientPatternFinder("47 ? 85 C0 0F 8E ? ? ? ? 55 48 89 E5 41 54"_pat).add(1).template readOffset<OffsetToWeapons>();
}
};
5 changes: 5 additions & 0 deletions Source/MemoryPatterns/Windows/WeaponServicesPatternsWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ struct WeaponServicesPatterns {
{
return patternFinders.clientPatternFinder("? FF FF FF FF 48 85 D2 75 ? ? 8B"_pat).template readOffset<OffsetToActiveWeapon>();
}

[[nodiscard]] OffsetToWeapons offsetToWeapons() const noexcept
{
return patternFinders.clientPatternFinder("DB 48 8B F9 39 59 ?"_pat).add(6).template readOffset<OffsetToWeapons>();
}
};
1 change: 1 addition & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<ClInclude Include="GameClasses\PanoramaUiPanelMethodInvoker.h" />
<ClInclude Include="GameClasses\PlantedC4.h" />
<ClInclude Include="GameClasses\PlayerPawn.h" />
<ClInclude Include="GameClasses\PlayerWeapons.h" />
<ClInclude Include="GameClasses\RenderComponent.h" />
<ClInclude Include="GameClasses\SceneObjectUpdater.h" />
<ClInclude Include="GameClasses\SceneObjectUpdaters.h" />
Expand Down
3 changes: 3 additions & 0 deletions Source/Osiris.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,9 @@
<ClInclude Include="OutlineGlow\GlowSceneObjectContext.h">
<Filter>OutlineGlow</Filter>
</ClInclude>
<ClInclude Include="GameClasses\PlayerWeapons.h">
<Filter>GameClasses</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="UI\Panorama\CreateGUI.js">
Expand Down

0 comments on commit f78d8cb

Please sign in to comment.