General SDK Snippets & Fixes: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎Schrodinger's/Quantum crouch fix: Give line numbers, people!)
(Precache new scriptsound in npc_combine.cpp for the "Restoring the Combine Elite Soldier's ability to use the alt-fire of the SMG1" tutorial)
 
(35 intermediate revisions by 12 users not shown)
Line 1: Line 1:
__FORCETOC__
__FORCETOC__


=Replace zombie blood with human blood=
= Snippets =


Human blood for zombies.
== Half-Life 2 Deathmatch crashes the host at death (most often from an explosion) ==
 
In '''src/game/server/hl2/npc_zombie.cpp''', go to line 279.


Go to {{path|src/game/shared/multiplay_gamerules|cpp}} and in the void CMultiplayRules::DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info ) (approx. line 814) find the lines:
<source lang="cpp">
<source lang="cpp">
#ifdef HL2_EPISODIC
if ( pInflictor == pScorer )
      SetBloodColor ( BLOOD_COLOR_ZOMBIE );
{
// If the inflictor is the killer,  then it must be their current weapon doing the damage
if ( pScorer->GetActiveWeapon() )
{
#ifdef HL1MP_DLL
killer_weapon_name = pScorer->GetActiveWeapon()->GetClassname();
#else
killer_weapon_name = pScorer->GetActiveWeapon()->GetDeathNoticeName();
#endif
}
}
else
{
killer_weapon_name = STRING( pInflictor->m_iClassname ); // it's just that easy
}
</source>
</source>
 
And simply change it to:
Modify it to look like this:
<source lang="cpp">
<source lang="cpp">
#ifdef HL2_EPISODIC
killer_weapon_name = STRING( pInflictor->m_iClassname );
      SetBloodColor ( BLOOD_COLOR_RED );
</source>
</source>


=Remove headcrab from zombies=
== Fixing imported CS:S weapons in HL2 based mods ==
 
How to remove headcrab from zombies.
 
In '''src/game/server/hl2/npc_zombie.cpp''' look for <code>void CZombie::Spawn( void )</code> then find this line.
<source lang="cpp">
m_fIsHeadless = false;
</source>
 
and simply change it to this
<source lang="cpp">
m_fIsHeadless = true;
</source>
 
Now open '''src/game/server/hl2/npc_BaseZombie.cpp''' and change the <code>HeadcrabRelease_t CNPC_BaseZombie::ShouldReleaseHeadcrab( const CTakeDamageInfo &info, float flDamageThreshold )</code> section to look like this:
<source lang="cpp">
//-----------------------------------------------------------------------------
// Purpose: A zombie has taken damage. Determine whether he release his headcrab.
// Output : YES, IMMEDIATE, or SCHEDULED (see HeadcrabRelease_t)
//-----------------------------------------------------------------------------
HeadcrabRelease_t CNPC_BaseZombie::ShouldReleaseHeadcrab( const CTakeDamageInfo &info, float flDamageThreshold )
{
return ( m_iHealth <= 0 && m_fIsTorso && IsChopped( info ) ) ? RELEASE_RAGDOLL_SLICED_OFF : RELEASE_NO;
}
</source>


=Working CS:S muzzle flashes without model editing=
{{Main|Importing CSS Weapons Into HL2}}


In '''src/game/client/c_baseanimating.cpp''', at line 4130 (after the big switch statement), comment out the code so it looks like this
== Crossbow bolt going through glass (func_breakable) ==
<source lang="cpp">
if ( iAttachment != -1 && m_Attachments.Count() > iAttachment )
{
/*
GetAttachment( iAttachment+1, attachOrigin, attachAngles );
int entId = render->GetViewEntity();
ClientEntityHandle_t hEntity = ClientEntityList().EntIndexToHandle( entId );
tempents->MuzzleFlash( attachOrigin, attachAngles, atoi( options ), hEntity, bFirstPerson );
*/
}
</source>


and insert the following code below the commented out code.
Open {{path|src/game/server/hl2/weapon_crossbow|cpp}}
<source lang="cpp">
if ( input->CAM_IsThirdPerson() )
{
C_BaseCombatWeapon *pWeapon = GetActiveWeapon();
pWeapon->GetAttachment( iAttachment+1, attachOrigin, attachAngles );
}
else
{
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
CBaseViewModel *vm = pPlayer->GetViewModel();
vm->GetAttachment( iAttachment+1, attachOrigin, attachAngles );
engine->GetViewAngles( attachAngles );
}
g_pEffects->MuzzleFlash( attachOrigin, attachAngles, 1.0, MUZZLEFLASH_TYPE_DEFAULT );
</source>
 
Go to '''src/game/client/fx.cpp''', under the statement <code>pParticle->m_vecVelocity.Init();</code> in <code>void FX_MuzzleEffect( ... )</code>, place the following code.
<source lang="cpp">
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
Vector velocity = pPlayer->GetLocalVelocity();
pParticle->m_vecVelocity += velocity;
</source>
 
=Crossbow bolt going through glass (func_breakable)=
 
Open '''src/game/server/hl2/weapon_crossbow.cpp'''


Start off by adding <code>#include "func_break.h"</code>
Start off by adding <code>#include "func_break.h"</code>


Then in <code>CCrossbowBolt::BoltTouch( CBaseEntity *pOther )</code>, after:
Then in {{Code|highlight=c|CCrossbowBolt::BoltTouch( CBaseEntity *pOther )}}, after:
<source lang="cpp">
<source lang="cpp">
if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS )
if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS )
Line 108: Line 58:
{{todo|This could be taken further, allowing the bolts to go through <code>matWeb</code> or through any '''func_breakable_surf''' for example.}}
{{todo|This could be taken further, allowing the bolts to go through <code>matWeb</code> or through any '''func_breakable_surf''' for example.}}


=Ignite ragdolls=
== Ignite ragdolls ==


In your player's class (<code>CSDKPlayer</code> or <code>CBasePlayer</code>) find the <code>Event_Killed()</code> function. Add this inside of it:
In your player's class (<code>CSDKPlayer</code> or <code>CBasePlayer</code>) find the <code>Event_Killed()</code> function. Add this inside of it:
Line 128: Line 78:
If you're not doing that, add it in right above the <code>if( info.GetDamageType() & (DMG_BLAST|DMG_BURN) )</code> line.
If you're not doing that, add it in right above the <code>if( info.GetDamageType() & (DMG_BLAST|DMG_BURN) )</code> line.


