Skip to content

Commit 34675a9

Browse files
committed
fix sound scripts pure bypass
1 parent d0b7fc7 commit 34675a9

File tree

9 files changed

+138
-84
lines changed

9 files changed

+138
-84
lines changed

common/netmessages.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,62 @@ bool CLC_FileMD5Check::WriteToBuffer( bf_write &buffer )
462462
return !buffer.IsOverflowed();
463463
}
464464

465+
void CLC_FileCRCCheck::SetPath(const char* path)
466+
{
467+
int iCode = FindCommonPathID(path);
468+
if (iCode == -1)
469+
{
470+
m_iCodePath = -1;
471+
V_strncpy(m_szPathID, path, sizeof(m_szPathID));
472+
}
473+
else
474+
{
475+
m_iCodePath = iCode;
476+
}
477+
}
478+
479+
const char* CLC_FileCRCCheck::GetPath()
480+
{
481+
int iCode = m_iCodePath;
482+
if ((iCode >= 0) && (iCode < ARRAYSIZE(g_MostCommonPathIDs)))
483+
{
484+
return g_MostCommonPathIDs[iCode];
485+
}
486+
487+
Assert(iCode == -1);
488+
return m_szPathID;
489+
}
490+
491+
void CLC_FileCRCCheck::SetFileName(const char* fileName)
492+
{
493+
int iCode = FindCommonPrefix(fileName);
494+
if (iCode == -1)
495+
{
496+
m_iCodeFilename = -1;
497+
V_strncpy(m_szFilename, fileName, sizeof(m_szFilename));
498+
}
499+
else
500+
{
501+
m_iCodeFilename = iCode;
502+
V_strncpy(m_szFilename, &fileName[V_strlen(g_MostCommonPrefixes[iCode]) + 1], sizeof(m_szFilename));
503+
}
504+
}
505+
506+
const char* CLC_FileCRCCheck::GetFileName()
507+
{
508+
// FIXME(mastercoms): unresolved external va symbol
509+
#if 0
510+
int iCode = m_iCodeFilename;
511+
if ((iCode >= 0) && (iCode < ARRAYSIZE(g_MostCommonPrefixes)))
512+
{
513+
return va("%s%c%s", g_MostCommonPrefixes[iCode], CORRECT_PATH_SEPARATOR, m_szFilename);
514+
}
515+
516+
Assert(iCode == -1);
517+
#endif
518+
return m_szFilename;
519+
}
520+
465521
bool CLC_FileMD5Check::ReadFromBuffer( bf_read &buffer )
466522
{
467523
VPROF( "CLC_FileMD5Check::ReadFromBuffer" );

common/netmessages.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ class CLC_FileCRCCheck : public CNetMessage
311311
{
312312
public:
313313
DECLARE_CLC_MESSAGE( FileCRCCheck );
314+
int m_iCodePath;
315+
int m_iCodeFilename;
314316
char m_szPathID[MAX_PATH];
315317
char m_szFilename[MAX_PATH];
316318
MD5Value_t m_MD5;
@@ -320,8 +322,14 @@ class CLC_FileCRCCheck : public CNetMessage
320322
int m_nPackFileNumber;
321323
int m_PackFileID;
322324
int m_nFileFraction;
325+
326+
void SetPath(const char* path);
327+
const char* GetPath();
328+
void SetFileName(const char* fileName);
329+
const char* GetFileName();
323330
};
324331

332+
325333
class CLC_FileMD5Check : public CNetMessage
326334
{
327335
public:

engine/client.cpp

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,65 +1561,54 @@ void CClientState::CheckUpdatingSteamResources()
15611561
}
15621562
}
15631563

