Skip to content

Commit

Permalink
Add Hooks struct
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Oct 17, 2023
1 parent daf6588 commit 9c343f2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Source/Endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ inline int PeepEventsHook::SDL_PeepEvents(void* events, int numevents,
hudFeatures().killfeedPreserver.run();

GlobalContext::instance().panoramaGUI->run();
GlobalContext::instance().loopModeGameHook->update();
GlobalContext::instance().viewRenderHook->update();
GlobalContext::instance().hooks->loopModeGameHook.update();
GlobalContext::instance().hooks->viewRenderHook.update();
visuals().scopeOverlayRemover.updatePanelVisibility();

if (GlobalContext::instance().unloadFlag) {
const auto originalPeepEvents = GlobalContext::instance().peepEventsHook.original;
GlobalContext::instance().peepEventsHook.disable();
GlobalContext::instance().loopModeGameHook->forceUninstall();
GlobalContext::instance().viewRenderHook->forceUninstall();
GlobalContext::instance().hooks->loopModeGameHook.forceUninstall();
GlobalContext::instance().hooks->viewRenderHook.forceUninstall();
GlobalContext::destroyInstance();
return originalPeepEvents(events, numevents, action, minType, maxType);
}
Expand All @@ -48,10 +48,10 @@ inline int PeepEventsHook::SDL_PeepEvents(void* events, int numevents,
inline void* LoopModeGameHook::getWorldSession(cs2::CLoopModeGame* thisptr) noexcept
{
visuals().scopeOverlayRemover.getWorldSessionHook(RETURN_ADDRESS());
return GlobalContext::instance().loopModeGameHook->originalGetWorldSession(thisptr);
return GlobalContext::instance().hooks->loopModeGameHook.originalGetWorldSession(thisptr);
}

inline void ViewRenderHook::onRenderStart(cs2::CViewRender* thisptr) noexcept
{
GlobalContext::instance().viewRenderHook->originalOnRenderStart(thisptr);
GlobalContext::instance().hooks->viewRenderHook.originalOnRenderStart(thisptr);
}
10 changes: 5 additions & 5 deletions Source/GlobalContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <optional>

#include "CS2/Constants/DllNames.h"
#include "Hooks/Hooks.h"
#include "Hooks/PeepEventsHook.h"
#include "Hooks/ViewRenderHook.h"

Expand All @@ -23,8 +24,7 @@ struct GlobalContext {
PatternFinder<PatternNotFoundLogger> clientPatternFinder{ DynamicLibrary{cs2::CLIENT_DLL}.getCodeSection().raw(), PatternNotFoundLogger{} };
PatternFinder<PatternNotFoundLogger> panoramaPatternFinder{ DynamicLibrary{cs2::PANORAMA_DLL}.getCodeSection().raw(), PatternNotFoundLogger{} };
std::optional<GameClassImplementations> gameClasses;
std::optional<LoopModeGameHook> loopModeGameHook;
std::optional<ViewRenderHook> viewRenderHook;
std::optional<Hooks> hooks;
std::optional<Features> features;
std::optional<PanoramaGUI> panoramaGUI;

Expand Down Expand Up @@ -52,9 +52,9 @@ struct GlobalContext {
return;

gameClasses.emplace();
loopModeGameHook.emplace(VmtLengthCalculator{ DynamicLibrary{cs2::CLIENT_DLL}.getCodeSection(), DynamicLibrary{cs2::CLIENT_DLL}.getVmtSection() });
viewRenderHook.emplace(VmtLengthCalculator{ DynamicLibrary{cs2::CLIENT_DLL}.getCodeSection(), DynamicLibrary{cs2::CLIENT_DLL}.getVmtSection() });
features.emplace(HudProvider{}, *loopModeGameHook);
const VmtLengthCalculator clientVmtLengthCalculator{ DynamicLibrary{cs2::CLIENT_DLL}.getCodeSection(), DynamicLibrary{cs2::CLIENT_DLL}.getVmtSection() };
hooks.emplace(clientVmtLengthCalculator);
features.emplace(HudProvider{}, hooks->loopModeGameHook, hooks->viewRenderHook);
panoramaGUI.emplace(*features, unloadFlag);

initializedFromGameThread = true;
Expand Down
17 changes: 17 additions & 0 deletions Source/Hooks/Hooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "LoopModeGameHook.h"
#include "ViewRenderHook.h"

#include <Vmt/VmtLengthCalculator.h>

struct Hooks {
explicit Hooks(const VmtLengthCalculator& clientVmtLengthCalculator) noexcept
: loopModeGameHook{ clientVmtLengthCalculator }
, viewRenderHook{ clientVmtLengthCalculator }
{
}

LoopModeGameHook loopModeGameHook;
ViewRenderHook viewRenderHook;
};
1 change: 1 addition & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<ClInclude Include="Helpers\PatternNotFoundLogger.h" />
<ClInclude Include="Helpers\PlantedC4Provider.h" />
<ClInclude Include="Helpers\UnloadFlag.h" />
<ClInclude Include="Hooks\Hooks.h" />
<ClInclude Include="Hooks\LoopModeGameHook.h" />
<ClInclude Include="Hooks\PeepEventsHook.h" />
<ClInclude Include="Hooks\ViewRenderHook.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 @@ -531,6 +531,9 @@
<ClInclude Include="Hooks\ViewRenderHook.h">
<Filter>Hooks</Filter>
</ClInclude>
<ClInclude Include="Hooks\Hooks.h">
<Filter>Hooks</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="UI\Panorama\CreateGUI.js">
Expand Down

0 comments on commit 9c343f2

Please sign in to comment.