=Control height and width of icon progress bars=
== Control height and width of icon progress bars ==


This allows you to control the height and width of progress bars drawn with icons instead of the bars being the same dimensions as the textures.<br>
This allows you to control the height and width of progress bars drawn with icons instead of the bars being the same dimensions as the textures.<br>
In the file '''src/game/client/hud.h''' add the function declaration:
In the file {{path|src/game/client/hud|h}} add the function declaration:
<source lang="cpp">
<source lang="cpp">
void DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color &clr, int type );
void DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color &clr, int type );
Line 141: Line 91:
</source>
</source>


Then in '''src/game/client/hud_redraw.cpp''' add the function itself:
Then in {{path|src/game/client/hud_redraw|cpp}} add the function itself:
<source lang="cpp">
<source lang="cpp">
void CHud::DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type )
void CHud::DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type )
Line 175: Line 125:
This was tested with vertical bars, horizontal bars haven't been tested.
This was tested with vertical bars, horizontal bars haven't been tested.


=Enabling func_precipitation rendering whilst in a point_viewcontrol=
== Enabling func_precipitation rendering whilst in a point_viewcontrol ==


In '''src/game/client/viewrender.cpp''' find and delete:
In {{path|src/game/client/viewrender|cpp}} find and delete:
<source lang="cpp">
<source lang="cpp">
if ( CurrentViewID() == VIEW_MONITOR )
if ( CurrentViewID() == VIEW_MONITOR )
Line 183: Line 133:
</source>
</source>


=Randomizing models=
== Randomizing models ==


Have some global constant char* of every model:
Have some global constant char* of every model:
Line 194: Line 144:
</source>
</source>


And choose one at random in the <code>Spawn()</code> function:
And choose one at random in the {{Code|highlight=c|Spawn()}} function:
<source lang="cpp">
<source lang="cpp">
SetModel (modelnames[ random->RandomInt( 0, ARRAYSIZE(modelnames) - 1 ) ]);
SetModel (modelnames[ random->RandomInt( 0, ARRAYSIZE(modelnames) - 1 ) ]);
Line 204: Line 154:
</source>
</source>


=Stopping viewmodels from getting rotated when zooming=
== Simple camera animation implementation for weapons ==
 
Go to {{path|src/game/client/view|cpp}} then head over to {{Code|highlight=c|void CViewRender::Render( vrect_t *rect )}}
 
Scroll down until you find {{Code|highlight=c|RenderView( view, nClearFlags, flags );}}, then paste this code above it:
<source lang="cpp">
if ( pPlayer && pPlayer->InFirstPersonView() && pPlayer->GetViewModel( 0 ) )
{
int iCamAttachment = pPlayer->GetViewModel( 0 )->LookupAttachment( "camera" );
 
if ( iCamAttachment != -1 )
{
Vector cameraOrigin = Vector(0, 0, 0);
QAngle cameraAngles = QAngle(0, 0, 0);
pPlayer->GetViewModel( 0 )->GetAttachmentLocal( iCamAttachment, cameraOrigin, cameraAngles );
view.angles += cameraAngles;
view.origin += cameraOrigin;
}
}
</source>
 
{{note|Valve uses the  "attach_camera" attachment name in {{l4d2}} and "cam_driver" in {{csgo}}, if you prefer backwards compatibility.}}
 
== A way to suppress the "Node Graph out of Date. Rebuilding..." message ==
 
This snippet will hide the message from appearing unless [[Developer|developer]] mode is enabled.
 
 
Go to {{path|src/game/server/ai_networkmanager|cpp}} then head over to {{Code|highlight=c|void CAI_NetworkManager::DelayedInit( void )}}
 
Scroll down until you find this line of code: (Should be near line 1113)
<source lang="cpp">
UTIL_CenterPrintAll( "Node Graph out of Date. Rebuilding...\n" );
</source>
 
And simply change it this:
<source lang="cpp">
if ( developer.GetBool() )
UTIL_CenterPrintAll( "Node Graph out of Date. Rebuilding...\n" );
</source>
 
{{idea|For those of you that want to keep this in but wants to spice things up a bit, replace '''"Rebuilding..."''' with '''"Refunding..."'''}}
 
== Self casting player shadows ==


In '''src/game/client/view.cpp''' find <code>void CViewRender::SetUpViews()</code> and search for the line
Go to {{path|src/game/client/c_baseplayer|h}}, scroll down until you find
<source lang=cpp>
virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; }
</source>
 
and simply change that to:
<source lang=cpp>
virtual ShadowType_t ShadowCastType() { return SHADOWS_RENDER_TO_TEXTURE_DYNAMIC; }
</source>
 
Your playermodel (by default '''player.mdl''') should now cast shadows.
 
== Enabling shadow receiving on viewmodels ==
 
Go to {{path|src/game/shared/baseviewmodel_shared|h}}, scroll down until you find
<source lang=cpp>
virtual bool ShouldReceiveProjectedTextures( int flags )
{
return false;
}
</source>
 
and simply change that to:
<source lang=cpp>
virtual bool ShouldReceiveProjectedTextures( int flags )
{
return true;
}
</source>
 
Your viewmodels should now be able to receive shadows.
 
== Seamless cubemaps hack ==
 
Go to {{path|src/game/client/viewrender|cpp}}, scroll down until you find the {{Code|highlight=c|RenderView( ... )}} function, then add this snippet:
<source lang=cpp highlight=7-8>
void CViewRender::RenderView( const CViewSetup &viewIn, int nClearFlags, int whatToDraw )
{
m_UnderWaterOverlayMaterial.Shutdown(); // underwater view will set
 
m_CurrentView = view;
 
if ( building_cubemaps.GetBool() )
m_CurrentView.fov = RAD2DEG( 2.0f * atanf( 64.0f / ( 64 - 0.5f ) ) );
}
</source>
 
You should now have seamless cubemaps!
 
== Remove ear ringing from explosions ==
 
If you find the ear ringing to be annoying and want to remove it, simply go to {{path|src/game/server/player|cpp}}, go to  {{Code|highlight=c|void CBasePlayer::OnDamagedByExplosion}}, find this line:
<source lang=cpp>
int effect = shock ?
random->RandomInt( 35, 37 ) :
random->RandomInt( 32, 34 );
</source>
and replace it with this:
<source lang=cpp>
int effect =  random->RandomInt( 32, 34 );
</source>
 