1564-
15651564
//-----------------------------------------------------------------------------
15661565
// Purpose: At a certain rate, this function will verify any unverified
15671566
// file CRCs with the server.
15681567
//-----------------------------------------------------------------------------
15691568
void CClientState::CheckFileCRCsWithServer()
15701569
{
1571-
//! !FIXME! Stubbed this. Several reasons:
1572-
//!
1573-
//! 1.) Removed the CRC functionality (because it was broken when we switched to use MD5's for hashes of
1574-
//! loose files, but the server only has CRC's of some files in the VPK headers.). Currently the only
1575-
//! supported pure server mode is "trusted source."
1576-
//! 2.) Sending MD5's of VPK's is a bit too restrictive for most use cases. For example, if a client
1577-
//! has an extra VPK for custom content, the server doesn't know what to do with it. Or if we
1578-
//! release an optional update, the VPK's might legitimately differ.
1579-
//!
1580-
//! Rich has pointed out that we really need pure server client work to be something that the client
1581-
//! cannot easily bypass. Currently that is the case. But I need to ship the SteamPipe conversion now.
1582-
//! We can revisit pure server security after that has shipped.
1583-
//
1584-
// VPROF_( "CheckFileCRCsWithServer", 1, VPROF_BUDGETGROUP_OTHER_NETWORKING, false, BUDGETFLAG_CLIENT );
1585-
// const float flBatchInterval = 1.0f / 5.0f;
1586-
// const int nBatchSize = 5;
1587-
//
1588-
// // Don't do this yet..
1589-
// if ( !m_bCheckCRCsWithServer )
1590-
// return;
1591-
//
1592-
// if ( m_nSignonState != SIGNONSTATE_FULL )
1593-
// return;
1594-
//
1595-
// // Only send a batch every so often.
1596-
// float flCurTime = Plat_FloatTime();
1597-
// if ( (flCurTime - m_flLastCRCBatchTime) < flBatchInterval )
1598-
// return;
1599-
//
1600-
// m_flLastCRCBatchTime = flCurTime;
1601-
//
1602-
// CUnverifiedFileHash rgUnverifiedFiles[nBatchSize];
1603-
// int count = g_pFileSystem->GetUnverifiedFileHashes( rgUnverifiedFiles, ARRAYSIZE( rgUnverifiedFiles ) );
1604-
// if ( count == 0 )
1605-
// return;
1606-
//
1607-
// // Send the messages to the server.
1608-
// for ( int i=0; i < count; i++ )
1609-
// {
1610-
// CLC_FileCRCCheck crcCheck;
1611-
// V_strncpy( crcCheck.m_szPathID, rgUnverifiedFiles[i].m_PathID, sizeof( crcCheck.m_szPathID ) );
1612-
// V_strncpy( crcCheck.m_szFilename, rgUnverifiedFiles[i].m_Filename, sizeof( crcCheck.m_szFilename ) );
1613-
// crcCheck.m_nFileFraction = rgUnverifiedFiles[i].m_nFileFraction;
1614-
// crcCheck.m_MD5 = rgUnverifiedFiles[i].m_FileHash.m_md5contents;
1615-
// crcCheck.m_CRCIOs = rgUnverifiedFiles[i].m_FileHash.m_crcIOSequence;
1616-
// crcCheck.m_eFileHashType = rgUnverifiedFiles[i].m_FileHash.m_eFileHashType;
1617-
// crcCheck.m_cbFileLen = rgUnverifiedFiles[i].m_FileHash.m_cbFileLen;
1618-
// crcCheck.m_nPackFileNumber = rgUnverifiedFiles[i].m_FileHash.m_nPackFileNumber;
1619-
// crcCheck.m_PackFileID = rgUnverifiedFiles[i].m_FileHash.m_PackFileID;
1620-
//
1621-
// m_NetChannel->SendNetMsg( crcCheck );
1622-
// }
1570+
// See comment in filetracker.cpp to see why we can't send hashes for TF.
1571+
#if 0
1572+
VPROF_("CheckFileCRCsWithServer", 1, VPROF_BUDGETGROUP_OTHER_NETWORKING, false, BUDGETFLAG_CLIENT);
1573+
const float flBatchInterval = 1.0f / 5.0f;
1574+
const int nBatchSize = 5;
1575+
1576+
// Don't do this yet..
1577+
if (!m_bCheckCRCsWithServer)
1578+
return;
1579+
1580+
if (m_nSignonState != SIGNONSTATE_FULL)
1581+
return;
1582+
1583+
// Only send a batch every so often.
1584+
float flCurTime = Plat_FloatTime();
1585+
if ((flCurTime - m_flLastCRCBatchTime) < flBatchInterval)
1586+
return;
1587+
1588+
m_flLastCRCBatchTime = flCurTime;
1589+
1590+
CUnverifiedFileHash rgUnverifiedFiles[nBatchSize];
1591+
int count = g_pFileSystem->GetUnverifiedFileHashes(rgUnverifiedFiles, ARRAYSIZE(rgUnverifiedFiles));
1592+
if (count == 0)
1593+
return;
1594+
1595+
// Send the messages to the server.
1596+
for (int i = 0; i < count; i++)
1597+
{
1598+
CLC_FileCRCCheck crcCheck;
1599+
V_strncpy( crcCheck.m_szPathID, rgUnverifiedFiles[i].m_PathID, sizeof( crcCheck.m_szPathID ) );
1600+
V_strncpy( crcCheck.m_szFilename, rgUnverifiedFiles[i].m_Filename, sizeof( crcCheck.m_szFilename ) );
1601+
crcCheck.m_nFileFraction = rgUnverifiedFiles[i].m_nFileFraction;
1602+
crcCheck.m_MD5 = rgUnverifiedFiles[i].m_FileHash.m_md5contents;
1603+
crcCheck.m_CRCIOs = rgUnverifiedFiles[i].m_FileHash.m_crcIOSequence;
1604+
crcCheck.m_eFileHashType = rgUnverifiedFiles[i].m_FileHash.m_eFileHashType;
1605+
crcCheck.m_cbFileLen = rgUnverifiedFiles[i].m_FileHash.m_cbFileLen;
1606+
crcCheck.m_nPackFileNumber = rgUnverifiedFiles[i].m_FileHash.m_nPackFileNumber;
1607+
crcCheck.m_PackFileID = rgUnverifiedFiles[i].m_FileHash.m_PackFileID;
1608+
1609+
m_NetChannel->SendNetMsg(crcCheck);
1610+
}
1611+
#endif
16231612
}
16241613

