From 5dd184da23abe1a9d8378a61fe13547d703cc9c9 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Fri, 26 Mar 2021 04:08:05 +0500 Subject: [PATCH 1/8] Fix memory leaks when parsing files. --- cl_dll/hud_spectator.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cl_dll/hud_spectator.cpp b/cl_dll/hud_spectator.cpp index ce32e4e2..7cb8e1fe 100644 --- a/cl_dll/hud_spectator.cpp +++ b/cl_dll/hud_spectator.cpp @@ -824,6 +824,7 @@ bool CHudSpectator::ParseOverviewFile() char levelname[256] = { 0 }; char token[1024] = { 0 }; float height; + bool ret = false; char *afile = NULL, *pfile = NULL; @@ -843,7 +844,7 @@ bool CHudSpectator::ParseOverviewFile() strcpy( m_OverviewData.map, gEngfuncs.pfnGetLevelName() ); if( m_OverviewData.map[0] == '\0' ) - return false; // not active yet + return ret; // not active yet strcpy( levelname, m_OverviewData.map + 5 ); levelname[strlen( levelname ) - 4] = 0; @@ -855,7 +856,7 @@ bool CHudSpectator::ParseOverviewFile() if( !pfile ) { gEngfuncs.Con_DPrintf( "Couldn't open file %s. Using default values for overiew mode.\n", filename ); - return false; + return ret; } while( true ) @@ -872,7 +873,7 @@ bool CHudSpectator::ParseOverviewFile() if( stricmp( token, "{" ) ) { gEngfuncs.Con_Printf( "Error parsing overview file %s. (expected { )\n", filename ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); @@ -912,7 +913,7 @@ bool CHudSpectator::ParseOverviewFile() else { gEngfuncs.Con_Printf( "Error parsing overview file %s. (%s unkown)\n", filename, token ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); // parse next token @@ -924,7 +925,7 @@ bool CHudSpectator::ParseOverviewFile() if( m_OverviewData.layers == OVERVIEW_MAX_LAYERS ) { gEngfuncs.Con_Printf( "Error parsing overview file %s. ( too many layers )\n", filename ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); @@ -932,7 +933,7 @@ bool CHudSpectator::ParseOverviewFile() if( stricmp( token, "{" ) ) { gEngfuncs.Con_Printf( "Error parsing overview file %s. (expected { )\n", filename ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); @@ -953,7 +954,7 @@ bool CHudSpectator::ParseOverviewFile() else { gEngfuncs.Con_Printf( "Error parsing overview file %s. (%s unkown)\n", filename, token ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); // parse next token @@ -963,12 +964,14 @@ bool CHudSpectator::ParseOverviewFile() } } - gEngfuncs.COM_FreeFile( afile ); - m_mapZoom = m_OverviewData.zoom; m_mapOrigin = m_OverviewData.origin; - return true; + ret = true; +end: + gEngfuncs.COM_FreeFile( afile ); + + return ret; } void CHudSpectator::LoadMapSprites() From c0720d3cfc06720c88594f4c5ece4b6db2e4abce Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 4 Apr 2021 07:07:54 +0500 Subject: [PATCH 2/8] Precache missing sounds for sentry gun. --- dlls/turret.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dlls/turret.cpp b/dlls/turret.cpp index a5aa6d23..556d7ede 100644 --- a/dlls/turret.cpp +++ b/dlls/turret.cpp @@ -1150,6 +1150,9 @@ void CSentry::Precache() { CBaseTurret::Precache(); PRECACHE_MODEL( "models/sentry.mdl" ); + PRECACHE_SOUND( "weapons/hks1.wav" ); + PRECACHE_SOUND( "weapons/hks2.wav" ); + PRECACHE_SOUND( "weapons/hks3.wav" ); } void CSentry::Spawn() From 17ab9975010d44779b57bdc3af9b971ee8735a80 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 4 Apr 2021 07:18:32 +0500 Subject: [PATCH 3/8] Remove duplicated macros. --- pm_shared/pm_shared.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pm_shared/pm_shared.c b/pm_shared/pm_shared.c index 01825777..2352b51f 100644 --- a/pm_shared/pm_shared.c +++ b/pm_shared/pm_shared.c @@ -63,19 +63,7 @@ playermove_t *pmove = NULL; #define STOP_EPSILON 0.1f #define CTEXTURESMAX 512 // max number of textures loaded -#define CBTEXTURENAMEMAX 13 // only load first n chars of name - -#define CHAR_TEX_CONCRETE 'C' // texture types -#define CHAR_TEX_METAL 'M' -#define CHAR_TEX_DIRT 'D' -#define CHAR_TEX_VENT 'V' -#define CHAR_TEX_GRATE 'G' -#define CHAR_TEX_TILE 'T' -#define CHAR_TEX_SLOSH 'S' -#define CHAR_TEX_WOOD 'W' -#define CHAR_TEX_COMPUTER 'P' -#define CHAR_TEX_GLASS 'Y' -#define CHAR_TEX_FLESH 'F' +#include "pm_materials.h" #define STEP_CONCRETE 0 // default step sound #define STEP_METAL 1 // metal floor From 08f5c265cefebf665eda88d93770ee543a9c4c4f Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 4 Apr 2021 07:32:25 +0500 Subject: [PATCH 4/8] Clamp gravity. --- dlls/bigmomma.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dlls/bigmomma.cpp b/dlls/bigmomma.cpp index a73334ff..584a6737 100644 --- a/dlls/bigmomma.cpp +++ b/dlls/bigmomma.cpp @@ -1034,7 +1034,7 @@ Vector VecCheckSplatToss( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot Vector vecScale; Vector vecGrenadeVel; Vector vecTemp; - float flGravity = g_psv_gravity->value; + float flGravity = Q_max( g_psv_gravity->value, 0.1f ); // calculate the midpoint and apex of the 'triangle' vecMidPoint = vecSpot1 + ( vecSpot2 - vecSpot1 ) * 0.5f; @@ -1050,6 +1050,9 @@ Vector VecCheckSplatToss( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot // Don't worry about actually hitting the target, this won't hurt us! + // TODO: Need another way to calculate height because current calculation is completely wrong + // and there posible crash. + // How high should the grenade travel (subtract 15 so the grenade doesn't hit the ceiling)? float height = vecApex.z - vecSpot1.z - 15.0f; // How fast does the grenade need to travel to reach that height given gravity? From 4ba54bdcdc6b3e8b1a022d98c3fe131cd812c31d Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 4 Apr 2021 22:10:51 +0500 Subject: [PATCH 5/8] Fix target check. Same as https://github.com/ValveSoftware/halflife/issues/3083. --- dlls/cbase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/cbase.h b/dlls/cbase.h index a09b0a61..ba1c0464 100644 --- a/dlls/cbase.h +++ b/dlls/cbase.h @@ -193,7 +193,7 @@ public: virtual BOOL IsAlive( void ) { return (pev->deadflag == DEAD_NO) && pev->health > 0; } virtual BOOL IsBSPModel( void ) { return pev->solid == SOLID_BSP || pev->movetype == MOVETYPE_PUSHSTEP; } virtual BOOL ReflectGauss( void ) { return ( IsBSPModel() && !pev->takedamage ); } - virtual BOOL HasTarget( string_t targetname ) { return FStrEq(STRING(targetname), STRING(pev->targetname) ); } + virtual BOOL HasTarget( string_t targetname ) { return FStrEq(STRING(targetname), STRING(pev->target) ); } virtual BOOL IsInWorld( void ); virtual BOOL IsPlayer( void ) { return FALSE; } virtual BOOL IsNetClient( void ) { return FALSE; } From a07acb3d14ec42d6630e5ad7055f790f84a0b6a8 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 4 Apr 2021 22:26:27 +0500 Subject: [PATCH 6/8] Restore global time on Save/Restore. Same as https://github.com/ValveSoftware/halflife/issues/3065. --- dlls/cbase.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dlls/cbase.cpp b/dlls/cbase.cpp index 4e6292ba..7f1f204a 100644 --- a/dlls/cbase.cpp +++ b/dlls/cbase.cpp @@ -255,6 +255,8 @@ void DispatchSave( edict_t *pent, SAVERESTOREDATA *pSaveData ) { ENTITYTABLE *pTable = &pSaveData->pTable[pSaveData->currentIndex]; + gpGlobals->time = pSaveData->time; + if( pTable->pent != pent ) ALERT( at_error, "ENTITY TABLE OR INDEX IS WRONG!!!!\n" ); @@ -307,6 +309,9 @@ int DispatchRestore( edict_t *pent, SAVERESTOREDATA *pSaveData, int globalEntity Vector oldOffset; CRestore restoreHelper( pSaveData ); + + gpGlobals->time = pSaveData->time; + if( globalEntity ) { CRestore tmpRestore( pSaveData ); From 93630eae2375bcc25e5596c777a42cc68686ac27 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 4 Apr 2021 22:30:44 +0500 Subject: [PATCH 7/8] Fix player model angles. Same as https://github.com/ValveSoftware/halflife/issues/3075. --- cl_dll/view.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cl_dll/view.cpp b/cl_dll/view.cpp index 9ce6208e..01139689 100644 --- a/cl_dll/view.cpp +++ b/cl_dll/view.cpp @@ -736,6 +736,10 @@ void V_CalcNormalRefdef( struct ref_params_s *pparams ) if( CL_IsThirdPerson() ) { VectorCopy( camAngles, pparams->viewangles ); + } + + // Apply this at all times + { float pitch = camAngles[0]; // Normalize angles From 9a6ef538b6be879b9f6e396fb4614da9205f615d Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Mon, 12 Apr 2021 09:57:56 +0500 Subject: [PATCH 8/8] Do not precache sounds for xash3d-only builds. --- dlls/enginecallback.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dlls/enginecallback.h b/dlls/enginecallback.h index a9e37c26..19e9b33d 100644 --- a/dlls/enginecallback.h +++ b/dlls/enginecallback.h @@ -28,7 +28,11 @@ extern enginefuncs_t g_engfuncs; // The actual engine callbacks #define GETPLAYERUSERID (*g_engfuncs.pfnGetPlayerUserId) #define PRECACHE_MODEL (*g_engfuncs.pfnPrecacheModel) +#ifdef GOLDSOURCE_SUPPORT #define PRECACHE_SOUND (*g_engfuncs.pfnPrecacheSound) +#else +#define PRECACHE_SOUND(x) +#endif #define PRECACHE_GENERIC (*g_engfuncs.pfnPrecacheGeneric) #define SET_MODEL (*g_engfuncs.pfnSetModel) #define MODEL_INDEX (*g_engfuncs.pfnModelIndex)