From 48b87b4dab243b4cb3894bdc8d021ffa2a465488 Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 19 May 2023 14:17:08 -0400 Subject: [PATCH 1/6] Add Backstab multiplier CKnife member with default value --- regamedll/dlls/weapons.h | 3 +++ regamedll/dlls/wpn_shared/wpn_knife.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index bd22989e3..b78b3fa96 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -1160,6 +1160,7 @@ const float KNIFE_SWING_DAMAGE = 15.0f; const float KNIFE_SWING_DAMAGE_FAST = 20.0f; const float KNIFE_STAB_DISTANCE = 32.0f; const float KNIFE_SWING_DISTANCE = 48.0f; +const float KNIFE_BACKSTAB_MULT = 3.0f; enum knife_e { @@ -1231,6 +1232,8 @@ class CKnife: public CBasePlayerWeapon float m_flStabDistance; float m_flSwingDistance; + + float m_flBackStabMult; }; diff --git a/regamedll/dlls/wpn_shared/wpn_knife.cpp b/regamedll/dlls/wpn_shared/wpn_knife.cpp index 18275c047..66c4c5027 100644 --- a/regamedll/dlls/wpn_shared/wpn_knife.cpp +++ b/regamedll/dlls/wpn_shared/wpn_knife.cpp @@ -50,6 +50,8 @@ void CKnife::Precache() m_flStabDistance = KNIFE_STAB_DISTANCE; m_flSwingDistance = KNIFE_SWING_DISTANCE; + + m_flBackStabMult = KNIFE_BACKSTAB_MULT; } int CKnife::GetItemInfo(ItemInfo *p) @@ -532,10 +534,10 @@ BOOL CKnife::Stab(BOOL fFirst) flDot = DotProduct(vec2LOS, gpGlobals->v_forward.Make2D()); - //Triple the damage if we are stabbing them in the back. + // Multiply the damage if we are stabbing them in the back. if (flDot > 0.80f) { - flDamage *= 3.0f; + flDamage *= m_flBackStabMult; } } From 46b02185598c359f166db7ee5c0fd4b9a67a52d5 Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 19 May 2023 14:35:43 -0400 Subject: [PATCH 2/6] Sort of non trivial code cleaning --- regamedll/dlls/wpn_shared/wpn_knife.cpp | 77 +++++++++++++------------ 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/regamedll/dlls/wpn_shared/wpn_knife.cpp b/regamedll/dlls/wpn_shared/wpn_knife.cpp index 66c4c5027..a03f31121 100644 --- a/regamedll/dlls/wpn_shared/wpn_knife.cpp +++ b/regamedll/dlls/wpn_shared/wpn_knife.cpp @@ -168,14 +168,7 @@ void CKnife::SetPlayerShieldAnim() if (!m_pPlayer->HasShield()) return; - if (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) - { - Q_strcpy(m_pPlayer->m_szAnimExtention, "shield"); - } - else - { - Q_strcpy(m_pPlayer->m_szAnimExtention, "shieldknife"); - } + Q_strcpy(m_pPlayer->m_szAnimExtention, (m_iWeaponState & WPNSTATE_SHIELD_DRAWN) != 0 ? "shield" : "shieldknife"); } void CKnife::ResetPlayerShieldAnim() @@ -305,8 +298,8 @@ BOOL CKnife::Swing(BOOL fFirst) { switch ((m_iSwing++) % 2) { - case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break; - case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break; + case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break; + case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break; } // miss @@ -324,10 +317,15 @@ BOOL CKnife::Swing(BOOL fFirst) m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f; // play wiff or swish sound - if (RANDOM_LONG(0, 1)) - EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash1.wav", VOL_NORM, ATTN_NORM, 0, 94); - else - EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash2.wav", VOL_NORM, ATTN_NORM, 0, 94); + EMIT_SOUND_DYN(m_pPlayer->edict(), + CHAN_WEAPON, + RANDOM_LONG(0, 1) ? + "weapons/knife_slash1.wav" : + "weapons/knife_slash2.wav", + VOL_NORM, + ATTN_NORM, + 0, + 94); // player "shoot" animation m_pPlayer->SetAnimation(PLAYER_ATTACK1); @@ -342,8 +340,8 @@ BOOL CKnife::Swing(BOOL fFirst) { switch ((m_iSwing++) % 2) { - case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break; - case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break; + case 0: SendWeaponAnim(KNIFE_MIDATTACK1HIT, UseDecrement() != FALSE); break; + case 1: SendWeaponAnim(KNIFE_MIDATTACK2HIT, UseDecrement() != FALSE); break; } m_flNextPrimaryAttack = GetNextAttackDelay(0.4); @@ -370,10 +368,13 @@ BOOL CKnife::Swing(BOOL fFirst) m_pPlayer->SetAnimation(PLAYER_ATTACK1); ClearMultiDamage(); - if (m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase()) - pEntity->TraceAttack(m_pPlayer->pev, m_flSwingBaseDamage_Fast, gpGlobals->v_forward, &tr, (DMG_NEVERGIB | DMG_BULLET)); - else - pEntity->TraceAttack(m_pPlayer->pev, m_flSwingBaseDamage, gpGlobals->v_forward, &tr, (DMG_NEVERGIB | DMG_BULLET)); + pEntity->TraceAttack(m_pPlayer->pev, + (m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase()) ? + m_flSwingBaseDamage_Fast : + m_flSwingBaseDamage, + gpGlobals->v_forward, + &tr, + (DMG_NEVERGIB | DMG_BULLET)); ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev); @@ -381,28 +382,27 @@ BOOL CKnife::Swing(BOOL fFirst) if (pEntity) // -V595 #endif { + if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE #ifdef REGAMEDLL_FIXES - if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE && pEntity->Classify() != CLASS_VEHICLE) -#else - if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE) + && pEntity->Classify() != CLASS_VEHICLE #endif + ) { // play thwack or smack sound switch (RANDOM_LONG(0, 3)) { - case 0: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit1.wav", VOL_NORM, ATTN_NORM); break; - case 1: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit2.wav", VOL_NORM, ATTN_NORM); break; - case 2: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit3.wav", VOL_NORM, ATTN_NORM); break; - case 3: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit4.wav", VOL_NORM, ATTN_NORM); break; + case 0: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit1.wav", VOL_NORM, ATTN_NORM); break; + case 1: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit2.wav", VOL_NORM, ATTN_NORM); break; + case 2: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit3.wav", VOL_NORM, ATTN_NORM); break; + case 3: EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_hit4.wav", VOL_NORM, ATTN_NORM); break; } m_pPlayer->m_iWeaponVolume = KNIFE_BODYHIT_VOLUME; if (!pEntity->IsAlive()) return TRUE; - else - flVol = 0.1f; + flVol = 0.1f; fHitWorld = FALSE; } } @@ -488,10 +488,15 @@ BOOL CKnife::Stab(BOOL fFirst) m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f; // play wiff or swish sound - if (RANDOM_LONG(0, 1)) - EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash1.wav", VOL_NORM, ATTN_NORM, 0, 94); - else - EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_slash2.wav", VOL_NORM, ATTN_NORM, 0, 94); + EMIT_SOUND_DYN(m_pPlayer->edict(), + CHAN_WEAPON, + RANDOM_LONG(0, 1)) ? + "weapons/knife_slash1.wav" : + "weapons/knife_slash2.wav", + VOL_NORM, + ATTN_NORM, + 0, + 94); // player "shoot" animation m_pPlayer->SetAnimation(PLAYER_ATTACK1); @@ -551,11 +556,11 @@ BOOL CKnife::Stab(BOOL fFirst) if (pEntity) // -V595 #endif { + if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE #ifdef REGAMEDLL_FIXES - if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE && pEntity->Classify() != CLASS_VEHICLE) -#else - if (pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE) + && pEntity->Classify() != CLASS_VEHICLE #endif + ) { EMIT_SOUND(m_pPlayer->edict(), CHAN_WEAPON, "weapons/knife_stab.wav", VOL_NORM, ATTN_NORM); m_pPlayer->m_iWeaponVolume = KNIFE_BODYHIT_VOLUME; From da324f1e7484b95d4d9b0906b214de5eb600284f Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 19 May 2023 14:38:35 -0400 Subject: [PATCH 3/6] Forgotten default assignation on Spawn --- regamedll/dlls/wpn_shared/wpn_knife.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/regamedll/dlls/wpn_shared/wpn_knife.cpp b/regamedll/dlls/wpn_shared/wpn_knife.cpp index a03f31121..39e8aad12 100644 --- a/regamedll/dlls/wpn_shared/wpn_knife.cpp +++ b/regamedll/dlls/wpn_shared/wpn_knife.cpp @@ -19,6 +19,8 @@ void CKnife::Spawn() m_flStabDistance = KNIFE_STAB_DISTANCE; m_flSwingDistance = KNIFE_SWING_DISTANCE; + m_flBackStabMult = KNIFE_BACKSTAB_MULT; + // Get ready to fall down FallInit(); From 541c2666aec59b6e1d5740ff2ce61521f3baae01 Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 19 May 2023 14:42:46 -0400 Subject: [PATCH 4/6] Typo --- regamedll/dlls/wpn_shared/wpn_knife.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regamedll/dlls/wpn_shared/wpn_knife.cpp b/regamedll/dlls/wpn_shared/wpn_knife.cpp index 39e8aad12..6ea18f63b 100644 --- a/regamedll/dlls/wpn_shared/wpn_knife.cpp +++ b/regamedll/dlls/wpn_shared/wpn_knife.cpp @@ -492,7 +492,7 @@ BOOL CKnife::Stab(BOOL fFirst) // play wiff or swish sound EMIT_SOUND_DYN(m_pPlayer->edict(), CHAN_WEAPON, - RANDOM_LONG(0, 1)) ? + RANDOM_LONG(0, 1) ? "weapons/knife_slash1.wav" : "weapons/knife_slash2.wav", VOL_NORM, From 1cbe1500cf39e4ca28df98294a7fae617a67efe5 Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 30 Jun 2023 02:06:20 -0400 Subject: [PATCH 5/6] Adding REGAMEDLL_API macros correctly to extended members of CKnife - Added forgotten macros to last commit that included members used mostly on API - Added inline functions for specific values, considering original and new behaviour - Mult -> Multiplier --- regamedll/dlls/weapons.h | 43 ++++++++++++++++++------- regamedll/dlls/wpn_shared/wpn_knife.cpp | 20 ++++++------ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index b78b3fa96..eb896503e 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -1151,16 +1151,16 @@ class CHEGrenade: public CBasePlayerWeapon }; -const float KNIFE_BODYHIT_VOLUME = 128.0f; -const float KNIFE_WALLHIT_VOLUME = 512.0f; -const float KNIFE_MAX_SPEED = 250.0f; -const float KNIFE_MAX_SPEED_SHIELD = 180.0f; -const float KNIFE_STAB_DAMAGE = 65.0f; -const float KNIFE_SWING_DAMAGE = 15.0f; -const float KNIFE_SWING_DAMAGE_FAST = 20.0f; -const float KNIFE_STAB_DISTANCE = 32.0f; -const float KNIFE_SWING_DISTANCE = 48.0f; -const float KNIFE_BACKSTAB_MULT = 3.0f; +const float KNIFE_BODYHIT_VOLUME = 128.0f; +const float KNIFE_WALLHIT_VOLUME = 512.0f; +const float KNIFE_MAX_SPEED = 250.0f; +const float KNIFE_MAX_SPEED_SHIELD = 180.0f; +const float KNIFE_STAB_DAMAGE = 65.0f; +const float KNIFE_SWING_DAMAGE = 15.0f; +const float KNIFE_SWING_DAMAGE_FAST = 20.0f; +const float KNIFE_STAB_DISTANCE = 32.0f; +const float KNIFE_SWING_DISTANCE = 48.0f; +const float KNIFE_BACKSTAB_MULTIPLIER = 3.0f; enum knife_e { @@ -1221,10 +1221,17 @@ class CKnife: public CBasePlayerWeapon void SetPlayerShieldAnim(); void ResetPlayerShieldAnim(); + float KnifeStabDamage() const; + float KnifeSwingDamage(bool fast) const; + float KnifeStabDistance() const; + float KnifeSwingDistance() const; + float KnifeBackStabMultiplier() const; + private: TraceResult m_trHit; unsigned short m_usKnife; +#ifdef REGAMEDLL_API // Extra RegameDLL features float m_flStabBaseDamage; float m_flSwingBaseDamage; @@ -1233,9 +1240,23 @@ class CKnife: public CBasePlayerWeapon float m_flStabDistance; float m_flSwingDistance; - float m_flBackStabMult; + float m_flBackStabMultiplier; +#endif }; +#ifdef REGAMEDLL_API +inline float CKnife::KnifeStabDamage() const { return m_flStabBaseDamage; } +inline float CKnife::KnifeSwingDamage(bool fast) const { return fast ? m_flSwingBaseDamage_Fast : m_flSwingBaseDamage; } +inline float CKnife::KnifeStabDistance() const { return m_flStabDistance; } +inline float CKnife::KnifeSwingDistance() const { return m_flSwingDistance; } +inline float CKnife::KnifeBackStabMultiplier() const { return m_flBackStabMultiplier; } +#else +inline float CKnife::KnifeStabDamage() const { return KNIFE_STAB_DAMAGE; } +inline float CKnife::KnifeSwingDamage(bool fast) const { return fast ? KNIFE_SWING_DAMAGE_FAST : KNIFE_SWING_DAMAGE; } +inline float CKnife::KnifeStabDistance() const { return KNIFE_STAB_DISTANCE; } +inline float CKnife::KnifeSwingDistance() const { return KNIFE_SWING_DISTANCE; } +inline float CKnife::KnifeBackStabMultiplier() const { return KNIFE_BACKSTAB_MULTIPLIER; } +#endif // REGAMEDLL_API const float M249_MAX_SPEED = 220.0f; const float M249_DAMAGE = 32.0f; diff --git a/regamedll/dlls/wpn_shared/wpn_knife.cpp b/regamedll/dlls/wpn_shared/wpn_knife.cpp index 6ea18f63b..aa7e177cf 100644 --- a/regamedll/dlls/wpn_shared/wpn_knife.cpp +++ b/regamedll/dlls/wpn_shared/wpn_knife.cpp @@ -12,6 +12,7 @@ void CKnife::Spawn() m_iWeaponState &= ~WPNSTATE_SHIELD_DRAWN; m_iClip = WEAPON_NOCLIP; +#ifdef REGAMEDLL_API m_flStabBaseDamage = KNIFE_STAB_DAMAGE; m_flSwingBaseDamage = KNIFE_SWING_DAMAGE; m_flSwingBaseDamage_Fast = KNIFE_SWING_DAMAGE_FAST; @@ -19,7 +20,8 @@ void CKnife::Spawn() m_flStabDistance = KNIFE_STAB_DISTANCE; m_flSwingDistance = KNIFE_SWING_DISTANCE; - m_flBackStabMult = KNIFE_BACKSTAB_MULT; + m_flBackStabMultiplier = KNIFE_BACKSTAB_MULTIPLIER; +#endif // Get ready to fall down FallInit(); @@ -46,6 +48,7 @@ void CKnife::Precache() m_usKnife = PRECACHE_EVENT(1, "events/knife.sc"); +#ifdef REGAMEDLL_API m_flStabBaseDamage = KNIFE_STAB_DAMAGE; m_flSwingBaseDamage = KNIFE_SWING_DAMAGE; m_flSwingBaseDamage_Fast = KNIFE_SWING_DAMAGE_FAST; @@ -53,7 +56,8 @@ void CKnife::Precache() m_flStabDistance = KNIFE_STAB_DISTANCE; m_flSwingDistance = KNIFE_SWING_DISTANCE; - m_flBackStabMult = KNIFE_BACKSTAB_MULT; + m_flBackStabMultiplier = KNIFE_BACKSTAB_MULTIPLIER; +#endif } int CKnife::GetItemInfo(ItemInfo *p) @@ -268,7 +272,7 @@ BOOL CKnife::Swing(BOOL fFirst) UTIL_MakeVectors(m_pPlayer->pev->v_angle); vecSrc = m_pPlayer->GetGunPosition(); - vecEnd = vecSrc + gpGlobals->v_forward * m_flSwingDistance; + vecEnd = vecSrc + gpGlobals->v_forward * KnifeSwingDistance(); UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr); @@ -371,9 +375,7 @@ BOOL CKnife::Swing(BOOL fFirst) ClearMultiDamage(); pEntity->TraceAttack(m_pPlayer->pev, - (m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase()) ? - m_flSwingBaseDamage_Fast : - m_flSwingBaseDamage, + KnifeSwingDamage(m_flNextPrimaryAttack + 0.4f < UTIL_WeaponTimeBase()), gpGlobals->v_forward, &tr, (DMG_NEVERGIB | DMG_BULLET)); @@ -453,7 +455,7 @@ BOOL CKnife::Stab(BOOL fFirst) UTIL_MakeVectors(m_pPlayer->pev->v_angle); vecSrc = m_pPlayer->GetGunPosition(); - vecEnd = vecSrc + gpGlobals->v_forward * m_flStabDistance; + vecEnd = vecSrc + gpGlobals->v_forward * KnifeStabDistance(); UTIL_TraceLine(vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr); @@ -526,7 +528,7 @@ BOOL CKnife::Stab(BOOL fFirst) // player "shoot" animation m_pPlayer->SetAnimation(PLAYER_ATTACK1); - float flDamage = m_flStabBaseDamage; + float flDamage = KnifeStabDamage(); if (pEntity && pEntity->IsPlayer()) { @@ -544,7 +546,7 @@ BOOL CKnife::Stab(BOOL fFirst) // Multiply the damage if we are stabbing them in the back. if (flDot > 0.80f) { - flDamage *= m_flBackStabMult; + flDamage *= KnifeBackStabMultiplier(); } } From f6b975cdbb49f3e309f9e77bcb70b8e67489f532 Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 30 Jun 2023 02:10:40 -0400 Subject: [PATCH 6/6] lmao --- regamedll/dlls/weapons.h | 1 - 1 file changed, 1 deletion(-) diff --git a/regamedll/dlls/weapons.h b/regamedll/dlls/weapons.h index eb896503e..739d1538c 100644 --- a/regamedll/dlls/weapons.h +++ b/regamedll/dlls/weapons.h @@ -1232,7 +1232,6 @@ class CKnife: public CBasePlayerWeapon unsigned short m_usKnife; #ifdef REGAMEDLL_API - // Extra RegameDLL features float m_flStabBaseDamage; float m_flSwingBaseDamage; float m_flSwingBaseDamage_Fast;