Skip to content

Commit

Permalink
Allow disabling standard HL weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Dec 12, 2024
1 parent 2258464 commit fc52b30
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 128 deletions.
1 change: 1 addition & 0 deletions cl_dll/hl/hl_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ void CBasePlayerWeapon::FallInit( void ) { }
CBaseEntity *CBasePlayerWeapon::Respawn( void ) { return NULL; }
void CBasePlayerWeapon::DefaultTouch( CBaseEntity *pOther ) { }
void CBasePlayerWeapon::DestroyItem( void ) { }
bool CBasePlayerWeapon::IsEnabledInMod() { return true; }
int CBasePlayerWeapon::AddToPlayer( CBasePlayer *pPlayer ) { return TRUE; }
void CBasePlayerWeapon::Drop( void ) { }
void CBasePlayerWeapon::Kill( void ) { }
Expand Down
9 changes: 0 additions & 9 deletions dlls/displacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ void CDisplacer::Precache(void)
m_usDisplacer = PRECACHE_EVENT(1, "events/displacer.sc");
}

bool CDisplacer::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_DISPLACER);
#else
return true;
#endif
}

BOOL CDisplacer::Deploy()
{
return DefaultDeploy("models/v_displacer.mdl", "models/p_displacer.mdl", DISPLACER_DRAW, "egon");
Expand Down
9 changes: 0 additions & 9 deletions dlls/eagle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ void CEagle::Precache( void )
m_usEagle = PRECACHE_EVENT( 1, "events/eagle.sc" );
}

bool CEagle::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_EAGLE);
#else
return true;
#endif
}

int CEagle::AddToPlayer(CBasePlayer *pPlayer)
{
return AddToPlayerDefault(pPlayer);
Expand Down
61 changes: 54 additions & 7 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ ModFeatures::ModFeatures()
monstersCount = 0;
maxAmmoCount = 0;

EnableDefaultWeapons();

memset(nvg_sound_on, 0, sizeof(StringBuf));
memset(nvg_sound_off, 0, sizeof(StringBuf));

Expand Down Expand Up @@ -290,9 +292,26 @@ bool ModFeatures::UpdateFloat(const char *value, float &result, const char *key)
return success;
}

bool ModFeatures::EnableWeapon(const char *name)
bool ModFeatures::EnableWeapon(const char *name, bool enable)
{
static const WeaponNameAndId knownWeapons[] = {
WeaponNameAndId("crowbar", WEAPON_CROWBAR),
WeaponNameAndId("9mmhandgun", WEAPON_GLOCK),
WeaponNameAndId("glock", WEAPON_GLOCK),
WeaponNameAndId("357", WEAPON_PYTHON),
WeaponNameAndId("python", WEAPON_PYTHON),
WeaponNameAndId("9mmAR", WEAPON_MP5),
WeaponNameAndId("mp5", WEAPON_MP5),
WeaponNameAndId("shotgun", WEAPON_SHOTGUN),
WeaponNameAndId("crossbow", WEAPON_CROSSBOW),
WeaponNameAndId("rpg", WEAPON_RPG),
WeaponNameAndId("gauss", WEAPON_GAUSS),
WeaponNameAndId("egon", WEAPON_EGON),
WeaponNameAndId("hornetgun", WEAPON_HORNETGUN),
WeaponNameAndId("handgrenade", WEAPON_HANDGRENADE),
WeaponNameAndId("satchel", WEAPON_SATCHEL),
WeaponNameAndId("tripmine", WEAPON_TRIPMINE),
WeaponNameAndId("snark", WEAPON_SNARK),
WeaponNameAndId("pipewrench", WEAPON_PIPEWRENCH),
WeaponNameAndId("knife", WEAPON_KNIFE),
WeaponNameAndId("medkit", WEAPON_MEDKIT),
Expand All @@ -311,13 +330,36 @@ bool ModFeatures::EnableWeapon(const char *name)
{
if (stricmp(name, knownWeapons[i].name) == 0)
{
weapons[knownWeapons[i].id] = true;
weapons[knownWeapons[i].id] = enable;
return true;
}
}
return false;
}

bool ModFeatures::DisableWeapon(const char *name)
{
return EnableWeapon(name, false);
}

void ModFeatures::EnableDefaultWeapons()
{
weapons[WEAPON_CROWBAR] = true;
weapons[WEAPON_GLOCK] = true;
weapons[WEAPON_PYTHON] = true;
weapons[WEAPON_MP5] = true;
weapons[WEAPON_SHOTGUN] = true;
weapons[WEAPON_CROSSBOW] = true;
weapons[WEAPON_RPG] = true;
weapons[WEAPON_GAUSS] = true;
weapons[WEAPON_EGON] = true;
weapons[WEAPON_HORNETGUN] = true;
weapons[WEAPON_HANDGRENADE] = true;
weapons[WEAPON_SATCHEL] = true;
weapons[WEAPON_TRIPMINE] = true;
weapons[WEAPON_SNARK] = true;
}

void ModFeatures::EnableAllWeapons()
{
memset(weapons, 1, sizeof(weapons));
Expand Down Expand Up @@ -435,17 +477,21 @@ byte* LoadFileForMeWithBackup(const char* fileName, const char* fileNameBackup,
return pMemFile;
}

bool IsNonSignificantLine(const char* line)
bool IsNonSignificantLine(const char* line, bool allowMinus = false)
{
return !*line || *line == '/' || !IsValidIdentifierCharacter(*line);
if (!*line || *line == '/')
return true;
if (allowMinus)
return !(IsValidIdentifierCharacter(*line) || *line == '-');
return IsValidIdentifierCharacter(*line);
}

char* TryConsumeToken(char* buffer, const int length)
{
int i = 0;
SkipSpaces(buffer, i, length);

if (IsNonSignificantLine(buffer + i))
if (IsNonSignificantLine(buffer + i, true))
return NULL;

int tokenStart = i;
Expand Down Expand Up @@ -520,8 +566,9 @@ void ReadEnabledWeapons()
char* weaponName = TryConsumeToken(buffer, sizeof(buffer));
if (weaponName)
{
if (g_modFeatures.EnableWeapon(weaponName))
ALERT(at_console, "Enabled weapon '%s'\n", weaponName);
bool enable = *weaponName == '-' ? false : true;
if (g_modFeatures.EnableWeapon(enable ? weaponName : weaponName+1, enable))
ALERT(at_console, "%s weapon '%s'\n", enable ? "Enabled" : "Disabled", weaponName);
else
ALERT(at_warning, "Unknown weapon '%s' in %s\n", weaponName, fileName);
}
Expand Down
4 changes: 3 additions & 1 deletion dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ struct ModFeatures

ModFeatures();
bool SetValue(const char* key, const char* value);
bool EnableWeapon(const char* name);
bool EnableWeapon(const char* name, bool enable = true);
bool DisableWeapon(const char* name);
void EnableDefaultWeapons();
void EnableAllWeapons();

bool IsWeaponEnabled(int weaponId) const;
Expand Down
9 changes: 0 additions & 9 deletions dlls/grapple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,6 @@ void CBarnacleGrapple::Spawn( void )
FallInit();
}

bool CBarnacleGrapple::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_GRAPPLE);
#else
return true;
#endif
}

