Skip to content

Commit

Permalink
Add HostageServices class
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Oct 1, 2024
1 parent c5f2f8d commit e8a0c03
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
28 changes: 28 additions & 0 deletions Source/GameClasses/HostageServices.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <CS2/Classes/CCSPlayer_HostageServices.h>
#include "EntitySystem.h"

template <typename HookContext>
class HostageServices {
public:
HostageServices(HookContext& hookContext, cs2::CCSPlayer_HostageServices* hostageServices) noexcept
: hookContext{hookContext}
, hostageServices{hostageServices}
{
}

[[nodiscard]] bool hasCarriedHostage() const noexcept
{
return hookContext.template make<EntitySystem>().getEntityFromHandle(deps().offsetToCarriedHostage.of(hostageServices).valueOr(cs2::CEntityHandle{cs2::INVALID_EHANDLE_INDEX})) != nullptr;
}

private:
[[nodiscard]] const auto& deps() const noexcept
{
return hookContext.gameDependencies().hostageServicesDeps;
}

HookContext& hookContext;
cs2::CCSPlayer_HostageServices* hostageServices;
};
16 changes: 12 additions & 4 deletions Source/GameClasses/PlayerPawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "BaseEntity.h"
#include "GameSceneNode.h"
#include "HostageServices.h"
#include "PlayerWeapons.h"
#include "WeaponServices.h"

Expand Down Expand Up @@ -110,10 +111,7 @@ class PlayerPawn {

[[nodiscard]] bool isRescuingHostage() const noexcept
{
const auto hostageServices = hookContext.gameDependencies().playerPawnDeps.offsetToHostageServices.of(playerPawn).valueOr(nullptr);
if (!hostageServices)
return false;
return hookContext.template make<EntitySystem>().getEntityFromHandle(hookContext.gameDependencies().hostageServicesDeps.offsetToCarriedHostage.of(hostageServices).valueOr(cs2::CEntityHandle{cs2::INVALID_EHANDLE_INDEX})) != nullptr;
return hostageServices().hasCarriedHostage();
}

[[nodiscard]] float getRemainingFlashBangTime() const noexcept
Expand All @@ -135,6 +133,16 @@ class PlayerPawn {
}

private:
[[nodiscard]] decltype(auto) hostageServices() const noexcept
{
return hookContext.template make<HostageServices>(deps().offsetToHostageServices.of(playerPawn).valueOr(nullptr));
}

[[nodiscard]] const auto& deps() const noexcept
{
return hookContext.gameDependencies().playerPawnDeps;
}

[[nodiscard]] static cs2::Color getColorOfHealthFraction(float healthFraction) noexcept
{
return color::HSBtoRGB(color::kRedHue + (color::kGreenHue - color::kRedHue) * healthFraction, 0.7f, 1.0f);
Expand Down
1 change: 1 addition & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<ClInclude Include="GameClasses\ClientPanel.h" />
<ClInclude Include="GameClasses\EntitySystem.h" />
<ClInclude Include="GameClasses\GameSceneNode.h" />
<ClInclude Include="GameClasses\HostageServices.h" />
<ClInclude Include="GameClasses\Hud\HudContext.h" />
<ClInclude Include="GameClasses\OffsetTypes\GlowSceneObjectOffset.h" />
<ClInclude Include="GameClasses\OffsetTypes\RenderComponentOffset.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 @@ -1640,6 +1640,9 @@
<ClInclude Include="Features\Visuals\PlayerInfoInWorld\PlayerInfoPanelTypes.h">
<Filter>Features\Visuals\PlayerInfoInWorld</Filter>
</ClInclude>
<ClInclude Include="GameClasses\HostageServices.h">
<Filter>GameClasses</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="UI\Panorama\CreateGUI.js">
Expand Down

0 comments on commit e8a0c03

Please sign in to comment.