Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement removing sniper rifle scope blur #4205

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions Source/FeatureHelpers/FeatureHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Hud/KillfeedPreserverHelpers.h"
#include "Sound/SoundVisualizationHelpers.h"
#include "ViewToProjectionMatrix.h"
#include "Visuals/SniperScopeBlurRemover.h"
#include "WorldToClipSpaceConverter.h"

struct FeatureHelpers {
Expand Down Expand Up @@ -39,4 +40,5 @@ struct FeatureHelpers {
PlantedC4Provider plantedC4Provider;
HudInWorldPanelContainer hudInWorldPanelContainer;
ViewToProjectionMatrix viewToProjectionMatrix;
SniperScopeBlurRemover sniperScopeBlurRemover;
};
48 changes: 48 additions & 0 deletions Source/FeatureHelpers/Visuals/SniperScopeBlurRemover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <cassert>
#include <cstddef>
#include <limits>

#include <GameClasses/ClientMode.h>
#include <Hooks/LoopModeGameHook.h>
#include <MemoryPatterns/ClientPatterns.h>
#include <Utils/ReturnAddress.h>

class SniperScopeBlurRemover {
public:
void incrementReferenceCount(LoopModeGameHook& loopModeGameHook) noexcept
{
assert(referenceCount < (std::numeric_limits<std::size_t>::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};
};
6 changes: 4 additions & 2 deletions Source/Features/Features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
{
}
Expand Down
27 changes: 8 additions & 19 deletions Source/Features/Visuals/ScopeOverlayRemover/ScopeOverlayRemover.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@
#include <GameClasses/ClientMode.h>

#include <FeatureHelpers/TogglableFeature.h>
#include <FeatureHelpers/Visuals/SniperScopeBlurRemover.h>

#include "HudScopePanels.h"

class ScopeOverlayRemover : public TogglableFeature<ScopeOverlayRemover> {
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
{
Expand All @@ -43,12 +39,12 @@ class ScopeOverlayRemover : public TogglableFeature<ScopeOverlayRemover> {

void onEnable() const noexcept
{
loopModeGameHook.incrementReferenceCount();
sniperScopeBlurRemover.incrementReferenceCount(loopModeGameHook);
}

void onDisable() const noexcept
{
loopModeGameHook.decrementReferenceCount();
sniperScopeBlurRemover.decrementReferenceCount(loopModeGameHook);
restorePanels();
}

Expand All @@ -64,20 +60,13 @@ class ScopeOverlayRemover : public TogglableFeature<ScopeOverlayRemover> {
*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;
};
31 changes: 31 additions & 0 deletions Source/Features/Visuals/SniperScopeBlurRemovalFeature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <FeatureHelpers/TogglableFeature.h>
#include <FeatureHelpers/Visuals/SniperScopeBlurRemover.h>

class LoopModeGameHook;

class SniperScopeBlurRemovalFeature : public TogglableFeature<SniperScopeBlurRemovalFeature> {
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;
};
8 changes: 6 additions & 2 deletions Source/Features/Visuals/VisualFeatures.h
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion Source/GlobalContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Source/Osiris.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<ClInclude Include="FeatureHelpers\Sound\WeaponScopeSound.h" />
<ClInclude Include="FeatureHelpers\TogglableFeature.h" />
<ClInclude Include="FeatureHelpers\ViewToProjectionMatrix.h" />
<ClInclude Include="FeatureHelpers\Visuals\SniperScopeBlurRemover.h" />
<ClInclude Include="FeatureHelpers\WorldToClipSpaceConverter.h" />
<ClInclude Include="Features\Features.h" />
<ClInclude Include="Features\Hud\BombTimer.h" />
Expand All @@ -76,6 +77,7 @@
<ClInclude Include="Features\Sound\WeaponScopeVisualizer.h" />
<ClInclude Include="Features\Visuals\ScopeOverlayRemover\HudScopePanels.h" />
<ClInclude Include="Features\Visuals\ScopeOverlayRemover\ScopeOverlayRemover.h" />
<ClInclude Include="Features\Visuals\SniperScopeBlurRemovalFeature.h" />
<ClInclude Include="Features\Visuals\VisualFeatures.h" />
<ClInclude Include="GameClasses\ClientMode.h" />
<ClInclude Include="GameClasses\FileNameSymbolTable.h" />
Expand Down
9 changes: 9 additions & 0 deletions Source/Osiris.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<Filter Include="Platform\Windows\RTTI">
<UniqueIdentifier>{3908a784-03e1-437a-97b7-7479673278cc}</UniqueIdentifier>
</Filter>
<Filter Include="FeatureHelpers\Visuals">
<UniqueIdentifier>{1511f056-4a2b-4e6c-b5dc-3706343f42f0}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CS2\Classes\C_CSGameRules.h">
Expand Down Expand Up @@ -759,6 +762,12 @@
<ClInclude Include="Platform\Windows\RTTI\RttiCompleteObjectLocator.h">
<Filter>Platform\Windows\RTTI</Filter>
</ClInclude>
<ClInclude Include="FeatureHelpers\Visuals\SniperScopeBlurRemover.h">
<Filter>FeatureHelpers\Visuals</Filter>
</ClInclude>
<ClInclude Include="Features\Visuals\SniperScopeBlurRemovalFeature.h">
<Filter>Features\Visuals</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="UI\Panorama\CreateGUI.js">
Expand Down
2 changes: 2 additions & 0 deletions Source/UI/Panorama/CreateGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions Source/UI/Panorama/SetCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down