Skip to content

Commit 9e49a83

Browse files
authored
Merge pull request #900 from Victor-Diego/ultrawide_cheat_fix
restrict cursor to 16:9 area to prevent ultra-wide fov cheat
2 parents 06fa25f + a4edc34 commit 9e49a83

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/game/client/swarm/asw_in_mouse.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// memdbgon must be the last include file in a .cpp file!!!
1616
#include "tier0/memdbgon.h"
1717

18+
bool g_ultra_wide_screen = false;
19+
Rect_t g_clamp_area = {};
20+
1821
ConVar glow_outline_color_active( "glow_outline_color_active", "153 153 204", FCVAR_NONE );
1922
ConVar glow_outline_color_inactive( "glow_outline_color_inactive", "77 77 77", FCVAR_NONE );
2023

@@ -85,6 +88,36 @@ void CASWInput::ApplyMouse( int nSlot, QAngle& viewangles, CUserCmd *cmd, float
8588
int current_posx, current_posy;
8689
GetMousePos(current_posx, current_posy);
8790

91+
// restrict cursor to 16:9 area to prevent ultra-wide fov cheat
92+
g_ultra_wide_screen = false;
93+
C_ASW_Player* asw_player = C_ASW_Player::GetLocalASWPlayer();
94+
95+
if (asw_player && !asw_player->GetSpectatingNPC()) {
96+
int screen_w = ScreenWidth();
97+
int screen_h = ScreenHeight();
98+
float aspect = static_cast<float>(screen_w) / screen_h;
99+
100+
constexpr float ratio169 = 16.0f / 9.0f;
101+
102+
if (aspect > ratio169) {
103+
g_ultra_wide_screen = true;
104+
105+
int target_h = screen_h;
106+
int target_w = static_cast<int>(screen_h * ratio169);
107+
108+
int left = (screen_w - target_w) / 2;
109+
int top = 0;
110+
111+
g_clamp_area.x = left;
112+
g_clamp_area.y = top;
113+
g_clamp_area.width = left + target_w;
114+
g_clamp_area.height = top + target_h;
115+
116+
current_posx = clamp(current_posx, g_clamp_area.x, g_clamp_area.width);
117+
current_posy = clamp(current_posy, g_clamp_area.y, g_clamp_area.height);
118+
}
119+
}
120+
88121
if ( ASWInput()->ControllerModeActiveMouse() )
89122
return;
90123

src/game/client/swarm/vgui/asw_hud_master.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ extern ConVar asw_hud_alpha;
3636
extern ConVar rd_respawn_time;
3737
extern ConVar rd_hud_hide_clips;
3838

39+
extern bool g_ultra_wide_screen;
40+
extern Rect_t g_clamp_area;
41+
3942
ConVar rd_draw_avatars_with_frags( "rd_draw_avatars_with_frags", "1", FCVAR_ARCHIVE, "If 1 In PvP modes a panel with avatars and frags will be shown at top of the screen");
4043
ConVar rd_draw_portraits( "rd_draw_portraits", "1", FCVAR_NONE );
4144
ConVar rd_draw_timer( "rd_draw_timer", "0", FCVAR_ARCHIVE, "Display the current mission time at the top of the screen" );
4245
ConVar rd_draw_timer_color( "rd_draw_timer_color", "255 255 255 255", FCVAR_ARCHIVE, "The color of the current mission time" );
4346
ConVar rd_draw_marine_health_counter( "rd_draw_marine_health_counter", "0", FCVAR_ARCHIVE, "Display a numeric counter for marine health on the HUD" );
4447

48+
ConVar rd_draw_restricted_borders( "rd_draw_restricted_borders", "1", FCVAR_ARCHIVE, "Display the restricted cursor area when using ultra-wide resolution" );
49+
ConVar rd_draw_restricted_borders_color("rd_draw_restricted_borders_color", "128 128 128 128", 0, "Color of the restricted cursor area borders");
50+
4551
using namespace vgui;
4652

4753
DECLARE_HUDELEMENT( CASW_Hud_Master );
@@ -480,6 +486,17 @@ void CASW_Hud_Master::Paint( void )
480486

481487
if ( m_pLocalMarineResource )
482488
{
489+
// draw restricted borders for ultra-wide screen
490+
if (rd_draw_restricted_borders.GetBool() && g_ultra_wide_screen && !pPlayer->GetSpectatingNPC()) {
491+
// (x,y)-----------(w,y)
492+
// | |
493+
// | |
494+
// (x,h)-----------(w,h)
495+
surface()->DrawSetColor(rd_draw_restricted_borders_color.GetColor());
496+
surface()->DrawLine(g_clamp_area.x, g_clamp_area.y, g_clamp_area.x, g_clamp_area.height);
497+
surface()->DrawLine(g_clamp_area.width, g_clamp_area.y, g_clamp_area.width, g_clamp_area.height);
498+
}
499+
483500
C_ASW_Marine_Resource *pMR = m_pLocalMarineResource;
484501

485502
float flTimeToFade = 2.0f;

0 commit comments

Comments
 (0)