= Fixes =
== Stopping viewmodels from getting rotated when zooming ==
 
In {{path|src/game/client/view|cpp}} find {{Code|highlight=c|void CViewRender::SetUpViews()}} and search for the line
<source lang="cpp">
<source lang="cpp">
view.fovViewmodel = g_pClientMode->GetViewModelFOV() - flFOVOffset;
view.fovViewmodel = g_pClientMode->GetViewModelFOV() - flFOVOffset;
Line 213: Line 271:
and replace it with
and replace it with
<source lang="cpp">
<source lang="cpp">
view.fovViewmodel = fabs(g_pClientMode->GetViewModelFOV() - flFOVOffset);
view.fovViewmodel = fabs( g_pClientMode->GetViewModelFOV() - flFOVOffset );
</source>
</source>


That will simply stop negative FOVs to occur, which were causing a rotating of 180°.
That will simply stop negative FOVs to occur, which were causing a rotating of 180°.


=Restoring the Combine Elite Soldier's ability to use the alt-fire of the SMG1=
== Restoring the Combine Elite Soldier's ability to use the alt-fire of the SMG1 ==


In '''src/game/server/hl2/weapon_smg1.cpp''', go to line 48 and replace <code>WeaponRangeAttack2Condition( float flDot, float flDist )</code> with this:
In {{path|src/game/server/hl2/weapon_smg1|cpp}}, go to line 48 and replace {{Code|highlight=c|WeaponRangeAttack2Condition( float flDot, float flDist )}} with this:
<source lang="cpp">
<source lang="cpp">
int WeaponRangeAttack2Condition();
int WeaponRangeAttack2Condition();
Line 271: Line 329:
</source>
</source>


Now go to the <code>int CWeaponSMG1::WeaponRangeAttack2Condition( float flDot, float flDist )</code> function and replace it with this:
Now go to the {{Code|highlight=c|int CWeaponSMG1::WeaponRangeAttack2Condition( float flDot, float flDist )}} function and replace it with this:
<source lang="cpp">
<source lang="cpp">
int CWeaponSMG1::WeaponRangeAttack2Condition()
int CWeaponSMG1::WeaponRangeAttack2Condition()
Line 281: Line 339:
</source>
</source>


For the last step, since this is only cosmetic, go to '''src/game/server/hl2/npc_combine.cpp'''.
For the last step, since this is only cosmetic, go to {{path|src/game/server/hl2/npc_combine|cpp}}.


On line 381, disable the <code>DevWarning</code> (only in case you don't want to see it neither on DEV mode):
On line 381, disable the <code>DevWarning</code> (only in case you don't want to see it neither on DEV mode):
Line 309: Line 367:
</source>
</source>


=Restoring dropship container gun rotation functionality=
At around line 279, don't forget to precache the SMG1 alt-fire sound effect in CNPC_Combine::Precache
<source lang="cpp">
void CNPC_Combine::Precache()
{
PrecacheModel("models/Weapons/w_grenade.mdl");
UTIL_PrecacheOther( "npc_handgrenade" );


This is to make it so that the gun on the combine dropship can rotate again
PrecacheScriptSound( "NPC_Combine.GrenadeLaunch" );
PrecacheScriptSound( "NPC_Combine.WeaponBash" );
PrecacheScriptSound( "Weapon_CombineGuard.Special1" );
PrecacheScriptSound( "Weapon_SMG1.Double" ); // SMG1 Alt-Fire sound


Go to line 873 in '''src/game/server/hl2/npc_combinedropship.cpp''' and add these two lines to the bottom of the <code>if ( m_hContainer )</code> statement:
BaseClass::Precache();
<source lang="cpp">
}
m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );
</source>
</source>


Now your gun should rotate and shoot again!
== Restoring [[Dropship]] container gun rotation functionality ==
This bug has been fixed in the 2022 {{steamdeck|1}} update for {{hl2|4}} (and it's episodes), but the SDK 2007 and SDK 2013 code (including {{tob|1}} on console) still remains unfixed.


=Fixing the acid damage white flash sticking around bug=
To fix the Dropship gun rotation, follow the instructions:


This is a very easy fix, I'm surprised no one has patched this.
Go to line 898 in {{path|src/game/server/hl2/npc_combinedropship|cpp}} and in the {{Code|highlight=c|Spawn( void )}} function insert the following lines


Go to '''src/game/shared/hl2/hl2_gamerules.cpp''' and at line 209 add <code>DMG_ACID</code>, like so:
<source lang="cpp">
<source lang="cpp">
return ( ( iDmgType & ( DMG_PARALYZE | DMG_NERVEGAS | DMG_POISON | DMG_RADIATION | DMG_DROWNRECOVER | DMG_ACID | DMG_SLOWBURN ) ) != 0 );
// Store spawned container weapon pitch and yaw pose parameters to allow weapon point to the player
m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );
</source>
</source>


And it's fixed. Someone, please spread this knowledge.
so the <code>Spawn( void )</code> function code fragment will look like this


=Schrodinger's/Quantum crouch fix=
<source lang="cpp">
m_iMachineGunBaseAttachment = m_hContainer->LookupAttachment( "gun_base" );
// NOTE: gun_ref must have the same position as gun_base, but rotates with the gun
m_iMachineGunRefAttachment = m_hContainer->LookupAttachment( "gun_ref" );
// Store spawned container weapon pitch and yaw pose parameters to allow weapon point to the player
m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );
</source>


See: https://wiki.sourceruns.org/wiki/Schrodinger's_Crouch
Go to line 864 in {{path|src/game/server/hl2/npc_combinedropship|cpp}} and in the {{Code|highlight=c|Spawn( void )}} function insert the following lines
<source lang="cpp">
m_poseWeapon_Pitch = -1;
m_poseWeapon_Yaw = -1;
</source>


so the <code>Spawn( void )</code> function code fragment will look like this


Another easy fix.
<source lang="cpp">
m_iAttachmentTroopDeploy = -1;
m_iAttachmentDeployStart = -1;
m_poseWeapon_Pitch = -1;
m_poseWeapon_Yaw = -1;


