Skip to content

Commit

Permalink
Merge branch 'master' into mobile_hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
nekonomicon committed Sep 18, 2024
2 parents 4087ebb + c461624 commit 93292f1
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 29 deletions.
19 changes: 18 additions & 1 deletion cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,9 @@ int CHudAmmo::MsgFunc_WeaponList( const char *pszName, int iSize, void *pbuf )

WEAPON Weapon;

strcpy( Weapon.szName, READ_STRING() );
strncpy( Weapon.szName, READ_STRING(), sizeof(Weapon.szName) );
Weapon.szName[sizeof(Weapon.szName) - 1] = '\0';

Weapon.iAmmoType = (int)READ_CHAR();

Weapon.iMax1 = READ_BYTE();
Expand All @@ -665,6 +667,21 @@ int CHudAmmo::MsgFunc_WeaponList( const char *pszName, int iSize, void *pbuf )
Weapon.iFlags = READ_BYTE();
Weapon.iClip = 0;

if( Weapon.iId < 0 || Weapon.iId >= MAX_WEAPONS )
return 0;
if( Weapon.iSlot < 0 || Weapon.iSlot >= MAX_WEAPON_SLOTS + 1 )
return 0;
if( Weapon.iSlotPos < 0 || Weapon.iSlotPos >= MAX_WEAPON_POSITIONS + 1 )
return 0;
if( Weapon.iAmmoType < -1 || Weapon.iAmmoType >= MAX_AMMO_TYPES )
return 0;
if( Weapon.iAmmo2Type < -1 || Weapon.iAmmo2Type >= MAX_AMMO_TYPES )
return 0;
if( Weapon.iAmmoType >= 0 && Weapon.iMax1 == 0 )
return 0;
if( Weapon.iAmmo2Type >= 0 && Weapon.iMax2 == 0 )
return 0;

gWR.AddWeapon( &Weapon );

return 1;
Expand Down
4 changes: 3 additions & 1 deletion cl_dll/hud_spectator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ void UTIL_StringToVector( float * pVector, const char *pString )
char *pstr, *pfront, tempString[128];
int j;

strcpy( tempString, pString );
strncpy( tempString, pString, sizeof( tempString ) );
tempString[sizeof( tempString ) - 1] = '\0';

pstr = pfront = tempString;

for( j = 0; j < 3; j++ )
Expand Down
2 changes: 1 addition & 1 deletion dlls/basemonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class CBaseMonster : public CBaseToggle
virtual BOOL ShouldFadeOnDeath( void );

// Basic Monster AI functions
virtual float ChangeYaw( int speed );
virtual float ChangeYaw( int yawSpeed );
float VecToYaw( Vector vecDir );
float FlYawDiff( void );

Expand Down
8 changes: 8 additions & 0 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,14 @@ void ClientCommand( edict_t *pEntity )
strncpy( command, pcmd, sizeof(command) - 1);
command[sizeof(command) - 1] = '\0';

// First parse the name and remove any %'s
for( char *pApersand = command; *pApersand; pApersand++ )
{
// Replace it with a space
if( *pApersand == '%' )
*pApersand = ' ';
}

// tell the user they entered an unknown command
ClientPrint( &pEntity->v, HUD_PRINTCONSOLE, UTIL_VarArgs( "Unknown command: %s\n", command ) );
}
Expand Down
23 changes: 20 additions & 3 deletions dlls/flyingmonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "game.h"
#include "monsters.h"
#include "schedule.h"
#include "flyingmonster.h"
Expand Down Expand Up @@ -83,7 +84,7 @@ void CFlyingMonster::Stop( void )
m_vecTravel = g_vecZero;
}

float CFlyingMonster::ChangeYaw( int speed )
float CFlyingMonster::ChangeYaw( int yawSpeed )
{
if( pev->movetype == MOVETYPE_FLY )
{
Expand All @@ -97,9 +98,25 @@ float CFlyingMonster::ChangeYaw( int speed )
else if( diff > 20.0f )
target = -90.0f;
}
pev->angles.z = UTIL_Approach( target, pev->angles.z, 220.0f * gpGlobals->frametime );

float speed = 220.f;

if( monsteryawspeedfix.value )
{
if( m_flLastZYawTime == 0.f )
m_flLastZYawTime = gpGlobals->time - gpGlobals->frametime;

float delta = Q_min( gpGlobals->time - m_flLastZYawTime, 0.25f );
m_flLastZYawTime = gpGlobals->time;

speed *= delta;
}
else
speed *= gpGlobals->frametime;

pev->angles.z = UTIL_Approach( target, pev->angles.z, speed );
}
return CBaseMonster::ChangeYaw( speed );
return CBaseMonster::ChangeYaw( yawSpeed );
}

