Skip to content

Commit

Permalink
Add GameDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Jun 14, 2024
1 parent 989c812 commit efdc020
Show file tree
Hide file tree
Showing 77 changed files with 759 additions and 643 deletions.
18 changes: 9 additions & 9 deletions Source/FeatureHelpers/ConVarAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

#include <optional>

#include <GameClasses/Implementation/ConVarImpl.h>
#include "ConVars.h"
#include <GameDependencies/ConVarDeps.h>
#include <GameDependencies/ConVars.h>

struct ConVarAccessorState {
std::optional<bool> mp_teammates_are_enemies;
};

struct ConVarAccessor {
explicit ConVarAccessor(const ConVars& conVars, const ConVarImpl& conVarImpl, ConVarAccessorState& state) noexcept
explicit ConVarAccessor(const ConVars& conVars, const ConVarDeps& conVarDeps, ConVarAccessorState& state) noexcept
: conVars{conVars}
, conVarImpl{conVarImpl}
, conVarDeps{conVarDeps}
, state{state}
{
}
Expand All @@ -29,7 +29,7 @@ struct ConVarAccessor {
if (!conVar)
return false;

if (!conVarImpl.offsetToConVarValue || !conVarIsBool(conVar))
if (!conVarDeps.offsetToConVarValue || !conVarIsBool(conVar))
return false;

state.mp_teammates_are_enemies = readConVarValue<bool>(conVar);
Expand All @@ -49,19 +49,19 @@ struct ConVarAccessor {
[[nodiscard]] T readConVarValue(cs2::ConVar* conVar) const noexcept
{
T value;
std::memcpy(&value, conVarImpl.offsetToConVarValue.of(conVar).get(), sizeof(value));
std::memcpy(&value, conVarDeps.offsetToConVarValue.of(conVar).get(), sizeof(value));
return value;
}

[[nodiscard]] bool conVarIsBool(cs2::ConVar* conVar) const noexcept
{
if (!conVarImpl.offsetToConVarValueType)
if (!conVarDeps.offsetToConVarValueType)
return true;

return cs2::ConVarValueType{*conVarImpl.offsetToConVarValueType.of(conVar).get()} == cs2::ConVarValueType::boolean;
return cs2::ConVarValueType{*conVarDeps.offsetToConVarValueType.of(conVar).get()} == cs2::ConVarValueType::boolean;
}

const ConVars& conVars;
const ConVarImpl& conVarImpl;
const ConVarDeps& conVarDeps;
ConVarAccessorState& state;
};
37 changes: 0 additions & 37 deletions Source/FeatureHelpers/FeatureHelpers.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#pragma once

#include "ConVars.h"
#include "EntitiesVMTs.h"
#include <Helpers/HudProvider.h>
#include <Helpers/PanoramaTransformFactory.h>
#include "HudInWorldPanelContainer.h"
#include "MainMenuProvider.h"
#include "PanelConfigurator.h"
#include "Sound/SoundWatcherState.h"
#include "StylePropertiesSymbolsAndVMTs.h"
Expand All @@ -14,40 +11,6 @@
#include "WorldToClipSpaceConverter.h"

struct FeatureHelpers {
explicit FeatureHelpers(const MemoryPatterns& memoryPatterns, const VmtFinder& panoramaVmtFinder, const VmtFinder& clientVmtFinder) noexcept
: hudProvider{memoryPatterns.clientPatterns()}
, globalVars{memoryPatterns.clientPatterns().globalVars()}
, transformFactory{memoryPatterns.clientPatterns()}
, worldtoClipSpaceConverter{memoryPatterns.clientPatterns()}
, viewToProjectionMatrix{memoryPatterns.clientPatterns()}
, stylePropertiesSymbolsAndVMTs{StylePropertySymbolMap{memoryPatterns.panelStylePatterns().stylePropertiesSymbols()}, panoramaVmtFinder}
, mainMenuProvider{memoryPatterns.clientPatterns()}
, localPlayerController{memoryPatterns.clientPatterns().localPlayerController()}
, entitiesVMTs{clientVmtFinder}
, plantedC4s{memoryPatterns.clientPatterns().plantedC4s()}
, soundChannels{memoryPatterns.soundSystemPatterns().soundChannels()}
, fileSystem{memoryPatterns.fileSystemPatterns().fileSystem()}
{
}

[[nodiscard]] PanelConfigurator panelConfigurator() const noexcept
{
return PanelConfigurator{PanelStylePropertyFactory{stylePropertiesSymbolsAndVMTs}};
}

HudProvider hudProvider;
cs2::GlobalVars** globalVars;
PanoramaTransformFactory transformFactory;
WorldToClipSpaceConverter worldtoClipSpaceConverter;
HudInWorldPanelContainer hudInWorldPanelContainer;
ViewToProjectionMatrix viewToProjectionMatrix;
StylePropertiesSymbolsAndVMTs stylePropertiesSymbolsAndVMTs;
SoundWatcherState soundWatcherState;
MainMenuProvider mainMenuProvider;
cs2::CCSPlayerController** localPlayerController;
EntitiesVMTs entitiesVMTs;
cs2::CUtlVector<cs2::CPlantedC4*>* plantedC4s;
cs2::SoundChannels** soundChannels;
cs2::CBaseFileSystem** fileSystem;
std::optional<ConVars> conVars;
};
11 changes: 7 additions & 4 deletions Source/FeatureHelpers/HudInWorldPanelContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ class HudInWorldPanelContainer {
PanoramaUiEngine::onDeletePanel(containerPanel.getHandle());
}

[[nodiscard]] PanoramaUiPanel get(HudProvider hudProvider, PanelConfigurator panelConfigurator) noexcept
[[nodiscard]] PanoramaUiPanel get(HudOptional hud, PanelConfigurator panelConfigurator) noexcept
{
if (const auto container = containerPanel.get())
return container;
return createPanel(hudProvider, panelConfigurator);
return createPanel(hud, panelConfigurator);
}

private:
[[nodiscard]] PanoramaUiPanel createPanel(HudProvider hudProvider, PanelConfigurator panelConfigurator) noexcept
[[nodiscard]] PanoramaUiPanel createPanel(HudOptional hud, PanelConfigurator panelConfigurator) noexcept
{
if (const auto hudReticle = hudProvider.getHudReticle()) {
if (!hud)
return PanoramaUiPanel{nullptr};

if (const auto hudReticle = hud->getHudReticle()) {
if (const auto panel = Panel::create("", hudReticle)) {
if (const auto style{PanoramaUiPanel{panel->uiPanel}.getStyle()})
panelConfigurator.panelStyle(*style).fitParent();
Expand Down
4 changes: 2 additions & 2 deletions Source/FeatureHelpers/PanelStyleSetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <CS2/Classes/Color.h>
#include <CS2/Classes/Panorama.h>
#include "GameClasses/Implementation/PanelStyleImpl.h"
#include <GameDependencies/PanelStyleDeps.h>
#include "PanelStylePropertyFactory.h"

struct ImageShadowParams;
Expand All @@ -20,7 +20,7 @@ class PanelStyleSetter {
if (!styleProperty)
return;

if (const auto setPropertyFn{PanelStyleImpl::instance().setProperty})
if (const auto setPropertyFn{PanelStyleDeps::instance().setProperty})
setPropertyFn(thisptr, styleProperty, true);
}

Expand Down
15 changes: 11 additions & 4 deletions Source/FeatureHelpers/Sound/SoundWatcherImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ class SoundWatcherImpl<SoundWatcherImplState<Sounds...>> {

void update() noexcept
{
constexpr auto kCrucialDependencies{HookDependenciesMask{}.set<CurTime>().set<SoundChannels>()};
constexpr auto kCrucialDependencies{HookDependenciesMask{}.set<SoundChannels>()};
if (!hookDependencies.requestDependencies(kCrucialDependencies))
return;

const auto curtime = hookDependencies.getDependency<CurTime>();
const auto globalVars = hookDependencies.globalVars();
if (!globalVars)
return;

const auto curtime = globalVars->curtime();
if (!curtime)
return;

auto& soundChannels = hookDependencies.getDependency<SoundChannels>();
(removeExpiredSounds<Sounds>(soundChannels, curtime), ...);
collectNewSounds(soundChannels, curtime);
(removeExpiredSounds<Sounds>(soundChannels, *curtime), ...);
collectNewSounds(soundChannels, *curtime);
}

template <typename Sound>
Expand Down
5 changes: 2 additions & 3 deletions Source/FeatureHelpers/ViewToProjectionMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#include <CS2/Constants/AspectRatio.h>

struct ViewToProjectionMatrix {
template <typename ClientPatterns>
explicit ViewToProjectionMatrix(const ClientPatterns& clientPatterns) noexcept
: viewToProjectionMatrix{clientPatterns.viewToProjectionMatrix()}
explicit ViewToProjectionMatrix(const cs2::VMatrix* viewToProjectionMatrix) noexcept
: viewToProjectionMatrix{viewToProjectionMatrix}
{
}

Expand Down
5 changes: 2 additions & 3 deletions Source/FeatureHelpers/WorldToClipSpaceConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#include <CS2/Classes/VMatrix.h>

struct WorldToClipSpaceConverter {
template <typename ClientPatterns>
explicit WorldToClipSpaceConverter(const ClientPatterns& clientPatterns) noexcept
: worldToProjectionMatrix{clientPatterns.worldToProjectionMatrix()}
explicit WorldToClipSpaceConverter(const cs2::VMatrix* worldToProjectionMatrix) noexcept
: worldToProjectionMatrix{worldToProjectionMatrix}
{
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Features/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Features {

[[nodiscard]] VisualFeatures visualFeatures() const noexcept
{
return VisualFeatures{states.visualFeaturesStates, helpers, hooks.viewRenderHook};
return VisualFeatures{hookDependencies, states.visualFeaturesStates, helpers, hooks.viewRenderHook};
}

FeaturesStates& states;
Expand Down
22 changes: 16 additions & 6 deletions Source/Features/Hud/BombTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ struct BombTimerToggle : FeatureToggleOff<BombTimerToggle> {

class BombTimer {
public:
BombTimer(BombTimerState& state, HookDependencies& hookDependencies, HudProvider hudProvider) noexcept
BombTimer(BombTimerState& state, HookDependencies& hookDependencies, HudOptional hud) noexcept
: state{state}
, hookDependencies{hookDependencies}
, hudProvider{hudProvider}
, hud{hud}
{
}

Expand All @@ -54,14 +54,21 @@ class BombTimer {
updatePanelHandles();
hideBombStatusPanel();

if (!hookDependencies.requestDependency<PlantedC4>() || !hookDependencies.requestDependency<CurTime>()) {
const auto globalVars = hookDependencies.globalVars();
if (!globalVars || !hookDependencies.requestDependency<PlantedC4>()) {
state.hideBombTimerPanel();
return;
}

const auto curtime = globalVars->curtime();
if (!curtime) {
state.hideBombTimerPanel();
return;
}

const PlantedC4 bomb{hookDependencies.getDependency<PlantedC4>()};

if (const auto timeToExplosion = bomb.getTimeToExplosion(hookDependencies.getDependency<CurTime>()); timeToExplosion > 0.0f) {
if (const auto timeToExplosion = bomb.getTimeToExplosion(*curtime); timeToExplosion > 0.0f) {
showBombTimerPanel(bomb.getBombSiteIconUrl(), timeToExplosion);
} else {
state.restorePanels();
Expand Down Expand Up @@ -92,7 +99,10 @@ class BombTimer {
if (state.scoreAndTimeAndBombPanel.get())
return;

const auto hudTeamCounter = hudProvider.findChildInLayoutFile(cs2::HudTeamCounter);
if (!hud)
return;

const auto hudTeamCounter = hud->findChildInLayoutFile(cs2::HudTeamCounter);
if (!hudTeamCounter)
return;

Expand Down Expand Up @@ -160,5 +170,5 @@ R"(

BombTimerState& state;
HookDependencies& hookDependencies;
HudProvider hudProvider;
HudOptional hud;
};
31 changes: 22 additions & 9 deletions Source/Features/Hud/DefusingAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ struct DefusingAlertToggle : FeatureToggleOff<DefusingAlertToggle> {

class DefusingAlert {
public:
DefusingAlert(DefusingAlertState& state, HookDependencies& hookDependencies, HudProvider hudProvider, PanelConfigurator panelConfigurator) noexcept
DefusingAlert(DefusingAlertState& state, HookDependencies& hookDependencies, HudOptional hud) noexcept
: state{state}
, hookDependencies{hookDependencies}
, hudProvider{hudProvider}
, panelConfigurator{panelConfigurator}
, hud{hud}
{
}

Expand All @@ -56,7 +55,7 @@ class DefusingAlert {

updatePanelHandles();

if (!hookDependencies.requestDependencies(HookDependenciesMask{}.set<CurTime>().set<PlantedC4>()))
if (!hookDependencies.requestDependencies(HookDependenciesMask{}.set<PlantedC4>()))
return;

const PlantedC4 bomb{hookDependencies.getDependency<PlantedC4>()};
Expand All @@ -65,15 +64,27 @@ class DefusingAlert {
return;
}

const auto timeToEnd = bomb.getTimeToDefuseEnd(hookDependencies.getDependency<CurTime>());
const auto globalVars = hookDependencies.globalVars();
if (!globalVars) {
state.hideDefusingAlert();
return;
}

const auto curtime = globalVars->curtime();
if (!curtime) {
state.hideDefusingAlert();
return;
}

const auto timeToEnd = bomb.getTimeToDefuseEnd(*curtime);
if (timeToEnd > 0.0f) {
if (const auto defusingAlertContainer = state.defusingAlertContainerPanel.get())
defusingAlertContainer.setVisible(true);

if (const auto defusingTimer = state.defusingTimerPanel.get()) {
PanoramaLabel{ static_cast<cs2::CLabel*>(defusingTimer.getClientPanel()) }.setTextInternal(DefusingCountdownStringBuilder{}(timeToEnd), 0, true);
if (const auto style = defusingTimer.getStyle())
panelConfigurator.panelStyle(*style).setSimpleForegroundColor(getTimerColor(bomb));
hookDependencies.getDependency<PanelConfigurator>().panelStyle(*style).setSimpleForegroundColor(getTimerColor(bomb));
}
} else {
state.hideDefusingAlert();
Expand All @@ -93,7 +104,10 @@ class DefusingAlert {
if (state.defusingTimerPanel.get())
return;

const auto hudTeamCounter = hudProvider.findChildInLayoutFile(cs2::HudTeamCounter);
if (!hud)
return;

const auto hudTeamCounter = hud->findChildInLayoutFile(cs2::HudTeamCounter);
if (!hudTeamCounter)
return;

Expand Down Expand Up @@ -132,6 +146,5 @@ R"(

DefusingAlertState& state;
HookDependencies& hookDependencies;
HudProvider hudProvider;
PanelConfigurator panelConfigurator;
HudOptional hud;
};
7 changes: 3 additions & 4 deletions Source/Features/Hud/HudFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
struct HudFeatures {
[[nodiscard]] BombTimer bombTimer() const noexcept
{
return BombTimer{states.bombTimerState, hookDependencies, helpers.hudProvider};
return BombTimer{states.bombTimerState, hookDependencies, hookDependencies.hud()};
}

[[nodiscard]] BombTimerToggle bombTimerToggle() const noexcept
Expand All @@ -24,8 +24,7 @@ struct HudFeatures {
return DefusingAlert{
states.defusingAlertState,
hookDependencies,
helpers.hudProvider,
helpers.panelConfigurator()
hookDependencies.hud()
};
}

Expand All @@ -36,7 +35,7 @@ struct HudFeatures {

[[nodiscard]] KillfeedPreserver killfeedPreserver() const noexcept
{
return KillfeedPreserver{states.killfeedPreserverState, hookDependencies, helpers.hudProvider, hookDependencies.offsets().gameRules.gameRules};
return KillfeedPreserver{states.killfeedPreserverState, hookDependencies, hookDependencies.hud()};
}

[[nodiscard]] KillfeedPreserveToggle killfeedPreserveToggle() const noexcept
Expand Down
Loading

0 comments on commit efdc020

Please sign in to comment.