int CBarnacleGrapple::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
Expand Down
9 changes: 0 additions & 9 deletions dlls/knife.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ void CKnife::Precache(void)
m_usKnife = PRECACHE_EVENT(1, "events/knife.sc");
}

bool CKnife::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_KNIFE);
#else
return true;
#endif
}

int CKnife::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
Expand Down
9 changes: 0 additions & 9 deletions dlls/m249.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ void CM249::Precache(void)
m_usM249 = PRECACHE_EVENT(1, "events/m249.sc");
}

bool CM249::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_M249);
#else
return true;
#endif
}

int CM249::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
Expand Down
9 changes: 0 additions & 9 deletions dlls/medkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,6 @@ void CMedkit::Precache(void)
m_usMedkitFire = PRECACHE_EVENT(1, "events/medkit.sc");
}

bool CMedkit::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_MEDKIT);
#else
return true;
#endif
}

int CMedkit::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
Expand Down
9 changes: 0 additions & 9 deletions dlls/pipewrench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ void CPipeWrench::Precache(void)
m_usPWrench = PRECACHE_EVENT(1, "events/pipewrench.sc");
}

bool CPipeWrench::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_PIPEWRENCH);
#else
return true;
#endif
}

int CPipeWrench::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
Expand Down
9 changes: 0 additions & 9 deletions dlls/shockrifle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ void CShockrifle::Precache(void)
UTIL_PrecacheOther("shock_beam");
}

bool CShockrifle::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_SHOCKRIFLE);
#else
return true;
#endif
}

int CShockrifle::AddToPlayer(CBasePlayer *pPlayer)
{
if (CBasePlayerWeapon::AddToPlayer(pPlayer))
Expand Down
9 changes: 0 additions & 9 deletions dlls/sniperrifle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ void CSniperrifle::Precache( void )
m_usSniper = PRECACHE_EVENT( 1, "events/sniper.sc" );
}

bool CSniperrifle::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_SNIPERRIFLE);
#else
return true;
#endif
}

int CSniperrifle::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
Expand Down
9 changes: 0 additions & 9 deletions dlls/sporelauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ void CSporelauncher::Precache(void)
m_usSporeFire = PRECACHE_EVENT(1, "events/spore.sc");
}

bool CSporelauncher::IsEnabledInMod()
{
#ifndef CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_SPORELAUNCHER);
#else
return true;
#endif
}

int CSporelauncher::AddToPlayer(CBasePlayer *pPlayer)
{
return AddToPlayerDefault(pPlayer);
Expand Down
9 changes: 0 additions & 9 deletions dlls/squeakgrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,15 +743,6 @@ const char* CSqueak::EventsFile() const
#if FEATURE_PENGUIN
LINK_ENTITY_TO_CLASS( weapon_penguin, CPenguin )

bool CPenguin::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WeaponId());
#else
return true;
#endif
}

const char* CPenguin::GrenadeName() const
{
return "monster_penguin";
Expand Down
9 changes: 0 additions & 9 deletions dlls/uzi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ void CUzi::Precache( void )
m_usUzi = PRECACHE_EVENT( 1, "events/uzi.sc" );
}

bool CUzi::IsEnabledInMod()
{
#if !CLIENT_DLL
return g_modFeatures.IsWeaponEnabled(WEAPON_UZI);
#else
return true;
#endif
}

int CUzi::GetItemInfo( ItemInfo *p )
{
p->pszName = STRING( pev->classname );
Expand Down
5 changes: 5 additions & 0 deletions dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,11 @@ int CBasePlayerWeapon::AddDuplicate( CBasePlayerWeapon *pOriginal )
}
}

bool CBasePlayerWeapon::IsEnabledInMod()
{
return g_modFeatures.IsWeaponEnabled(WeaponId());
}

int CBasePlayerWeapon::AddToPlayer( CBasePlayer *pPlayer )
{
m_pPlayer = pPlayer;
Expand Down
Loading

0 comments on commit fc52b30

Please sign in to comment.