void CFlyingMonster::Killed( entvars_t *pevAttacker, int iGib )
Expand Down
3 changes: 2 additions & 1 deletion dlls/flyingmonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CFlyingMonster : public CBaseMonster
Activity GetStoppedActivity( void );
void Killed( entvars_t *pevAttacker, int iGib );
void Stop( void );
float ChangeYaw( int speed );
float ChangeYaw( int yawSpeed );
void HandleAnimEvent( MonsterEvent_t *pEvent );
void MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval );
void Move( float flInterval = 0.1 );
Expand All @@ -45,5 +45,6 @@ class CFlyingMonster : public CBaseMonster
float m_stopTime; // Last time we stopped (to avoid switching states too soon)
float m_momentum; // Weight for desired vs. momentum velocity
const char *m_pFlapSound;
float m_flLastZYawTime; // Last frame time Z was changed when yaw was changed
};
#endif //FLYINGMONSTER_H
50 changes: 43 additions & 7 deletions dlls/ichthyosaur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "game.h"
#include "monsters.h"
#include "schedule.h"
#include "flyingmonster.h"
Expand Down Expand Up @@ -76,7 +77,7 @@ class CIchthyosaur : public CFlyingMonster
BOOL CheckMeleeAttack1( float flDot, float flDist );
BOOL CheckRangeAttack1( float flDot, float flDist );

float ChangeYaw( int speed );
float ChangeYaw( int yawSpeed );
Activity GetStoppedActivity( void );

void Move( float flInterval );
Expand All @@ -88,7 +89,7 @@ class CIchthyosaur : public CFlyingMonster

float VectorToPitch( const Vector &vec );
float FlPitchDiff( void );
float ChangePitch( int speed );
float ChangePitch( int pitchSpeed );

Vector m_SaveVelocity;
float m_idealDist;
Expand All @@ -106,6 +107,9 @@ class CIchthyosaur : public CFlyingMonster

float m_flNextAlert;

float m_flLastPitchTime; // Last frame time pitch was changed
float m_flLastZYawTime; // Last frame time Z was changed when yaw was changed

static const char *pIdleSounds[];
static const char *pAlertSounds[];
static const char *pAttackSounds[];
Expand Down Expand Up @@ -780,7 +784,7 @@ float CIchthyosaur::FlPitchDiff( void )
return flPitchDiff;
}

float CIchthyosaur::ChangePitch( int speed )
float CIchthyosaur::ChangePitch( int pitchSpeed )
{
if( pev->movetype == MOVETYPE_FLY )
{
Expand All @@ -793,12 +797,28 @@ float CIchthyosaur::ChangePitch( int speed )
else if( diff > 20 )
target = -45;
}
pev->angles.x = UTIL_Approach(target, pev->angles.x, 220.0f * 0.1f );

float speed = 220.f;

if( monsteryawspeedfix.value )
{
if( m_flLastPitchTime == 0.f )
m_flLastPitchTime = gpGlobals->time - gpGlobals->frametime;

float delta = Q_min( gpGlobals->time - m_flLastPitchTime, 0.25f );
m_flLastPitchTime = gpGlobals->time;

speed *= delta;
}
else
speed *= 0.1f;

pev->angles.x = UTIL_Approach(target, pev->angles.x, speed );
}
return 0;
}

float CIchthyosaur::ChangeYaw( int speed )
float CIchthyosaur::ChangeYaw( int yawSpeed )
{
if( pev->movetype == MOVETYPE_FLY )
{
Expand All @@ -812,9 +832,25 @@ float CIchthyosaur::ChangeYaw( int speed )
else if( diff > 20 )
target = -20;
}
pev->angles.z = UTIL_Approach( target, pev->angles.z, 220.0f * 0.1f );

float speed = 220.f;

if( monsteryawspeedfix.value )
{
if( m_flLastZYawTime == 0.f )
m_flLastZYawTime = gpGlobals->time - gpGlobals->frametime;

float delta = Q_min( gpGlobals->time - m_flLastZYawTime, 0.25f );
m_flLastZYawTime = gpGlobals->time;

speed *= delta;
}
else
speed *= 0.1f;

pev->angles.z = UTIL_Approach( target, pev->angles.z, speed );
}
return CFlyingMonster::ChangeYaw( speed );
return CFlyingMonster::ChangeYaw( yawSpeed );
}

Activity CIchthyosaur::GetStoppedActivity( void )
Expand Down
2 changes: 1 addition & 1 deletion dlls/maprules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void CGamePlayerEquip::KeyValue( KeyValueData *pkvd )
{
char tmp[128];

UTIL_StripToken( pkvd->szKeyName, tmp );
UTIL_StripToken( pkvd->szKeyName, tmp, sizeof( tmp ));

m_weaponNames[i] = ALLOC_STRING( tmp );
m_weaponCount[i] = atoi( pkvd->szValue );
Expand Down
11 changes: 5 additions & 6 deletions dlls/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,8 +2023,6 @@ void CBaseMonster::MonsterInit( void )
SetThink( &CBaseMonster::MonsterInitThink );
pev->nextthink = gpGlobals->time + 0.1f;
SetUse( &CBaseMonster::MonsterUse );

m_flLastYawTime = gpGlobals->time;
}