16251614

engine/common.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,17 @@ varargs versions of all text functions.
372372
*/
373373
char *va( const char *format, ... )
374374
{
375-
char* outbuf = tmpstr512();
376-
va_list argptr;
377-
va_start (argptr, format);
378-
Q_vsnprintf( outbuf, 512, format, argptr );
379-
va_end (argptr);
380-
return outbuf;
375+
va_list argptr;
376+
static char string[8][512];
377+
static int curstring = 0;
378+
379+
curstring = (curstring + 1) % 8;
380+
381+
va_start(argptr, format);
382+
Q_vsnprintf(string[curstring], sizeof(string[curstring]), format, argptr);
383+
va_end(argptr);
384+
385+
return string[curstring];
381386
}
382387

383388
/*
@@ -390,9 +395,14 @@ bufffer.
390395
*/
391396
const char *vstr(Vector& v)
392397
{
393-
char* outbuf = tmpstr512();
394-
Q_snprintf(outbuf, 512, "%.2f %.2f %.2f", v[0], v[1], v[2]);
395-
return outbuf;
398+
static int idx = 0;
399+
static char string[16][1024];
400+
401+
idx++;
402+
idx &= 15;
403+
404+
Q_snprintf(string[idx], sizeof(string[idx]), "%.2f %.2f %.2f", v[0], v[1], v[2]);
405+
return string[idx];
396406
}
397407

398408
char com_basedir[MAX_OSPATH];

engine/net_ws.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void NET_CloseSocket( int hSocket, int sock = -1)
468468
}
469469
}
470470

