Skip to content

Commit d614927

Browse files
Make HookContext default-constructible
1 parent c4e9980 commit d614927

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Source/GlobalContext/GlobalContext.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class GlobalContext {
4141
{
4242
}
4343

44+
using Complete = FullGlobalContext;
45+
4446
static void initializeInstance() noexcept
4547
{
4648
if (!globalContext.isInitialized()) {
@@ -76,18 +78,17 @@ class GlobalContext {
7678
if (initInProgress)
7779
initCompleteContextFromGameThread();
7880

79-
auto& fullCtx = fullContext();
80-
HookContext hookContext{fullCtx};
81+
HookContext<GlobalContext> hookContext;
8182

8283
if (initInProgress)
8384
finishInit(hookContext);
8485

85-
return PeepEventsHookResult{fullCtx.hooks.peepEventsHook.original};
86+
return PeepEventsHookResult{hookContext.hooks().peepEventsHook.original};
8687
}
8788

8889
[[nodiscard]] std::uint64_t playerPawnSceneObjectUpdater(cs2::C_CSPlayerPawn* entity, void* unknown, bool unknownBool) noexcept
8990
{
90-
HookContext hookContext{fullContext()};
91+
HookContext<GlobalContext> hookContext;
9192
const auto originalReturnValue = hookContext.featuresStates().visualFeaturesStates.modelGlowState.originalPlayerPawnSceneObjectUpdater(entity, unknown, unknownBool);
9293

9394
auto&& playerPawn = hookContext.make<PlayerPawn>(entity);
@@ -101,7 +102,7 @@ class GlobalContext {
101102

102103
[[nodiscard]] std::uint64_t weaponSceneObjectUpdater(cs2::C_CSWeaponBase* weapon, void* unknown, bool unknownBool) noexcept
103104
{
104-
HookContext hookContext{fullContext()};
105+
HookContext<GlobalContext> hookContext;
105106
const auto originalReturnValue = hookContext.featuresStates().visualFeaturesStates.modelGlowState.originalWeaponSceneObjectUpdater(weapon, unknown, unknownBool);
106107
if (auto&& c4 = hookContext.make<BaseWeapon>(weapon).template cast<C4>())
107108
hookContext.make<ModelGlow>().updateInSceneObjectUpdater()(DroppedBombModelGlow{hookContext}, c4.baseWeapon(), EntityTypeInfo{});
@@ -112,7 +113,7 @@ class GlobalContext {
112113

113114
[[nodiscard]] float getViewmodelFovHook(cs2::ClientModeCSNormal* clientMode) noexcept
114115
{
115-
HookContext hookContext{fullContext()};
116+
HookContext<GlobalContext> hookContext;
116117
const auto originalFov = hookContext.hooks().originalGetViewmodelFov(clientMode);
117118
if (auto&& viewmodelMod = hookContext.template make<ViewmodelMod>(); viewmodelMod.shouldModifyViewmodelFov())
118119
return viewmodelMod.viewmodelFov();
@@ -121,7 +122,7 @@ class GlobalContext {
121122

122123
[[nodiscard]] UnloadFlag onRenderStartHook(cs2::CViewRender* viewRender) noexcept
123124
{
124-
HookContext hookContext{fullContext()};
125+
HookContext<GlobalContext> hookContext;
125126
fullContext().hooks.viewRenderHook.getOriginalOnRenderStart()(viewRender);
126127
hookContext.make<InWorldPanels>().updateState();
127128
SoundWatcher<decltype(hookContext)> soundWatcher{fullContext().soundWatcherState, hookContext};

Source/HookContext/HookContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ struct GlowSceneObjectsState;
2727
struct Hooks;
2828
class EntityClassifier;
2929

30-
template <typename FullGlobalContext>
30+
template <typename GlobalContext>
3131
struct HookContext {
32-
HookContext(FullGlobalContext& fullGlobalContext) noexcept
33-
: fullGlobalContext{fullGlobalContext}
32+
HookContext() noexcept
33+
: fullGlobalContext{GlobalContext::instance().fullContext()}
3434
{
3535
}
3636

@@ -258,7 +258,7 @@ struct HookContext {
258258
return nullptr;
259259
}
260260

261-
FullGlobalContext& fullGlobalContext;
261+
GlobalContext::Complete& fullGlobalContext;
262262
InWorldPanelsPerHookState _inWorldPanelsPerHookState;
263263
PlayerInfoPanelCachePerHookState _playerInfoPanelCachePerHookState;
264264
};

0 commit comments

Comments
 (0)