//=========================================================
Expand Down Expand Up @@ -2509,9 +2507,12 @@ float CBaseMonster::ChangeYaw( int yawSpeed )
{
if( monsteryawspeedfix.value )
{
float delta;
if( m_flLastYawTime == 0.f )
m_flLastYawTime = gpGlobals->time - gpGlobals->frametime;

float delta = Q_min( gpGlobals->time - m_flLastYawTime, 0.25f );

delta = Q_min( gpGlobals->time - m_flLastYawTime, 0.25f );
m_flLastYawTime = gpGlobals->time;

speed = (float)yawSpeed * delta * 2;
}
Expand Down Expand Up @@ -2561,8 +2562,6 @@ float CBaseMonster::ChangeYaw( int yawSpeed )
else
move = 0;

m_flLastYawTime = gpGlobals->time;

return move;
}

Expand Down
2 changes: 1 addition & 1 deletion dlls/mpstubb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int CGraph::FindNearestNode( const Vector &vecOrigin, int afNodeTypes ) { return
/*********************************************************/

void CBaseMonster::ReportAIState( void ) { }
float CBaseMonster::ChangeYaw( int speed ) { return 0; }
float CBaseMonster::ChangeYaw( int yawSpeed ) { return 0; }
void CBaseMonster::MakeIdealYaw( Vector vecTarget ) { }

void CBaseMonster::CorpseFallThink( void )
Expand Down
2 changes: 1 addition & 1 deletion dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void CMultiManager::KeyValue( KeyValueData *pkvd )
{
char tmp[128];

UTIL_StripToken( pkvd->szKeyName, tmp );
UTIL_StripToken( pkvd->szKeyName, tmp, sizeof( tmp ));
m_iTargetName[m_cTargets] = ALLOC_STRING( tmp );
m_flTargetDelay[m_cTargets] = atof( pkvd->szValue );
m_cTargets++;
Expand Down
12 changes: 7 additions & 5 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,8 @@ void UTIL_StringToVector( float *pVector, const char *pString )
char *pstr, *pfront, tempString[128];
int j;

strcpy( tempString, pString );
strncpy( tempString, pString, sizeof( tempString ));
tempString[sizeof( tempString ) - 1] = '\0';
pstr = pfront = tempString;

for( j = 0; j < 3; j++ ) // lifted from pr_edict.c
Expand Down Expand Up @@ -1355,7 +1356,8 @@ void UTIL_StringToIntArray( int *pVector, int count, const char *pString )
char *pstr, *pfront, tempString[128];
int j;

strcpy( tempString, pString );
strncpy( tempString, pString, sizeof( tempString ));
tempString[sizeof( tempString ) - 1] = '\0';
pstr = pfront = tempString;

for( j = 0; j < count; j++ ) // lifted from pr_edict.c
Expand Down Expand Up @@ -1560,11 +1562,11 @@ float UTIL_DotPoints( const Vector &vecSrc, const Vector &vecCheck, const Vector
//=========================================================
// UTIL_StripToken - for redundant keynames
//=========================================================
void UTIL_StripToken( const char *pKey, char *pDest )
void UTIL_StripToken( const char *pKey, char *pDest, int nLen )
{
int i = 0;

while( pKey[i] && pKey[i] != '#' )
while( i < nLen - 1 && pKey[i] && pKey[i] != '#' )
{
pDest[i] = pKey[i];
i++;
Expand Down Expand Up @@ -2136,7 +2138,7 @@ int CRestore::ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCou
{
fieldNumber = ( i + startField ) % fieldCount;
pTest = &pFields[fieldNumber];
if( !stricmp( pTest->fieldName, pName ) )
if( pTest->fieldName && !stricmp( pTest->fieldName, pName ) )
{
if( !m_global || !(pTest->flags & FTYPEDESC_GLOBAL ) )
{
Expand Down
2 changes: 1 addition & 1 deletion dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ extern void UTIL_LogPrintf( const char *fmt, ... );
// Sorta like FInViewCone, but for nonmonsters.
extern float UTIL_DotPoints ( const Vector &vecSrc, const Vector &vecCheck, const Vector &vecDir );

extern void UTIL_StripToken( const char *pKey, char *pDest );// for redundant keynames
extern void UTIL_StripToken( const char *pKey, char *pDest, int nLen );// for redundant keynames

// Misc functions
extern void SetMovedir(entvars_t* pev);
Expand Down

0 comments on commit 93292f1

Please sign in to comment.