Go to '''src/game/shared/gamemovement.cpp''' then head over to <code>void CGameMovement::FinishDuck( void )</code> (Line 4194)
// create the correct bin for the ship to carry
switch ( m_iCrateType )
{
case CRATE_ROLLER_HOPPER:
break;
</source>


At the very top, you should see this:
Go to line 397 in {{path|src/game/server/hl2/npc_combinedropship|cpp}} and in the {{Code|highlight=c|PopulatePoseParameters( void )}} function add the following lines
<source lang="cpp">
<source lang="cpp">
if ( player->GetFlags() & FL_DUCKING )
// Dropship has any kind of container
return;
if ( m_hContainer )
{
// Restore container weapon pose parameters on load if any found
m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );
}
</source>
</source>


Now all you have to do is comment it out, that's it!
Go to line 392 in {{path|src/game/server/hl2/npc_combinedropship|cpp}} and in the {{Code|highlight=cpp|PopulatePoseParameters( void )}} function remove the following lines
<source lang="cpp">
m_poseWeapon_Pitch = LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw = LookupPoseParameter( "weapon_yaw" );
</source>


=Simple camera animation implementation for weapons=
so the final <code>PopulatePoseParameters( void )</code> function will look like this


Go to '''src/game/client/view.cpp''' then head over to <code>void CViewRender::Render( vrect_t *rect )</code>
Scroll down until you find <code>RenderView( view, nClearFlags, flags );</code>, then paste this code above it:
<source lang="cpp">
<source lang="cpp">
if ( pPlayer && pPlayer->InFirstPersonView() && pPlayer->GetViewModel( 0 ) )
void CNPC_CombineDropship::PopulatePoseParameters( void )
{
{
int iCamAttachment = pPlayer->GetViewModel( 0 )->LookupAttachment( "camera" );
if (!m_sbStaticPoseParamsLoaded)
{
m_poseBody_Accel = LookupPoseParameter( "body_accel");
m_poseBody_Sway = LookupPoseParameter( "body_sway" );
m_poseCargo_Body_Accel  = LookupPoseParameter( "cargo_body_accel" );
m_poseCargo_Body_Sway  = LookupPoseParameter( "cargo_body_sway" );
 
m_sbStaticPoseParamsLoaded = true;
}


if ( iCamAttachment != -1 )
// Dropship has any kind of container
if ( m_hContainer )
{
{
Vector cameraOrigin = Vector(0, 0, 0);
// Restore container weapon pose parameters on load if any found
QAngle cameraAngles = QAngle(0, 0, 0);
m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
pPlayer->GetViewModel( 0 )->GetAttachmentLocal( iCamAttachment, cameraOrigin, cameraAngles );
m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );
view.angles += cameraAngles;
view.origin += cameraOrigin;
}
}
BaseClass::PopulatePoseParameters();
}
}
</source>
</source>


{{note|Valve uses the "attach_camera" attachment name in {{l4d2}} and "cam_driver" in {{csgo}}, if you prefer backwards compatibility.}}
Go to line 378 in {{path|src/game/server/hl2/npc_combinedropship|cpp}} and remove the following lines
<source lang="cpp">
int CNPC_CombineDropship::m_poseWeapon_Pitch = 0;
int CNPC_CombineDropship::m_poseWeapon_Yaw = 0;
</source>
 
Go to line 366 in {{path|src/game/server/hl2/npc_combinedropship|cpp}} and remove trailing <code>,</code> and the following lines
<source lang="cpp">
m_poseWeapon_Pitch, m_poseWeapon_Yaw
</source>
 
so the code will look like this
 
<source lang="cpp">
static int m_poseBody_Accel, m_poseBody_Sway, m_poseCargo_Body_Accel, m_poseCargo_Body_Sway;
static bool m_sbStaticPoseParamsLoaded;
</source>
 
Go to line 346 in {{path|src/game/server/hl2/npc_combinedropship|cpp}} and add the following lines after <code>int m_iAttachmentDeployStart;</code>
<source lang="cpp">
// Cached container weapon pose parameters
int m_poseWeapon_Pitch;
int m_poseWeapon_Yaw;
</source>
 
so the code will look like this


=A way to suppress the "Node Graph out of Date. Rebuilding..." message=
<source lang="cpp">
int m_iAttachmentTroopDeploy;
int m_iAttachmentDeployStart;


This snippet will hide the message from appearing unless [[Developer|developer]] mode is enabled.
// Cached container weapon pose parameters
int m_poseWeapon_Pitch;
int m_poseWeapon_Yaw;
</source>
 
Now the Dropship gun should rotate and shoot again!


== Fixing the acid damage white flash sticking around bug ==


Go to '''src/game/server/ai_networkmanager.cpp''' then head over to <code>void CAI_NetworkManager::DelayedInit( void )</code>
This is a very easy fix, I'm surprised no one has patched this.


Scroll down until you find this line of code: (Should be near line 1113)
Go to {{path|src/game/shared/hl2/hl2_gamerules|cpp}} and at line 209 add <code>DMG_ACID</code>, like so:
<source lang="cpp">
<source lang="cpp">
UTIL_CenterPrintAll( "Node Graph out of Date. Rebuilding...\n" );
return ( ( iDmgType & ( DMG_PARALYZE | DMG_NERVEGAS | DMG_POISON | DMG_RADIATION | DMG_DROWNRECOVER | DMG_ACID | DMG_SLOWBURN ) ) != 0 );
</source>
</source>


And simply change it this:
And it's fixed. Someone, please spread this knowledge.
 
== Schrodinger's/Quantum crouch fix ==
 
See: https://wiki.sourceruns.org/wiki/Schrodinger's_Crouch
 
 
Another easy fix.
 
Go to {{path|src/game/shared/gamemovement|cpp}} then head over to <code>void CGameMovement::FinishDuck( void )</code> (Line 4194)
 
At the very top, you should see this:
<source lang="cpp">
<source lang="cpp">
if ( developer.GetBool() )
if ( player->GetFlags() & FL_DUCKING )
UTIL_CenterPrintAll( "Node Graph out of Date. Rebuilding...\n" );
return;
</source>
</source>


{{idea|For those of you that want to keep this in but wants to spice things up a bit, replace '''"Rebuilding..."''' with '''"Refunding..."'''}}
Now all you have to do is comment it out, that's it!


=Fixing the NPC not blinking bug=
== Fixing the NPC not blinking bug ==


