diff --git a/Source/Endpoints.h b/Source/Endpoints.h index a9c12f85e2e..3fdc1953dc7 100644 --- a/Source/Endpoints.h +++ b/Source/Endpoints.h @@ -47,7 +47,7 @@ inline int PeepEventsHook::SDL_PeepEvents(void* events, int numevents, inline void* LoopModeGameHook::getWorldSession(cs2::CLoopModeGame* thisptr) noexcept { - visuals().scopeOverlayRemover.getWorldSessionHook(RETURN_ADDRESS()); + GlobalContext::instance().featureHelpers->sniperScopeBlurRemover.getWorldSessionHook(RETURN_ADDRESS()); return GlobalContext::instance().hooks->loopModeGameHook.originalGetWorldSession(thisptr); } diff --git a/Source/FeatureHelpers/FeatureHelpers.h b/Source/FeatureHelpers/FeatureHelpers.h index 5cb9c55f91b..d30ffeb40f3 100644 --- a/Source/FeatureHelpers/FeatureHelpers.h +++ b/Source/FeatureHelpers/FeatureHelpers.h @@ -9,6 +9,7 @@ #include "Hud/KillfeedPreserverHelpers.h" #include "Sound/SoundVisualizationHelpers.h" #include "ViewToProjectionMatrix.h" +#include "Visuals/SniperScopeBlurRemover.h" #include "WorldToClipSpaceConverter.h" struct FeatureHelpers { @@ -39,4 +40,5 @@ struct FeatureHelpers { PlantedC4Provider plantedC4Provider; HudInWorldPanelContainer hudInWorldPanelContainer; ViewToProjectionMatrix viewToProjectionMatrix; + SniperScopeBlurRemover sniperScopeBlurRemover; }; diff --git a/Source/FeatureHelpers/Visuals/SniperScopeBlurRemover.h b/Source/FeatureHelpers/Visuals/SniperScopeBlurRemover.h new file mode 100644 index 00000000000..713d063df91 --- /dev/null +++ b/Source/FeatureHelpers/Visuals/SniperScopeBlurRemover.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include +#include + +class SniperScopeBlurRemover { +public: + void incrementReferenceCount(LoopModeGameHook& loopModeGameHook) noexcept + { + assert(referenceCount < (std::numeric_limits::max)()); + ++referenceCount; + loopModeGameHook.incrementReferenceCount(); + } + + void decrementReferenceCount(LoopModeGameHook& loopModeGameHook) noexcept + { + assert(referenceCount > 0); + --referenceCount; + loopModeGameHook.decrementReferenceCount(); + } + + void getWorldSessionHook(ReturnAddress returnAddress) const noexcept + { + if (shouldRemoveZoomedSniperEffect(returnAddress)) + clientMode.removeZoomedSniperEffect(); + } + +private: + [[nodiscard]] bool shouldRemoveZoomedSniperEffect(ReturnAddress returnAddress) const noexcept + { + return isEnabled() && returnAddress == getWorldSessionInClientMode && clientMode; + } + + [[nodiscard]] bool isEnabled() const noexcept + { + return referenceCount > 0; + } + + ReturnAddress getWorldSessionInClientMode{ClientPatterns::getWorldSessionInClientMode()}; + ClientMode clientMode{ClientPatterns::clientMode()}; + std::size_t referenceCount{0}; +}; diff --git a/Source/Features/Features.h b/Source/Features/Features.h index 197349b3974..3d2fa6569b0 100644 --- a/Source/Features/Features.h +++ b/Source/Features/Features.h @@ -6,9 +6,11 @@ #include "Sound/SoundFeatures.h" #include "Visuals/VisualFeatures.h" +class SniperScopeBlurRemover; + struct Features { - Features(LoopModeGameHook& loopModeGameHook, ViewRenderHook& viewRenderHook, SoundWatcher& soundWatcher) noexcept - : visuals{ loopModeGameHook } + Features(SniperScopeBlurRemover& sniperScopeBlurRemover, LoopModeGameHook& loopModeGameHook, ViewRenderHook& viewRenderHook, SoundWatcher& soundWatcher) noexcept + : visuals{sniperScopeBlurRemover, loopModeGameHook } , soundFeatures{ viewRenderHook, soundWatcher } { } diff --git a/Source/Features/Visuals/ScopeOverlayRemover/ScopeOverlayRemover.h b/Source/Features/Visuals/ScopeOverlayRemover/ScopeOverlayRemover.h index f3a6f9ab04b..a7929693961 100644 --- a/Source/Features/Visuals/ScopeOverlayRemover/ScopeOverlayRemover.h +++ b/Source/Features/Visuals/ScopeOverlayRemover/ScopeOverlayRemover.h @@ -9,21 +9,17 @@ #include #include +#include #include "HudScopePanels.h" class ScopeOverlayRemover : public TogglableFeature { public: - explicit ScopeOverlayRemover(LoopModeGameHook& loopModeGameHook) noexcept - : loopModeGameHook{ loopModeGameHook } + ScopeOverlayRemover(LoopModeGameHook& loopModeGameHook, SniperScopeBlurRemover& sniperScopeBlurRemover) noexcept + : loopModeGameHook{loopModeGameHook} + , sniperScopeBlurRemover{sniperScopeBlurRemover} { } - - void getWorldSessionHook(ReturnAddress returnAddress) const noexcept - { - if (shouldRemoveZoomedSniperEffect(returnAddress)) - clientMode.removeZoomedSniperEffect(); - } void updatePanelVisibility(HudProvider hudProvider) noexcept { @@ -43,12 +39,12 @@ class ScopeOverlayRemover : public TogglableFeature { void onEnable() const noexcept { - loopModeGameHook.incrementReferenceCount(); + sniperScopeBlurRemover.incrementReferenceCount(loopModeGameHook); } void onDisable() const noexcept { - loopModeGameHook.decrementReferenceCount(); + sniperScopeBlurRemover.decrementReferenceCount(loopModeGameHook); restorePanels(); } @@ -64,20 +60,13 @@ class ScopeOverlayRemover : public TogglableFeature { *hudScope = nullptr; } - [[nodiscard]] bool shouldRemoveZoomedSniperEffect(ReturnAddress returnAddress) const noexcept - { - return isEnabled() && returnAddress == getWorldSessionInClientMode && clientMode; - } - void restorePanels() const noexcept { hudScopePanels.setPanelsVisible(true); } cs2::CPanel2D** hudScope{ ClientPatterns::hudScope() }; - ReturnAddress getWorldSessionInClientMode{ ClientPatterns::getWorldSessionInClientMode() }; - ClientMode clientMode{ ClientPatterns::clientMode() }; - - HudScopePanels hudScopePanels; LoopModeGameHook& loopModeGameHook; + SniperScopeBlurRemover& sniperScopeBlurRemover; + HudScopePanels hudScopePanels; }; diff --git a/Source/Features/Visuals/SniperScopeBlurRemovalFeature.h b/Source/Features/Visuals/SniperScopeBlurRemovalFeature.h new file mode 100644 index 00000000000..7d3b0434498 --- /dev/null +++ b/Source/Features/Visuals/SniperScopeBlurRemovalFeature.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +class LoopModeGameHook; + +class SniperScopeBlurRemovalFeature : public TogglableFeature { +public: + SniperScopeBlurRemovalFeature(LoopModeGameHook& loopModeGameHook, SniperScopeBlurRemover& sniperScopeBlurRemover) noexcept + : loopModeGameHook{loopModeGameHook} + , sniperScopeBlurRemover{sniperScopeBlurRemover} + { + } + +private: + friend TogglableFeature; + + void onEnable() const noexcept + { + sniperScopeBlurRemover.incrementReferenceCount(loopModeGameHook); + } + + void onDisable() const noexcept + { + sniperScopeBlurRemover.decrementReferenceCount(loopModeGameHook); + } + + LoopModeGameHook& loopModeGameHook; + SniperScopeBlurRemover& sniperScopeBlurRemover; +}; diff --git a/Source/Features/Visuals/VisualFeatures.h b/Source/Features/Visuals/VisualFeatures.h index 61732be3d98..258a5eb82e2 100644 --- a/Source/Features/Visuals/VisualFeatures.h +++ b/Source/Features/Visuals/VisualFeatures.h @@ -1,14 +1,18 @@ #pragma once #include "ScopeOverlayRemover/ScopeOverlayRemover.h" +#include "SniperScopeBlurRemovalFeature.h" class LoopModeGameHook; +class SniperScopeBlurRemover; struct VisualFeatures { - VisualFeatures(LoopModeGameHook& loopModeGameHook) noexcept - : scopeOverlayRemover{ loopModeGameHook } + VisualFeatures(SniperScopeBlurRemover& sniperScopeBlurRemover, LoopModeGameHook& loopModeGameHook) noexcept + : scopeOverlayRemover{loopModeGameHook, sniperScopeBlurRemover} + , sniperScopeBlurRemoval{loopModeGameHook, sniperScopeBlurRemover} { } ScopeOverlayRemover scopeOverlayRemover; + SniperScopeBlurRemovalFeature sniperScopeBlurRemoval; }; diff --git a/Source/GlobalContext.h b/Source/GlobalContext.h index b967963d143..e6e43f83c13 100644 --- a/Source/GlobalContext.h +++ b/Source/GlobalContext.h @@ -63,7 +63,7 @@ struct GlobalContext { hooks.init(clientVmtLengthCalculator); soundWatcher.init(); featureHelpers.init(); - features.init(hooks->loopModeGameHook, hooks->viewRenderHook, *soundWatcher); + features.init(featureHelpers->sniperScopeBlurRemover, hooks->loopModeGameHook, hooks->viewRenderHook, *soundWatcher); panoramaGUI.init(); initializedFromGameThread = true; diff --git a/Source/Osiris.vcxproj b/Source/Osiris.vcxproj index 322eca44ea6..b6e9f5c72fa 100644 --- a/Source/Osiris.vcxproj +++ b/Source/Osiris.vcxproj @@ -62,6 +62,7 @@ + @@ -76,6 +77,7 @@ + diff --git a/Source/Osiris.vcxproj.filters b/Source/Osiris.vcxproj.filters index ae6af087db2..66415027cfe 100644 --- a/Source/Osiris.vcxproj.filters +++ b/Source/Osiris.vcxproj.filters @@ -100,6 +100,9 @@ {3908a784-03e1-437a-97b7-7479673278cc} + + {1511f056-4a2b-4e6c-b5dc-3706343f42f0} + @@ -759,6 +762,12 @@ Platform\Windows\RTTI + + FeatureHelpers\Visuals + + + Features\Visuals + diff --git a/Source/UI/Panorama/CreateGUI.js b/Source/UI/Panorama/CreateGUI.js index 24e5285a3e2..ae44d4b3081 100644 --- a/Source/UI/Panorama/CreateGUI.js +++ b/Source/UI/Panorama/CreateGUI.js @@ -197,6 +197,8 @@ $.Osiris = (function () { var visuals = createTab('visuals'); var weapons = createSection(visuals, 'Weapons'); + createYesNoDropDown(weapons, "Remove Sniper Scope Blur", 'visuals', 'remove_scope_blur'); + $.CreatePanel('Panel', weapons, '', { class: "horizontal-separator" }); createYesNoDropDown(weapons, "Remove Scope Overlay", 'visuals', 'remove_scope_overlay'); var sound = createTab('sound'); diff --git a/Source/UI/Panorama/SetCommandHandler.h b/Source/UI/Panorama/SetCommandHandler.h index c537ea8d61e..38931a08a66 100644 --- a/Source/UI/Panorama/SetCommandHandler.h +++ b/Source/UI/Panorama/SetCommandHandler.h @@ -54,6 +54,8 @@ struct SetCommandHandler { { if (const auto feature = parser.getLine('/'); feature == "remove_scope_overlay") { handleTogglableFeature(features.visuals.scopeOverlayRemover); + } else if (feature == "remove_scope_blur") { + handleTogglableFeature(features.visuals.sniperScopeBlurRemoval); } }