Posted: . At: 10:33 AM. This was 4 years ago. Post ID: 14257
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.



Sponsored



Team Fortress 2 and Counterstrike source code leaked on the Internet.


The source code for Counterstrike GO and Team Fortress 2 has been leaked on the Internet, there is a torrent of various utilities and the complete source code in C++. I wonder what the lawyers for these companies will think of this debacle. Who leaked the source code in the first place? Apparently, some Remote Code Execution vulnerabilities were found in the Team Fortress 2 code and this is being addressed right now. This might be a good thing. Leaking the code allows peer review and this is a good way to find bugs and exploits that can be fixed. This does mean that exploits for the game can be found now, but also, the exploits can be fixed, as knowing how to exploit them also means that they can be patched. This is either good or bad, I wonder if anyone will compile this and use it for a project. Would Chinese developers compile it and make a game with it? They do not care about western lawsuits. There are also binaries in the archive, this is to do with the SDK. As well as screenshots in the Source Safe archive. This is pretty comprehensive. Something to take our minds off Coronavirus anyway.

Something to do with Steamworks.
Something to do with Steamworks.

Not to forget the release of Anime War episode 13. But I digress. This is a fascinating look into how games are coded, this enables us to see how a AAA game looks like behind the scenes. A lot of functions that all work together to create a fun PvP title. This surely will breed a new batch of exploits as the source is searched and more insight is gained into how networking and video graphics are created in the game. As well as the rendering of enemies on screen and how they are tracked around the map. This could lead to all new wallhack exploits. But the strength of open-source applications is the fact that peer-reviewed source code allows problems to be seen and fixed, whereas closed source solutions do not allow this at all. And the game can have annoying bugs that you depend upon the developer to fix instead of having the ability to fix it yourself.

Valve Visual Source Safe screenshot.
Valve Visual Source Safe screenshot.

Open source games have the advantage of peer-reviewed code and better support for Linux. Like OpenArena, which is a free game just like Quake 3 Arena. It is bad when a game like Arma 3 gets a release on Windows and Linux, but the Linux version is unmaintained and does not match the Windows version. This is lazy. If it used the Vulkan API, it might be easier to maintain. As well as easier to run. More games should be cross-compatible with Linux and Windows.  This would make Linux gamers happy. Of course, someone should look through this code, but actually using it for anything would result in a lawsuit. Just use it as a reference and do not make it obvious that your new game uses any Valve code. Otherwise, Gaben will sue your ass. Gordon Freeman will have a 😓. Just use it as a reference and learn from it. CSGO source mostly builds fine with VS2019 with a few tweaks (typeinfo.h -> typeinfo, remove operator new, etc), but then fails to link because of some missing lib files. The cryptlib.lib can be copied from the hl2_src folder and seems to link fine, but then it needs libprotobuf.lib, none of the included libprotobufs will build with 2019, maybe if I used an older VS one of them would work, or maybe could get libprotobuf from some other source, I do not know.

I Have not tried anything with hl2_src yet, I’m not really sure how different this is to the old src2007 leak, people say it’s meant to be TF2 2017 code but it looks a lot like the 2007 leak, with the same folders like tf/sixense/portal etcetera, haven’t seen anything that confirms it’s actually new TF2 code. Don’t have the old leak on hand atm to actually compare them though so I don’t really know yet. This must rely on components that are only available in the Valve build environment. So it is not actually complete source code. But it is possible to add the missing components if you know what they are supposed to be doing. A good project for a very keen programmer who knows C++ very well…

This is a sample of the networking code from the half Life 2 source. This is a very interesting piece of source code.

class CNetworkClient : public IConnectionlessPacketHandler, public INetworkMessageHandler, public ILookupChannel
{
public:
	CNetworkClient();
	virtual ~CNetworkClient();
 
	bool	Init( int nListenPort );
	void	Shutdown();
 
	bool	Connect( const char *server, int port );
	void	Disconnect();
 
	// IConnectionlessPacketHandler
	virtual bool ProcessConnectionlessPacket( CNetPacket *packet );	// process a connectionless packet
 
	// INetworkMessageHandler
	virtual void	OnConnectionClosing( INetChannel *channel, char const *reason );
	virtual void	OnConnectionStarted( INetChannel *channel );
 
	virtual void	OnPacketStarted( int inseq, int outseq );
	virtual void	OnPacketFinished();
 
	// ILookupChannel
    virtual INetChannel *FindNetChannel( const netadr_t& from ) ;
 
	INetChannel *GetNetChannel()
	{
		return &m_NetChan;
	}
 
	void ReadPackets();
	void SendUpdate();
 
	CUDPSocket *m_pSocket;
 
	CNetChannel		m_NetChan;
	bool			m_bConnected;
};
 
#endif // CLIENT_H

Half Life 2 is in pure C++. It uses UDP for networking. As shown in this code sample.