In Source SDK 2013 NPC's not being able to blink has been a bug for a while.
NPCs not being able to blink has been a bug for mods ever since the SteamPipe update. It was fixed in an update for {{hl2|3.1}} + its Episodes ({{hl2ep1}}/{{hl2ep2}}) on September 26, 2019, but the code was never pushed to the {{src13|3.1}} public repo.




Fixing this is as easy as removing a single line of code.
Fixing this is as easy as correcting a single line of code.


Go to '''src/game/client/c_baseflex.cpp''' then head over to <code>void C_BaseFlex::SetupWeights( ... )</code>
Go to {{path|src/game/client/c_baseflex|cpp}} then head over to the <code>void C_BaseFlex::SetupWeights( ... )</code> function.


And remove the following line:
Then at line 1152 correct the following line of code from:
<source lang=cpp>
<source lang=cpp>
m_iBlink = AddGlobalFlexController( "UH" );
m_iBlink = AddGlobalFlexController( "UH" );
</source>
to
<source lang=cpp>
m_iBlink = AddGlobalFlexController( "blink" );
</source>
</source>


Congratulations! You have successfully fixed NPC blinking, it was as easy as that.
Congratulations! You have successfully fixed NPC blinking, it was as easy as that.


=Fix smooth friction sounds using the incorrect soundhandle=
== Fix smooth friction sounds using the incorrect soundhandle ==


Fixes a tiny inconsistency. The bug causes the incorrect sound params to be used.
Fixes a tiny inconsistency. The bug causes the incorrect sound params to be used.




Go to '''src/game/shared/physics_shared.cpp''' then head over to <code>void PhysFrictionSound( ... )</code>
Go to {{path|src/game/shared/physics_shared|cpp}} then head over to <code>void PhysFrictionSound( ... )</code>


Near the bottom of the function, you should see this line of code within an <code>if</code> statement:
Near the bottom of the function, you should see this line of code within an <code>if</code> statement:
Line 425: Line 575:
</source>
</source>


=Self casting player shadows=
== Restoring the Combine Soldier's ability to emit pain sounds ==


Go to '''src/game/client/hl2/c_basehlplayer.h''' scroll down to <code>bool IsWeaponLowered( void ) { ... }</code>
Go to '''src/game/server/hl2/npc_combine.h''' and find <code>void PainSound( void );</code>


And right below it add this:
And change it to this:
<source lang=cpp>
<source lang=cpp>
virtual ShadowType_t ShadowCastType() { return SHADOWS_RENDER_TO_TEXTURE_DYNAMIC; } // Should this object cast shadows?
void PainSound( const CTakeDamageInfo &info );
</source>
</source>


=Restoring the Combine Soldier's ability to emit pain sounds=
Now head over to {{path|src/game/server/hl2/npc_combine|cpp}} and find <code>void CNPC_Combine::PainSound ( void )</code>


Go to '''src/game/server/hl2/npc_combine.h''' and find <code>void PainSound( void );</code>
And like before, change it to this:
<source lang=cpp>
void CNPC_Combine::PainSound( const CTakeDamageInfo &info )
</source>
 
== Restoring ability to disallow player holstering weapons in Multiplayer ==
Everyone knows about this bug, but fix here is very simple, go to src/game/shared/basecombatweapon_shared.h, then remove <code>const</code> at 248 line.


And change it to this:
Now it should look like:
<source lang=cpp>
<source lang=cpp>
void PainSound( const CTakeDamageInfo &info );
virtual bool CanHolster( void ) { return TRUE; }; // returns true if the weapon can be holstered
</source>
</source>


Now head over to '''src/game/server/hl2/npc_combine.cpp''' and find <code>void CNPC_Combine::PainSound ( void )</code>
That's it, now you can use CanHolster for weapons!


And like before, change it to this:
== Fix env_sun sprite disappearing in sky when you look at it ==
Yet another famous glitch, fix for it is very easy, go to {{path|src/game/client/glow_overlay|cpp}}, find 162 line then replace zFar * 0.999f; with 0.99f;
 
Now it should look like:
<source lang=cpp>
<source lang=cpp>
void CNPC_Combine::PainSound( const CTakeDamageInfo &info )
Vector pos = CurrentViewOrigin() + m_vDirection * zFar * 0.99f;
</source>
</source>


Now env_sun sprite shouldn't disappear when you look at it.
== Fix for viewmodel FOV going into negative integers ==
This glitch is most obvious when using zoom on higher than normal fov's like 120 or 150.
To fix; go to {{path|src/game/client/view|cpp}} and on line 739 change this:
<source lang=cpp>
//Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end
view.fovViewmodel = g_pClientMode->GetViewModelFOV() - flFOVOffset;
</source>
To this:
<source lang=cpp>
//Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end
view.fovViewmodel = fabs( g_pClientMode->GetViewModelFOV() - MIN( flFOVOffset, g_pClientMode->GetViewModelFOV() ) );
</source>
Now viewmodels won't look super wonky when zooming with higher than normal fov's!


[[Category:Snippets]][[Category:Programming]]
[[Category:Snippets]]
[[Category:Bug fixes]]
[[Category:C++]]

Latest revision as of 04:55, 15 August 2025


Snippets

Half-Life 2 Deathmatch crashes the host at death (most often from an explosion)

Go to 🖿src/game/shared/multiplay_gamerules.cpp and in the void CMultiplayRules::DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info ) (approx. line 814) find the lines:

					if ( pInflictor == pScorer )
					{
						// If the inflictor is the killer,  then it must be their current weapon doing the damage
						if ( pScorer->GetActiveWeapon() )
						{
#ifdef HL1MP_DLL
							killer_weapon_name = pScorer->GetActiveWeapon()->GetClassname();
#else
							killer_weapon_name = pScorer->GetActiveWeapon()->GetDeathNoticeName();
#endif
						}
					}
					else
					{
						killer_weapon_name = STRING( pInflictor->m_iClassname );  // it's just that easy
					}

And simply change it to:

killer_weapon_name = STRING( pInflictor->m_iClassname );

Fixing imported CS:S weapons in HL2 based mods

Crossbow bolt going through glass (func_breakable)

Open 🖿src/game/server/hl2/weapon_crossbow.cpp

Start off by adding #include "func_break.h"

Then in CCrossbowBolt::BoltTouch( CBaseEntity *pOther ), after:

if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS )
	return;

Insert the following code:

if ( FClassnameIs(pOther, "func_breakable") )
{
    CBreakable* pOtherEntity = static_cast<CBreakable*>( pOther );
    if ( pOtherEntity->GetMaterialType() == matGlass )
        return;
}


Todo: This could be taken further, allowing the bolts to go through matWeb or through any func_breakable_surf for example.

Ignite ragdolls

In your player's class (CSDKPlayer or CBasePlayer) find the Event_Killed() function. Add this inside of it:

if( info.GetDamageType() & (DMG_BLAST|DMG_BURN) )
{
    if( m_hRagdoll )
    {
        CBaseAnimating *pRagdoll = (CBaseAnimating *)CBaseEntity::Instance(m_hRagdoll);
        if( info.GetDamageType() & (DMG_BURN|DMG_BLAST) )
        {
            pRagdoll->Ignite(45, false, 10 );
        }
    }
}

If you don't have a ragdoll to ignite before that is called, make sure that code is placed after a call to CreateRagdollEntity(). If you're not doing that, add it in right above the if( info.GetDamageType() & (DMG_BLAST|DMG_BURN) ) line.

Control height and width of icon progress bars

This allows you to control the height and width of progress bars drawn with icons instead of the bars being the same dimensions as the textures.
In the file 🖿src/game/client/hud.h add the function declaration:

void	DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color &clr, int type );

Underneath the old declaration:

void    DrawIconProgressBar( int x, int y, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type );

Then in 🖿src/game/client/hud_redraw.cpp add the function itself:

void CHud::DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type )
{
	if ( icon == NULL )
		return;

	//Clamp our percentage
	percentage = min( 1.0f, percentage );
	percentage = max( 0.0f, percentage );

	int	height = icon->Height();
	int	width  = icon->Width();

	//Draw a vertical progress bar
	if ( type == HUDPB_VERTICAL )
	{
		int	barOfs = height * percentage;

		icon2->DrawSelfCropped( 
			x, y,  // Pos
			0, 0, width, barOfs, // Cropped subrect
			w, (h * percentage), clr );

		icon->DrawSelfCropped( 
			x, y + (h * percentage), 
			0, barOfs, width, height - barOfs, // Cropped subrect
			w, h - (h * percentage), clr );
	}
}

This was tested with vertical bars, horizontal bars haven't been tested.

Enabling func_precipitation rendering whilst in a point_viewcontrol

In 🖿src/game/client/viewrender.cpp find and delete:

if ( CurrentViewID() == VIEW_MONITOR )
   return;

Randomizing models

Have some global constant char* of every model:

static const char* modelnames[] = {
   "Model1", // 0
   "Model2", // 1
   "Model3", // 2
};

And choose one at random in the Spawn() function:

SetModel (modelnames[ random->RandomInt( 0, ARRAYSIZE(modelnames) - 1 ) ]);

And if you wish to have a different skin for each model (provided your model was compiled with multiple skins), then you can add:

m_nSkin = random->RandomInt( 0, GetModelPtr()->numskinfamilies() - 1 );

Simple camera animation implementation for weapons

Go to 🖿src/game/client/view.cpp then head over to void CViewRender::Render( vrect_t *rect )

Scroll down until you find RenderView( view, nClearFlags, flags );, then paste this code above it:

if ( pPlayer && pPlayer->InFirstPersonView() && pPlayer->GetViewModel( 0 ) )
{
	int iCamAttachment = pPlayer->GetViewModel( 0 )->LookupAttachment( "camera" );

	if ( iCamAttachment != -1 )
	{
		Vector cameraOrigin = Vector(0, 0, 0);
		QAngle cameraAngles = QAngle(0, 0, 0);
		pPlayer->GetViewModel( 0 )->GetAttachmentLocal( iCamAttachment, cameraOrigin, cameraAngles );
		view.angles += cameraAngles;
		view.origin += cameraOrigin;
	}
}
Note.pngNote:Valve uses the "attach_camera" attachment name in Left 4 Dead 2 and "cam_driver" in Counter-Strike: Global Offensive, if you prefer backwards compatibility.

A way to suppress the "Node Graph out of Date. Rebuilding..." message

This snippet will hide the message from appearing unless developer mode is enabled.


Go to 🖿src/game/server/ai_networkmanager.cpp then head over to void CAI_NetworkManager::DelayedInit( void )

Scroll down until you find this line of code: (Should be near line 1113)

UTIL_CenterPrintAll( "Node Graph out of Date. Rebuilding...\n" );

And simply change it this:

if ( developer.GetBool() )
	UTIL_CenterPrintAll( "Node Graph out of Date. Rebuilding...\n" );
Tip.pngIdea:For those of you that want to keep this in but wants to spice things up a bit, replace "Rebuilding..." with "Refunding..."

Self casting player shadows

Go to 🖿src/game/client/c_baseplayer.h, scroll down until you find

virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; }

and simply change that to:

virtual ShadowType_t ShadowCastType() { return SHADOWS_RENDER_TO_TEXTURE_DYNAMIC; }

Your playermodel (by default player.mdl) should now cast shadows.

Enabling shadow receiving on viewmodels

Go to 🖿src/game/shared/baseviewmodel_shared.h, scroll down until you find

virtual bool ShouldReceiveProjectedTextures( int flags )
{
	return false;
}

and simply change that to:

virtual bool ShouldReceiveProjectedTextures( int flags )
{
	return true;
}

Your viewmodels should now be able to receive shadows.

Seamless cubemaps hack

Go to 🖿src/game/client/viewrender.cpp, scroll down until you find the RenderView( ... ) function, then add this snippet:

void CViewRender::RenderView( const CViewSetup &viewIn, int nClearFlags, int whatToDraw )
{
	m_UnderWaterOverlayMaterial.Shutdown();					// underwater view will set

	m_CurrentView = view;

	if ( building_cubemaps.GetBool() )
		m_CurrentView.fov = RAD2DEG( 2.0f * atanf( 64.0f / ( 64 - 0.5f ) ) );
}

You should now have seamless cubemaps!

Remove ear ringing from explosions

If you find the ear ringing to be annoying and want to remove it, simply go to 🖿src/game/server/player.cpp, go to void CBasePlayer::OnDamagedByExplosion, find this line:

int effect = shock ? 
		random->RandomInt( 35, 37 ) : 
		random->RandomInt( 32, 34 );

and replace it with this:

int effect =  random->RandomInt( 32, 34 );

Fixes

Stopping viewmodels from getting rotated when zooming