471-
bool NET_SetBufferSize(unsigned int nBufferSize, int newsocket, bool bReceive, bool bUDP)
471+
bool NET_SetBufferSize(int nBufferSize, int newsocket, bool bReceive, bool bUDP)
472472
{
473473
int optval = bReceive ? SO_RCVBUF : SO_SNDBUF;
474474
int opt = 0;

engine/sv_client.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ bool CGameClient::ProcessFileCRCCheck( CLC_FileCRCCheck *msg )
261261

262262
char warningStr[1024] = {0};
263263

264-
// The client may send us files we don't care about, so filter them here
265-
// if ( !sv.GetPureServerWhitelist()->GetForceMatchList()->IsFileInList( msg->m_szFilename ) )
266-
// return true;
267-
268264
// first check against all the other files users have sent
269265
FileHash_t filehash;
270266
filehash.m_md5contents = msg->m_MD5;
@@ -274,8 +270,8 @@ bool CGameClient::ProcessFileCRCCheck( CLC_FileCRCCheck *msg )
274270
filehash.m_nPackFileNumber = msg->m_nPackFileNumber;
275271
filehash.m_PackFileID = msg->m_PackFileID;
276272

277-
const char *path = msg->m_szPathID;
278-
const char *fileName = msg->m_szFilename;
273+
const char *path = msg->GetPath();
274+
const char *fileName = msg->GetFileName();
279275
if ( g_PureFileTracker.DoesFileMatch( path, fileName, msg->m_nFileFraction, &filehash, GetNetworkID() ) )
280276
{
281277
// track successful file

filesystem/basefilesystem.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,15 +2941,14 @@ bool CBaseFileSystem::LoadKeyValues( KeyValues& head, KeyValuesPreloadType_t typ
29412941
ParsePathID( filename, pPathID, tempPathID );
29422942

29432943
// FIXME: THIS STUFF DOESN'T TRACK pPathID AT ALL RIGHT NOW!!!!!
2944-
if ( !m_PreloadData[ type ].m_pReader || !m_PreloadData[ type ].m_pReader->InstanceInPlace( head, filename ) )
2944+
if (!m_PreloadData[type].m_pReader || !m_PreloadData[type].m_pReader->InstanceInPlace(head, filename))
29452945
{
2946-
bret = head.LoadFromFile( this, filename, pPathID );
2946+
bret = head.LoadFromFile(this, filename, pPathID);
29472947
}
2948-
return bret;
29492948
#else
29502949
bret = head.LoadFromFile( this, filename, pPathID );
2951-
return bret;
29522950
#endif
2951+
return bret;
29532952
}
29542953

29552954

game_clean/start_server.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@echo off
2-
srcds.bat +sv_pure 0 +maxplayers 32 +sv_lan 1 %* < nul
2+
srcds.bat +sv_pure 1 +maxplayers 32 +sv_lan 1 %* < nul

soundemittersystem/soundemittersystembase.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ soundlevel_t CSoundEmitterSystemBase::LookupSoundLevel( const char *soundname )
862862
void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPreload, bool bIsOverride /*=false*/, bool bRefresh /*=false*/ )
863863
{
864864
CSoundScriptFile sf;
865-
sf.hFilename = filesystem->FindOrAddFileName( filename );
865+
sf.hFilename = filesystem->FindOrAddFileName(filename);
866866
sf.dirty = false;
867867

868868
int scriptindex = m_SoundKeyValues.AddToTail( sf );
@@ -873,7 +873,7 @@ void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPre
873873

874874
// Open the soundscape data file, and abort if we can't
875875
KeyValues *kv = new KeyValues( "" );
876-
if ( filesystem->LoadKeyValues( *kv, IFileSystem::TYPE_SOUNDEMITTER, filename, "GAME" ) )
876+
if (filesystem->LoadKeyValues( *kv, IFileSystem::TYPE_SOUNDEMITTER, filename, "GAME" ) )
877877
{
878878
// parse out all of the top level sections and save their names
879879
KeyValues *pKeys = kv;
@@ -907,7 +907,7 @@ void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPre
907907
UtlHashHandle_t lookup = m_Sounds.Insert( pEntry ); // insert returns existing item if found
908908
if ( m_Sounds[ lookup ] != pEntry )
909909
{
910-
if ( bIsOverride )
910+
if ( bIsOverride || bRefresh )
911911
{
912912
MEM_ALLOC_CREDIT();
913913

@@ -929,10 +929,6 @@ void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPre
929929

930930
++replaceCount;
931931
}
932-
else if ( bRefresh )
933-
{
934-
InitSoundInternalParameters( pKeys->GetName(), pKeys, m_Sounds[ lookup ]->m_SoundParams );
935-
}
936932
#if 0
937933
else
938934
{
@@ -1054,7 +1050,7 @@ int CSoundEmitterSystemBase::CheckForMissingWavFiles( bool verbose )
10541050
if ( name[0] == CHAR_SENTENCE )
10551051
continue;
10561052
Q_snprintf( testfile, sizeof( testfile ), "sound/%s", PSkipSoundChars( name ) );
1057-
if ( filesystem->FileExists( testfile ) )
1053+
if (filesystem->FileExists( testfile ) )
10581054
continue;
10591055

10601056
internal->SetHadMissingWaveFiles( true );
@@ -1146,7 +1142,7 @@ const char *CSoundEmitterSystemBase::GetSourceFileForSound( int index ) const
11461142
return "";
11471143
}
11481144
static char fn[ 512 ];
1149-
if ( filesystem->String( m_SoundKeyValues[ scriptindex ].hFilename, fn, sizeof( fn ) ))
1145+
if (filesystem->String( m_SoundKeyValues[ scriptindex ].hFilename, fn, sizeof( fn ) ))
11501146
{
11511147
return fn;
11521148
}
@@ -1293,7 +1289,7 @@ const char *CSoundEmitterSystemBase::GetSoundScriptName( int index ) const
12931289
return NULL;
12941290

12951291
static char fn[ 512 ];
1296-
if ( filesystem->String( m_SoundKeyValues[ index ].hFilename, fn, sizeof( fn ) ) )
1292+
if (filesystem->String( m_SoundKeyValues[ index ].hFilename, fn, sizeof( fn ) ) )
12971293
{
12981294
return fn;
12991295
}

0 commit comments

Comments
 (0)