From 0e88d368b93c768d54a7c6a06b1f5c2b02f9a3a1 Mon Sep 17 00:00:00 2001 From: pierow Date: Mon, 27 Nov 2023 16:01:49 -0500 Subject: [PATCH] HL25 fixes -Add new widescreen method and exploit prevention -disable old widescreen method and exploit prevention -force sv_rollangle 0 -add sv_widescreenclamp to limit fov expansion to 16:9 --- main/source/cl_dll/hud_update.cpp | 71 ++++++++++++++-------------- main/source/cl_dll/input.cpp | 4 +- main/source/cl_dll/util.cpp | 9 +++- main/source/dlls/game.cpp | 5 ++ main/source/mod/AvHClientVariables.h | 2 +- main/source/mod/AvHGamerules.cpp | 2 + main/source/mod/AvHHud.cpp | 50 ++++++++++++++++++++ main/source/mod/AvHHud.h | 3 ++ main/source/mod/AvHServerVariables.h | 3 ++ 9 files changed, 109 insertions(+), 40 deletions(-) diff --git a/main/source/cl_dll/hud_update.cpp b/main/source/cl_dll/hud_update.cpp index 7ae6be42..061e6906 100644 --- a/main/source/cl_dll/hud_update.cpp +++ b/main/source/cl_dll/hud_update.cpp @@ -41,47 +41,46 @@ int CHud::UpdateClientData(client_data_t *cdata, float time) Think(); - //cdata->fov = m_iFOV; + cdata->fov = m_iFOV; - float width = ScreenWidth(); - float height = ScreenHeight(); + //// Horizontal+ widescreen view correction - Removed after HL25 update + //float width = ScreenWidth(); + //float height = ScreenHeight(); - // Horizontal+ widescreen view correction - engine uses vertical- cropping + //// Cvar to let players use old widescreen. Only allow it to change when not alive so it can't be used as a zoom toggle. + //if (!gHUD.GetIsAlive(false)) + //{ + // wstoggle = CVAR_GET_FLOAT("cl_widescreen") != 0; + //} - // Cvar to let players use old widescreen. Only allow it to change when not alive so it can't be used as a zoom toggle. - if (!gHUD.GetIsAlive(false)) - { - wstoggle = CVAR_GET_FLOAT("cl_widescreen") != 0; - } + //if (wstoggle) + //{ + // m_wsFOV = atanf(tan(m_iFOV * M_PI / 360) * 0.75 * width / height) * 360 / M_PI; - if (wstoggle) - { - m_wsFOV = atanf(tan(m_iFOV * M_PI / 360) * 0.75 * width / height) * 360 / M_PI; + // //clamp for game balance + // if (m_iFOV == 105 && m_wsFOV > 121) + // { + // m_wsFOV = 120; + // } + // else if (m_iFOV == 100 && m_wsFOV > 117) + // { + // m_wsFOV = 116; + // } + // else if (m_iFOV == 90 && m_wsFOV > 107) + // { + // m_wsFOV = 106; + // } + // else if (m_wsFOV < 90) + // { + // m_wsFOV = 90; + // } + //} + //else + //{ + // m_wsFOV = m_iFOV; + //} - //clamp for game balance - if (m_iFOV == 105 && m_wsFOV > 121) - { - m_wsFOV = 120; - } - else if (m_iFOV == 100 && m_wsFOV > 117) - { - m_wsFOV = 116; - } - else if (m_iFOV == 90 && m_wsFOV > 107) - { - m_wsFOV = 106; - } - else if (m_wsFOV < 90) - { - m_wsFOV = 90; - } - } - else - { - m_wsFOV = m_iFOV; - } - - cdata->fov = m_wsFOV; + //cdata->fov = m_wsFOV; CL_ResetButtonBits( m_iKeyBits ); diff --git a/main/source/cl_dll/input.cpp b/main/source/cl_dll/input.cpp index 5724e271..ba805e31 100644 --- a/main/source/cl_dll/input.cpp +++ b/main/source/cl_dll/input.cpp @@ -138,7 +138,7 @@ cvar_t *cl_dynamiclights; cvar_t *r_dynamic; cvar_t *cl_buildmessages; cvar_t *cl_particleinfo; -cvar_t *cl_widescreen; +//cvar_t *cl_widescreen; cvar_t *cl_ambientsound; cvar_t *senslock; cvar_t *hud_style; @@ -1638,7 +1638,7 @@ void InitInput (void) cl_cmhotkeys = gEngfuncs.pfnRegisterVariable ( kvCMHotkeys, "qwerasdfzxcv", FCVAR_ARCHIVE ); //cl_forcedefaultfov = gEngfuncs.pfnRegisterVariable ( kvForceDefaultFOV, "0", FCVAR_ARCHIVE ); cl_particleinfo = gEngfuncs.pfnRegisterVariable ( kvParticleInfo, "0", FCVAR_ARCHIVE ); - cl_widescreen = gEngfuncs.pfnRegisterVariable ( kvWidescreen, "1", FCVAR_ARCHIVE ); + //cl_widescreen = gEngfuncs.pfnRegisterVariable ( kvWidescreen, "1", FCVAR_ARCHIVE ); cl_ambientsound = gEngfuncs.pfnRegisterVariable ( kvAmbientSound, "0", FCVAR_ARCHIVE); senslock = gEngfuncs.pfnRegisterVariable ("senslock", "0", FCVAR_ARCHIVE); hud_style = gEngfuncs.pfnRegisterVariable ("hud_style", "1", FCVAR_ARCHIVE); diff --git a/main/source/cl_dll/util.cpp b/main/source/cl_dll/util.cpp index f6d3e454..ef53dfea 100644 --- a/main/source/cl_dll/util.cpp +++ b/main/source/cl_dll/util.cpp @@ -182,7 +182,14 @@ void CreatePickingRay( int mousex, int mousey, Vector& outVecPickingRay ) // char gDebugMessage[256]; - float fovDegrees = gHUD.m_wsFOV; + //float fovDegrees = gHUD.m_wsFOV; + bool wideScreen = CVAR_GET_FLOAT("gl_widescreen_yfov"); + float fovDegrees = gHUD.m_iFOV; + //Adjust for widescreen FOV + if (wideScreen) + { + fovDegrees = atanf(tan(gHUD.m_iFOV * M_PI / 360) * 0.75f * ScreenWidth() / ScreenHeight()) * 360 / M_PI; + } //cl_entity_s* theLocalEntity = gEngfuncs.GetLocalPlayer(); //Vector vecRenderOrigin = theLocalEntity->origin; diff --git a/main/source/dlls/game.cpp b/main/source/dlls/game.cpp index 03554246..4fd05f8b 100644 --- a/main/source/dlls/game.cpp +++ b/main/source/dlls/game.cpp @@ -123,6 +123,7 @@ cvar_t avh_mapvoteratio = {kvMapVoteRatio, ".6", FCVAR_SERVER}; cvar_t avh_blockscripts = {kvBlockScripts, "1", FCVAR_SERVER}; cvar_t avh_jumpmode = {kvJumpMode, "1", FCVAR_SERVER}; cvar_t avh_version = {kvVersion, "330", FCVAR_SERVER}; +cvar_t avh_widescreenclamp = {kvWidescreenClamp, "0", FCVAR_SERVER}; //playtest cvars cvar_t avh_fastjp = {kvfastjp, "0", FCVAR_SERVER}; cvar_t avh_randomrfk = {kvRandomRfk, "1", FCVAR_SERVER}; @@ -239,6 +240,7 @@ void GameDLLInit( void ) CVAR_REGISTER (&avh_blockscripts); CVAR_REGISTER (&avh_jumpmode); CVAR_REGISTER (&avh_version); + CVAR_REGISTER (&avh_widescreenclamp); //playtest cvars CVAR_REGISTER (&avh_fastjp); CVAR_REGISTER (&avh_randomrfk); @@ -270,5 +272,8 @@ void GameDLLInit( void ) CVAR_REGISTER (&avh_uplink); CVAR_REGISTER (&avh_killdelay); + //Remove HL25 addition of roll angle in code so servers don't need to update configs. + CVAR_SET_FLOAT("sv_rollangle", 0.0f); + } diff --git a/main/source/mod/AvHClientVariables.h b/main/source/mod/AvHClientVariables.h index 9c507a83..9e5d1c56 100644 --- a/main/source/mod/AvHClientVariables.h +++ b/main/source/mod/AvHClientVariables.h @@ -47,7 +47,7 @@ extern cvar_t* cl_musicdir; // : #define kvCMHotKeys "cl_cmhotkeys" //#define kvForceDefaultFOV "cl_forcedefaultfov" -#define kvWidescreen "cl_widescreen" +//#define kvWidescreen "cl_widescreen" #define kvAmbientSound "cl_ambientsound" #define kvCenterEntityID "cl_centerentityid" #define kvHighDetail "cl_highdetail" diff --git a/main/source/mod/AvHGamerules.cpp b/main/source/mod/AvHGamerules.cpp index 56c5ae32..598197f7 100644 --- a/main/source/mod/AvHGamerules.cpp +++ b/main/source/mod/AvHGamerules.cpp @@ -338,6 +338,8 @@ AvHGamerules::AvHGamerules() : mTeamA(TEAM_ONE), mTeamB(TEAM_TWO) RegisterServerVariable(avh_cheats); RegisterServerVariable(&avh_structurelimit); RegisterServerVariable(&avh_version); + RegisterServerVariable(&avh_widescreenclamp); + //playtest cvars RegisterServerVariable(&avh_fastjp); RegisterServerVariable(&avh_randomrfk); diff --git a/main/source/mod/AvHHud.cpp b/main/source/mod/AvHHud.cpp index f400937c..a437cf0a 100644 --- a/main/source/mod/AvHHud.cpp +++ b/main/source/mod/AvHHud.cpp @@ -4883,6 +4883,8 @@ cvar_t *lightgamma = NULL; cvar_t *texgamma = NULL; cvar_t *r_detailtextures = NULL; cvar_t *gl_max_size = NULL; +cvar_t *gl_widescreen_yfov = NULL; +cvar_t *sv_widescreenclamp = NULL; void AvHHud::InitExploitPrevention() { gl_monolights = gEngfuncs.pfnGetCvarPointer("gl_monolights"); @@ -4897,6 +4899,7 @@ void AvHHud::InitExploitPrevention() { texgamma = gEngfuncs.pfnGetCvarPointer("texgamma"); r_detailtextures = gEngfuncs.pfnGetCvarPointer("r_detailtextures"); gl_max_size = gEngfuncs.pfnGetCvarPointer("gl_max_size"); + gl_widescreen_yfov = gEngfuncs.pfnGetCvarPointer("gl_widescreen_yfov"); ForceCvar("gl_monolights", gl_monolights, 0.0f); ForceCvar("gl_overbright", gl_overbright, 0.0f); @@ -4922,6 +4925,11 @@ void AvHHud::InitExploitPrevention() { if(texgamma && texgamma->value > 5.0) { ForceCvar("texgamma", texgamma, 5.0f); } + RemoveAlias("gl_widescreen_yfov"); + if (gl_widescreen_yfov) + { + mWideScreen = gl_widescreen_yfov->value; + } } @@ -4952,6 +4960,48 @@ void AvHHud::UpdateExploitPrevention() if(texgamma && texgamma->value > 5.0) { ForceCvar("texgamma", texgamma, 5.0f); } + //Widescreen exploit prevention + if (gViewPort) + { + if (gHUD.GetIsAlive(false)) + { + if (gl_widescreen_yfov && gl_widescreen_yfov->value == 0 && mWideScreen) { + ForceCvar("gl_widescreen_yfov", gl_widescreen_yfov, 1.0f); + mWideScreenChanged = true; + gEngfuncs.pfnCenterPrint("The Widescreen FOV\n will change after death\n"); + } + if (gl_widescreen_yfov && gl_widescreen_yfov->value != 0 && !mWideScreen) { + ForceCvar("gl_widescreen_yfov", gl_widescreen_yfov, 0); + mWideScreenChanged = true; + gEngfuncs.pfnCenterPrint("The Widescreen FOV\n will change after death\n"); + } + } + else if (mWideScreenChanged) + { + mWideScreen = !mWideScreen; + ForceCvar("gl_widescreen_yfov", gl_widescreen_yfov, (float)mWideScreen); + mWideScreenChanged = false; + } + else + { + mWideScreen = gl_widescreen_yfov->value; + } + + //sv_widescreenclamp is to prevent abuse of ultra-widescreen FOVs in competitive play. + if ((ScreenWidth() / ScreenHeight()) > 1.8f) + { + if (this->GetServerVariableFloat(kvWidescreenClamp) != 0 && gl_widescreen_yfov && gl_widescreen_yfov->value != 0) + { + ForceCvar("gl_widescreen_yfov", gl_widescreen_yfov, 0); + gEngfuncs.pfnCenterPrint("This aspect ratio is not allowed\n on this server\n"); + } + } + } + //else if (gl_widescreen_yfov) + //{ + // mWideScreen = gl_widescreen_yfov->value; + // gEngfuncs.Con_Printf("init mwidescreen from update %d\n", mWideScreen); + //} } void AvHHud::UpdateAlienUI(float inCurrentTime) diff --git a/main/source/mod/AvHHud.h b/main/source/mod/AvHHud.h index 5090f5c3..53085d8e 100644 --- a/main/source/mod/AvHHud.h +++ b/main/source/mod/AvHHud.h @@ -876,6 +876,9 @@ private: static bool sShowMap; + bool mWideScreen; + bool mWideScreenChanged; + }; #endif diff --git a/main/source/mod/AvHServerVariables.h b/main/source/mod/AvHServerVariables.h index 63d1af9c..e5eae623 100644 --- a/main/source/mod/AvHServerVariables.h +++ b/main/source/mod/AvHServerVariables.h @@ -96,6 +96,7 @@ extern cvar_t *violence_agibs; extern cvar_t avh_killdelay; extern cvar_t *showtriggers; extern cvar_t avh_version; +extern cvar_t avh_widescreenclamp; //playtest cvars extern cvar_t avh_fastjp; extern cvar_t avh_randomrfk; @@ -149,6 +150,8 @@ float ns_cvar_float(const cvar_t *cvar); #define kvBlockScripts "mp_blockscripts" #define kvJumpMode "sv_jumpmode" #define kvVersion "sv_nsversion" +#define kvWidescreenClamp "sv_widescreenclamp" + //playtest cvars #define kvfastjp "sv_fastjp" #define kvRandomRfk "mp_randomresfromkill"