In 🖿src/game/client/view.cpp find void CViewRender::SetUpViews() and search for the line

view.fovViewmodel = g_pClientMode->GetViewModelFOV() - flFOVOffset;

and replace it with

view.fovViewmodel = fabs( g_pClientMode->GetViewModelFOV() - flFOVOffset );

That will simply stop negative FOVs to occur, which were causing a rotating of 180°.

Restoring the Combine Elite Soldier's ability to use the alt-fire of the SMG1

In 🖿src/game/server/hl2/weapon_smg1.cpp, go to line 48 and replace WeaponRangeAttack2Condition( float flDot, float flDist ) with this:

int WeaponRangeAttack2Condition();

Now from the lines 249 to 274 (all the disabled code) replace it with this code:

case EVENT_WEAPON_AR2_ALTFIRE:
{
	CAI_BaseNPC *npc = pOperator->MyNPCPointer();

	Vector vecShootOrigin, vecShootDir;
	vecShootOrigin = pOperator->Weapon_ShootPosition();
	//vecShootDir = npc->GetShootEnemyDir( vecShootOrigin );

	//Checks if it can fire the grenade
	WeaponRangeAttack2Condition();

	Vector vecThrow = m_vecTossVelocity;

	//If on the rare case the vector is 0 0 0, cancel for avoid launching the grenade without speed
	//This should be on WeaponRangeAttack2Condition(), but for some unknown reason return CASE_NONE
	//doesn't stop the launch
	if (vecThrow == Vector(0, 0, 0)){
		break;
	}

	CGrenadeAR2 *pGrenade = (CGrenadeAR2*)Create("grenade_ar2", vecShootOrigin, vec3_angle, npc);
	pGrenade->SetAbsVelocity( vecThrow );
	pGrenade->SetLocalAngularVelocity(RandomAngle(-400, 400)); //tumble in air
	pGrenade->SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE);

	pGrenade->SetThrower(GetOwner());

	pGrenade->SetGravity(0.5); // lower gravity since grenade is aerodynamic and engine doesn't know it.
		
	pGrenade->SetDamage(sk_plr_dmg_smg1_grenade.GetFloat());

	if (g_pGameRules->IsSkillLevel(SKILL_HARD))
	{
		m_flNextGrenadeCheck = gpGlobals->curtime + RandomFloat(2, 3);
	}
	else{
		m_flNextGrenadeCheck = gpGlobals->curtime + 6;// wait six seconds before even looking again to see if a grenade can be thrown.
	}

	m_iClip2--;
}
break;

Now go to the int CWeaponSMG1::WeaponRangeAttack2Condition( float flDot, float flDist ) function and replace it with this:

int CWeaponSMG1::WeaponRangeAttack2Condition()

And near the top of the function, comment out return COND_NONE; like so:

//return COND_NONE;

For the last step, since this is only cosmetic, go to 🖿src/game/server/hl2/npc_combine.cpp.

On line 381, disable the DevWarning (only in case you don't want to see it neither on DEV mode):

//DevWarning("**Combine Elite Soldier MUST be equipped with AR2\n");

Between lines 2321 and 2325, you can replace that part of the code with the following, so you no longer hear the AR2 effect when using the SMG1:

if ( pEvent->event == COMBINE_AE_BEGIN_ALTFIRE )
{
	//We want it to use different sounds depending on the weapon
	if ( FClassnameIs(GetActiveWeapon(), "weapon_ar2") )
	{
		EmitSound( "Weapon_CombineGuard.Special1" );
	}
	else if ( FClassnameIs(GetActiveWeapon(), "weapon_smg1") )
	{
		EmitSound( "Weapon_SMG1.Double" ); 
	}
	else
	{
		EmitSound( "Weapon_CombineGuard.Special1" ); // We let this play by default
	}
	handledEvent = true;
}

At around line 279, don't forget to precache the SMG1 alt-fire sound effect in CNPC_Combine::Precache

void CNPC_Combine::Precache()
{
	PrecacheModel("models/Weapons/w_grenade.mdl");
	UTIL_PrecacheOther( "npc_handgrenade" );

	PrecacheScriptSound( "NPC_Combine.GrenadeLaunch" );
	PrecacheScriptSound( "NPC_Combine.WeaponBash" );
	PrecacheScriptSound( "Weapon_CombineGuard.Special1" );
	PrecacheScriptSound( "Weapon_SMG1.Double" ); // SMG1 Alt-Fire sound

	BaseClass::Precache();
}

Restoring Dropship container gun rotation functionality

This bug has been fixed in the 2022 Steam Deck update for Half-Life 2 Half-Life 2 (and it's episodes), but the SDK 2007 and SDK 2013 code (including The Orange Box on console) still remains unfixed.

To fix the Dropship gun rotation, follow the instructions:

Go to line 898 in 🖿src/game/server/hl2/npc_combinedropship.cpp and in the Spawn( void ) function insert the following lines

// Store spawned container weapon pitch and yaw pose parameters to allow weapon point to the player
m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );

so the Spawn( void ) function code fragment will look like this

m_iMachineGunBaseAttachment = m_hContainer->LookupAttachment( "gun_base" );
// NOTE: gun_ref must have the same position as gun_base, but rotates with the gun
m_iMachineGunRefAttachment = m_hContainer->LookupAttachment( "gun_ref" );
// Store spawned container weapon pitch and yaw pose parameters to allow weapon point to the player
m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );

Go to line 864 in 🖿src/game/server/hl2/npc_combinedropship.cpp and in the Spawn( void ) function insert the following lines

m_poseWeapon_Pitch = -1;
m_poseWeapon_Yaw = -1;

so the Spawn( void ) function code fragment will look like this

m_iAttachmentTroopDeploy = -1;
m_iAttachmentDeployStart = -1;
m_poseWeapon_Pitch = -1;
m_poseWeapon_Yaw = -1;

// create the correct bin for the ship to carry
switch ( m_iCrateType )
{
case CRATE_ROLLER_HOPPER:
	break;

Go to line 397 in 🖿src/game/server/hl2/npc_combinedropship.cpp and in the PopulatePoseParameters( void ) function add the following lines

// Dropship has any kind of container
if ( m_hContainer )
{
	// Restore container weapon pose parameters on load if any found
	m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
	m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );
}

Go to line 392 in 🖿src/game/server/hl2/npc_combinedropship.cpp and in the PopulatePoseParameters( void ) function remove the following lines