bool CUDPSocket::Init( unsigned short nBindToPort )
{
	m_Port = nBindToPort;
	struct sockaddr_in	address;
 
	m_Socket = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP );
	if ( m_Socket == INVALID_SOCKET )
		return false;
 
	address = m_pImpl->m_SocketIP;
	address.sin_family = AF_INET;
	address.sin_port = htons( m_Port );
	address.sin_addr.S_un.S_addr = INADDR_ANY;
 
	if ( SOCKET_ERROR == bind( m_Socket, ( struct sockaddr * )&address, sizeof( address ) ) )
	{
		return false;
	}
 
	// Set to non-blocking i/o
	unsigned long value = 1;
	if ( SOCKET_ERROR == ioctlsocket( m_Socket, FIONBIO, &value ) )
	{
		return false;
	}
 
	return true;
}

CsGo 15 uses the same source code as Half Life 2 to handle cheats. This is interesting.

void ReadCheatCommandsFromFile( char *pchFileName )
{
#if defined( _CERT )
	return;
#endif
	KeyValues *pCheatCodeKeys = new KeyValues( "cheat_codes" );
	if ( pCheatCodeKeys->LoadFromFile( g_pFullFileSystem, pchFileName, NULL ) )
	{
		KeyValues *pKey = NULL;
		for ( pKey = pCheatCodeKeys->GetFirstTrueSubKey(); pKey; pKey = pKey->GetNextTrueSubKey() )
		{
			int iCheat = s_CheatCodeCommands.AddToTail();
			CheatCodeData_t *pNewCheatCode = &(s_CheatCodeCommands[ iCheat ]);
 
			Q_strncpy( pNewCheatCode->szName, pKey->GetName(), CHEAT_NAME_MAX_LEN );	// Get the name
			pNewCheatCode->bDevOnly = ( pKey->GetInt( "dev", 0 ) != 0 );				// Get developer only flag
			pNewCheatCode->iCodeLength = 0;												// Start at zero code elements
			Q_strncpy( pNewCheatCode->szCommand, pKey->GetString( "command", "echo \"Cheat code has no command!\"" ), CHEAT_COMMAND_MAX_LEN );
 
			KeyValues *pSubKey = NULL;
			for ( pSubKey = pKey->GetFirstSubKey(); pSubKey; pSubKey = pSubKey->GetNextKey() )
			{
				const char *pchType = pSubKey->GetName();
				if ( Q_strcmp( pchType, "code" ) == 0 )
				{
					AssertMsg( ( pNewCheatCode->iCodeLength < CHEAT_NAME_MAX_LEN ), "Cheat code elements exceeded max!" );
 
					pNewCheatCode->pButtonCodes[ pNewCheatCode->iCodeLength ] = g_pInputSystem->StringToButtonCode( pSubKey->GetString() );
					++pNewCheatCode->iCodeLength;
				}
			}
 
			if ( pNewCheatCode->iCodeLength < CHEAT_NAME_MAX_LEN )
			{
				// If it's activation is a subsequence of another cheat, the longer cheat can't be activated!
				DevWarning( "Cheat code \"%s\" has less than %i code elements!", pKey->GetName(), CHEAT_NAME_MAX_LEN );
			}
		}
	}
 
	pCheatCodeKeys->deleteThis();
}

Finally, this source code for Counterstrike handles lag compensation for player movement.

bool CBasePlayer::WantsLagCompensationOnEntity( const CBaseEntity *entity, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits ) const
{
	// Team members shouldn't be adjusted unless friendly fire is on.
	if ( !mp_friendlyfire.GetInt() && !mp_teammates_are_enemies.GetBool() && entity->GetTeamNumber() == GetTeamNumber() )
		return false;
 
	// If this entity hasn't been transmitted to us and acked, then don't bother lag compensating it.
	if ( pEntityTransmitBits && !pEntityTransmitBits->Get( entity->entindex() ) )
		return false;
 
	const Vector &vMyOrigin = GetAbsOrigin();
	const Vector &vHisOrigin = entity->GetAbsOrigin();
 
	// get max distance player could have moved within max lag compensation time, 
	// multiply by 1.5 to to avoid "dead zones"  (sqrt(2) would be the exact value)
	float entityMaxSpeed = ToBasePlayer(entity) ? ToBasePlayer(entity)->MaxSpeed() : 300.0f;
	float maxDistance = 1.5 * entityMaxSpeed * sv_maxunlag.GetFloat();
 
	// If the player is within this distance, lag compensate them in case they're running past us.
	if ( vHisOrigin.DistTo( vMyOrigin ) < maxDistance )
		return true;
 
	// If their origin is not within a 45 degree cone in front of us, no need to lag compensate.
	Vector vForward;
	AngleVectors( pCmd->viewangles, &vForward );
 
	Vector vDiff = vHisOrigin - vMyOrigin;
	VectorNormalize( vDiff );
 
	float flCosAngle = 0.707107f;	// 45 degree angle
	if ( vForward.Dot( vDiff ) < flCosAngle )
		return false;
 
	return true;
}

This source code might be very useful to you, see what you can do with it. There are torrents out there that can give you this archive, but I am not going to link to it as that might not be a good idea.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.