Source 2007 Template Fixes

From Valve Developer Community
Jump to: navigation, search
Русский

This is a collection of fixes that only effect the Source 2007 Template.

Missing prediction table entry on the client-side player

A prediction table in game/client/sdk/c_sdk_player.cpp is missing an entry for shared player data, causing some values such as the amount of stamina to appear jittery.

--- game\client\sdk\c_sdk_player.cpp	2010-03-28 17:00:41.000000000 -0600
+++ game\client\sdk\c_sdk_player.cpp	2011-07-14 19:06:20.000000000 -0600
@@ -149,12 +149,13 @@
 #if defined( SDK_USE_SPRINTING )
 	DEFINE_PRED_FIELD( m_bIsSprinting, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
 #endif
 END_PREDICTION_DATA()
 
 BEGIN_PREDICTION_DATA( C_SDKPlayer )
+	DEFINE_PRED_TYPEDESCRIPTION( m_Shared, CSDKPlayerShared ),
 	DEFINE_PRED_FIELD( m_flCycle, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ),
 	DEFINE_PRED_FIELD( m_iShotsFired, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),   
 END_PREDICTION_DATA()
 
 LINK_ENTITY_TO_CLASS( player, C_SDKPlayer );

SDK sprinting

With the previous prediction patch, we need to apply the sprint penalty in prediction. The initial SetMaxSpeed is also called with the wrong value.

--- game\shared\sdk\sdk_player_shared.cpp	2010-03-28 17:00:44.000000000 -0600
+++ game\shared\sdk\sdk_player_shared.cpp	2011-07-14 18:52:55.000000000 -0600
@@ -213,13 +213,13 @@
 }
 
 bool CSDKPlayer::IsSprinting( void )
 {
 	float flVelSqr = GetAbsVelocity().LengthSqr();
 
-	return m_Shared.m_bIsSprinting && ( flVelSqr > 0.5f );
+	return m_Shared.IsSprinting() && ( flVelSqr > 0.5f );
 }
 #endif // SDK_USE_SPRINTING
 
 bool CSDKPlayer::CanAttack( void )
 {
 #if defined ( SDK_USE_SPRINTING )
@@ -424,24 +424,20 @@
 
 #endif
 
 #if defined ( SDK_USE_SPRINTING )
 void CSDKPlayerShared::SetSprinting( bool bSprinting )
 {
-	if ( bSprinting && !m_bIsSprinting )
+	if ( bSprinting && !IsSprinting())
 	{
 		StartSprinting();
 
-		// only one penalty per key press
-		if ( m_bGaveSprintPenalty == false )
-		{
-			m_flStamina -= INITIAL_SPRINT_STAMINA_PENALTY;
-			m_bGaveSprintPenalty = true;
-		}
+		// always apply this penalty as we're predicting m_bSprinting
+		m_flStamina -= INITIAL_SPRINT_STAMINA_PENALTY;
 	}
-	else if ( !bSprinting && m_bIsSprinting )
+	else if ( !bSprinting && IsSprinting() )
 	{
 		StopSprinting();
 	}
 }
 
 // this is reset when we let go of the sprint key
@@ -568,13 +564,13 @@
 {
 #if !defined ( SDK_USE_PLAYERCLASSES )
 	m_Shared.m_flRunSpeed = SDK_DEFAULT_PLAYER_RUNSPEED;
 	m_Shared.m_flSprintSpeed = SDK_DEFAULT_PLAYER_SPRINTSPEED;
 	m_Shared.m_flProneSpeed = SDK_DEFAULT_PLAYER_PRONESPEED;
 	// Set the absolute max to sprint speed
-	SetMaxSpeed( m_Shared.m_flSprintSpeed ); 
+	SetMaxSpeed( m_Shared.m_flRunSpeed ); 
 	return;
 #endif
 #if defined ( SDK_USE_PLAYERCLASSES )
 		int playerclass = m_Shared.PlayerClass();
 
 		//Tony; error checkings.

Game freezing on exit instead of closing

Note: do not work with episodic source code. ( read the discussion page for my report) Fuzz 05:40, 20 November 2012 (PST)

There's a problem in the Source 2007 (and maybe later versions, I'm not sure) which makes the game unable to be closed by normal means, the only way being finalizing the process in the Task Manager. Luckily for us, there is a simple fix for this.

1. Open the src/game/server/gameinterface.cpp

2. Search for CServerGameDLL::DLLShutdown

3. At the end of this function, add these lines above the DisconnectTier3Libraries() function call:

+	SteamClient()->ReleaseUser( GetHSteamPipe(), GetHSteamUser() );
+	SteamClient()->BReleaseSteamPipe( GetHSteamPipe() );

	DisconnectTier3Libraries();
	DisconnectTier2Libraries();
	ConVar_Unregister();
	DisconnectTier1Libraries();

Fix for CSDKPlayer::OnTakeDamage()

A fix for logic error that prevents you from taking fall-damage, etc from the world when not using teams.

--- game\server\sdk\sdk_player.cpp	2012-09-22 23:20:43.000000000 +0900
+++ game\server\sdk\sdk_player.cpp	2012-09-22 23:22:00.000000000 +0900
@@ -574,19 +574,21 @@
 		return 0;
 
 	float flArmorBonus = 0.5f;
 	float flArmorRatio = 0.5f;
 	float flDamage = info.GetDamage();
 
+	//Tony; re-work this so if you're not dealing with teams at all, you can still be hurt by the world.
+	//and that it always runs through here if friendly fire is off.
 	bool bCheckFriendlyFire = false;
 	bool bFriendlyFire = friendlyfire.GetBool();
 	//Tony; only check teams in teamplay
-	if ( gpGlobals->teamplay )
+	if ( gpGlobals->teamplay && bFriendlyFire )
 		bCheckFriendlyFire = true;
 
-	if ( bFriendlyFire || ( bCheckFriendlyFire && pInflictor->GetTeamNumber() != GetTeamNumber() ) || pInflictor == this ||	info.GetAttacker() == this )
+	if ( !bCheckFriendlyFire || ( bCheckFriendlyFire && pInflictor->GetTeamNumber() != GetTeamNumber() ) || pInflictor == this || info.GetAttacker() == this )
 	{
 		if ( bFriendlyFire && (info.GetDamageType() & DMG_BLAST) == 0 )
 		{
 			if ( pInflictor->GetTeamNumber() == GetTeamNumber() && bCheckFriendlyFire)
 			{
 				flDamage *= 0.35; // bullets hurt teammates less