m_poseWeapon_Pitch		= LookupPoseParameter( "weapon_pitch" );
m_poseWeapon_Yaw		= LookupPoseParameter( "weapon_yaw" );

so the final PopulatePoseParameters( void ) function will look like this

void	CNPC_CombineDropship::PopulatePoseParameters( void )
{
	if (!m_sbStaticPoseParamsLoaded)
	{
		m_poseBody_Accel		= LookupPoseParameter( "body_accel");
		m_poseBody_Sway			= LookupPoseParameter( "body_sway" );
		m_poseCargo_Body_Accel  = LookupPoseParameter( "cargo_body_accel" );
		m_poseCargo_Body_Sway   = LookupPoseParameter( "cargo_body_sway" );

		m_sbStaticPoseParamsLoaded = true;
	}

	// Dropship has any kind of container
	if ( m_hContainer )
	{
		// Restore container weapon pose parameters on load if any found
		m_poseWeapon_Pitch = m_hContainer->LookupPoseParameter( "weapon_pitch" );
		m_poseWeapon_Yaw = m_hContainer->LookupPoseParameter( "weapon_yaw" );
	}

	BaseClass::PopulatePoseParameters();
}

Go to line 378 in 🖿src/game/server/hl2/npc_combinedropship.cpp and remove the following lines

int CNPC_CombineDropship::m_poseWeapon_Pitch = 0;
int CNPC_CombineDropship::m_poseWeapon_Yaw = 0;

Go to line 366 in 🖿src/game/server/hl2/npc_combinedropship.cpp and remove trailing , and the following lines

m_poseWeapon_Pitch, m_poseWeapon_Yaw

so the code will look like this

static int m_poseBody_Accel, m_poseBody_Sway, m_poseCargo_Body_Accel, m_poseCargo_Body_Sway;
static bool m_sbStaticPoseParamsLoaded;

Go to line 346 in 🖿src/game/server/hl2/npc_combinedropship.cpp and add the following lines after int m_iAttachmentDeployStart;

// Cached container weapon pose parameters
int			m_poseWeapon_Pitch;
int			m_poseWeapon_Yaw;

so the code will look like this

	
int			m_iAttachmentTroopDeploy;
int			m_iAttachmentDeployStart;

// Cached container weapon pose parameters
int			m_poseWeapon_Pitch;
int			m_poseWeapon_Yaw;

Now the Dropship gun should rotate and shoot again!

Fixing the acid damage white flash sticking around bug

This is a very easy fix, I'm surprised no one has patched this.

Go to 🖿src/game/shared/hl2/hl2_gamerules.cpp and at line 209 add DMG_ACID, like so:

return ( ( iDmgType & ( DMG_PARALYZE | DMG_NERVEGAS | DMG_POISON | DMG_RADIATION | DMG_DROWNRECOVER | DMG_ACID | DMG_SLOWBURN ) ) != 0 );

And it's fixed. Someone, please spread this knowledge.

Schrodinger's/Quantum crouch fix

See: https://wiki.sourceruns.org/wiki/Schrodinger's_Crouch


Another easy fix.

Go to 🖿src/game/shared/gamemovement.cpp then head over to void CGameMovement::FinishDuck( void ) (Line 4194)

At the very top, you should see this:

if ( player->GetFlags() & FL_DUCKING )
	return;

Now all you have to do is comment it out, that's it!

Fixing the NPC not blinking bug

NPCs not being able to blink has been a bug for mods ever since the SteamPipe update. It was fixed in an update for Half-Life 2 + its Episodes (Half-Life 2: Episode One/Half-Life 2: Episode Two) on September 26, 2019, but the code was never pushed to the Source 2013 public repo.


Fixing this is as easy as correcting a single line of code.

Go to 🖿src/game/client/c_baseflex.cpp then head over to the void C_BaseFlex::SetupWeights( ... ) function.

Then at line 1152 correct the following line of code from:

m_iBlink = AddGlobalFlexController( "UH" );

to

m_iBlink = AddGlobalFlexController( "blink" );

Congratulations! You have successfully fixed NPC blinking, it was as easy as that.

Fix smooth friction sounds using the incorrect soundhandle

Fixes a tiny inconsistency. The bug causes the incorrect sound params to be used.


Go to 🖿src/game/shared/physics_shared.cpp then head over to void PhysFrictionSound( ... )

Near the bottom of the function, you should see this line of code within an if statement:

soundHandle = &psurf->soundhandles.scrapeRough;

Now all you have to do is change that to this:

soundHandle = &psurf->soundhandles.scrapeSmooth;

Restoring the Combine Soldier's ability to emit pain sounds

Go to src/game/server/hl2/npc_combine.h and find void PainSound( void );

And change it to this:

void PainSound( const CTakeDamageInfo &info );

Now head over to 🖿src/game/server/hl2/npc_combine.cpp and find void CNPC_Combine::PainSound ( void )

And like before, change it to this:

void CNPC_Combine::PainSound( const CTakeDamageInfo &info )

Restoring ability to disallow player holstering weapons in Multiplayer

Everyone knows about this bug, but fix here is very simple, go to src/game/shared/basecombatweapon_shared.h, then remove const at 248 line.

Now it should look like:

virtual bool			CanHolster( void ) { return TRUE; };		// returns true if the weapon can be holstered

That's it, now you can use CanHolster for weapons!

Fix env_sun sprite disappearing in sky when you look at it

Yet another famous glitch, fix for it is very easy, go to 🖿src/game/client/glow_overlay.cpp, find 162 line then replace zFar * 0.999f; with 0.99f;

Now it should look like:

Vector pos = CurrentViewOrigin() + m_vDirection * zFar * 0.99f;

Now env_sun sprite shouldn't disappear when you look at it.

Fix for viewmodel FOV going into negative integers

This glitch is most obvious when using zoom on higher than normal fov's like 120 or 150. To fix; go to 🖿src/game/client/view.cpp and on line 739 change this:

	//Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end
	view.fovViewmodel = g_pClientMode->GetViewModelFOV() - flFOVOffset;

To this:

	//Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end
	view.fovViewmodel = fabs( g_pClientMode->GetViewModelFOV() - MIN( flFOVOffset, g_pClientMode->GetViewModelFOV() ) );

Now viewmodels won't look super wonky when zooming with higher than normal fov's!