bool BasicGameStatsRecord_t::ParseFromBuffer( CUtlBuffer &buf, int iBufferStatsVersion )
{
	bool bret = true;
	m_nCount = buf.GetInt();

	if ( m_nCount > 100000 || m_nCount < 0 )
	{
		bret = false;
	}

	m_nSeconds = buf.GetInt();
	// Note, don't put the buf.GetInt() in the macro since it'll get evaluated twice!!!
	m_nSeconds = MAX( m_nSeconds, 0 );

	m_nCommentary = buf.GetInt();
	if ( m_nCommentary < 0 || m_nCommentary > 100000 )
	{
		bret = false;
	}

	m_nHDR = buf.GetInt();
	if ( m_nHDR < 0 || m_nHDR > 100000 )
	{
		bret = false;
	}

	m_nCaptions = buf.GetInt();
	if ( m_nCaptions < 0 || m_nCaptions > 100000 )
	{
		bret = false;
	}

	for ( int i = 0; i < 3; ++i )
	{
		m_nSkill[ i ] = buf.GetInt();
		if ( m_nSkill[ i ] < 0 || m_nSkill[ i ]  > 100000 )
		{
			bret = false;
		}
	}

	if ( iBufferStatsVersion > GAMESTATS_FILE_VERSION_OLD )
	{
		m_bSteam = buf.GetChar() ? true : false;
	}
	if ( iBufferStatsVersion > GAMESTATS_FILE_VERSION_OLD2 )
	{
		m_bCyberCafe = buf.GetChar() ? true : false;
	}
	if ( iBufferStatsVersion > GAMESTATS_FILE_VERSION_OLD5 )
	{
		m_nDeaths = buf.GetInt();
	}

	return bret;
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : buf - 
//-----------------------------------------------------------------------------
void CSentence::CacheRestoreFromBuffer( CUtlBuffer& buf )
{
	Assert( !buf.IsText() );

	Reset();

	m_bIsCached = true;

	int version = buf.GetChar();
	if ( version != CACHED_SENTENCE_VERSION )
	{
		// Uh oh, version changed...
		m_bIsValid = false;
		return;
	}

	unsigned short pcount = (unsigned short)buf.GetShort();
	
	CPhonemeTag pt;
	int i;

	for ( i = 0; i < pcount; ++i )
	{
		unsigned short code = buf.GetShort();
		float st = buf.GetFloat();
		float et = buf.GetFloat();

		pt.SetPhonemeCode( code );
		pt.SetStartTime( st );
		pt.SetEndTime( et );

		AddRuntimePhoneme( &pt );
	}

	// Now read emphasis samples
	int c = buf.GetShort();

	for ( i = 0; i < c; i++ )
	{
		CEmphasisSample sample;
		sample.SetSelected( false );

		sample.time = buf.GetFloat();
		sample.value = (float)buf.GetShort() / 32767.0f;

		m_EmphasisSamples.AddToTail( sample );
	}

	// And voice duck
	SetVoiceDuck( buf.GetChar() == 0 ? false : true );
	m_bIsValid = true;
}
Esempio n. 3
0
static int CountBinaryBytes( CUtlBuffer &buf, int *pEndGet )
{
	// This counts the number of bytes in the uuencoded text
	int nStartGet = buf.TellGet();
	buf.EatWhiteSpace();
	*pEndGet = buf.TellGet();
	int nByteCount = 0;
	while ( buf.IsValid() )
	{
		char c1 = buf.GetChar();
		char c2 = buf.GetChar();

		bool bIsNum1 = ( c1 >= '0' ) && ( c1 <= '9' );
		bool bIsNum2 = ( c2 >= '0' ) && ( c2 <= '9' );

		bool bIsAlpha1 = (( c1 >= 'A' ) && ( c1 <= 'F' )) || (( c1 >= 'a' ) && ( c1 <= 'f' ));
		bool bIsAlpha2 = (( c2 >= 'A' ) && ( c2 <= 'F' )) || (( c2 >= 'a' ) && ( c2 <= 'f' ));

		if ( !(bIsNum1 || bIsAlpha1) || !(bIsNum2 || bIsAlpha2) )
			break;

		buf.EatWhiteSpace();
		*pEndGet = buf.TellGet();
		++nByteCount;
	}
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, nStartGet );
	return nByteCount;
}
bool CNetworkStringTable::ReadStringTable( CUtlBuffer& buf )
{
	DeleteAllStrings();

	int numstrings = buf.GetInt();
	for ( int i = 0 ; i < numstrings; i++ )
	{
		char stringname[4096];
		
		buf.GetString( stringname, sizeof( stringname ) );

		if ( buf.GetChar() == 1 )
		{
			int userDataSize = (int)buf.GetShort();
			Assert( userDataSize > 0 );
			byte *data = new byte[ userDataSize + 4 ];
			Assert( data );

			buf.Get( data, userDataSize );

			AddString( true, stringname, userDataSize, data );

			delete[] data;
			
		}
		else
		{
			AddString( true, stringname );
		}
	}

	return true;
}
Esempio n. 5
0
bool CChoreoActor::RestoreFromBuffer( CUtlBuffer& buf, CChoreoScene *pScene )
{
	char sz[ 256 ];
	buf.GetString( sz, sizeof( sz ) );

	SetName( sz );

	int i;
	int c = buf.GetShort();
	for ( i = 0; i < c; i++ )
	{
		CChoreoChannel *channel = pScene->AllocChannel();
		Assert( channel );
		if ( channel->RestoreFromBuffer( buf, pScene, this ) )
		{
			AddChannel( channel );
			channel->SetActor( this );
			continue;
		}

		return false;
	}

	SetActive( buf.GetChar() == 1 ? true : false );

	return true;
}
bool BasicGameStats_t::ParseFromBuffer( CUtlBuffer& buf, int iBufferStatsVersion )
{
	bool bret = true;

	m_nSecondsToCompleteGame = buf.GetInt();
	if ( m_nSecondsToCompleteGame < 0 || m_nSecondsToCompleteGame > 10000000 )
	{
		bret = false;
	}

	m_Summary.ParseFromBuffer( buf, iBufferStatsVersion );
	int c = buf.GetInt();
	if ( c > 1024 || c < 0 )
	{
		bret = false;
	}

	for ( int i = 0; i < c; ++i )
	{
		char mapname[ 256 ];
		buf.GetString( mapname, sizeof( mapname ) );

		BasicGameStatsRecord_t *rec = FindOrAddRecordForMap( mapname );
		bool valid= rec->ParseFromBuffer( buf, iBufferStatsVersion );
		if ( !valid )
		{
			bret = false;
		}
	}

	if ( iBufferStatsVersion >= GAMESTATS_FILE_VERSION_OLD2 )
	{
		m_nHL2ChaptureUnlocked = (int)buf.GetChar();	
		m_bSteam = buf.GetChar() ? true : false;
	}
	if ( iBufferStatsVersion > GAMESTATS_FILE_VERSION_OLD2 )
	{
		m_bCyberCafe = buf.GetChar() ? true : false;
	}
	if ( iBufferStatsVersion > GAMESTATS_FILE_VERSION_OLD3 )
	{
		m_nDXLevel = (int)buf.GetShort();
	}
	return bret;
}
Esempio n. 7
0
//-----------------------------------------------------------------------------
// Parses a token from the excel .csv file
//-----------------------------------------------------------------------------
CSFMGenApp::TokenRetVal_t CSFMGenApp::ParseToken( CUtlBuffer &buf, char *pToken, int nMaxTokenLen )
{
	*pToken = 0;

	if ( !buf.IsValid() )
		return TOKEN_EOF;

	int nLen = 0;
	char c = buf.GetChar();
	bool bIsQuoted = false;
	while ( true )
	{
		if ( c == '"' )
		{
			bIsQuoted = !bIsQuoted;
		}
		else if ( ( c == ',' || c == '\n' ) && !bIsQuoted )
		{
			pToken[nLen] = 0;
			return ( c == '\n' ) ? TOKEN_RETURN : TOKEN_COMMA;
		}

		if ( nLen < nMaxTokenLen - 1 )
		{
			if ( c != '"' )
			{
				pToken[nLen++] = c;
			}
		}
		if ( !buf.IsValid() ) 
		{
			pToken[nLen] = 0;
			return TOKEN_EOF;
		}
		c = buf.GetChar();
	}

	// Should never get here
	return TOKEN_EOF;
}
Esempio n. 8
0
bool Unserialize( CUtlBuffer &buf, bool &dest )
{
	if ( buf.IsText() )
	{
		int nValue = 0;
		int nRetVal = buf.Scanf( "%d", &nValue );
		dest = ( nValue != 0 );
		return (nRetVal == 1) && buf.IsValid();
	}

	dest = ( buf.GetChar( ) != 0 );
	return buf.IsValid();
}
Esempio n. 9
0
//-----------------------------------------------------------------------------
// Deals with compressed channels
//-----------------------------------------------------------------------------
static void PSDReadCompressedChannels( CUtlBuffer &buf, int nChannelsCount, PSDMode_t mode, PSDPalette_t &palette, Bitmap_t &bitmap )
{
	unsigned char *pChannelRow = (unsigned char*)_alloca( bitmap.m_nWidth );
	for ( int i=0; i<nChannelsCount; ++i )
	{
		int nIndex = s_pChannelIndex[mode][i];
		Assert( nIndex != -1 );

		unsigned char *pDest = bitmap.m_pBits;
		for( int j=0; j < bitmap.m_nHeight; ++j )
		{
			unsigned char *pSrc = pChannelRow;
			unsigned int nPixelsRemaining = bitmap.m_nWidth;
			while ( nPixelsRemaining > 0 )
			{
				int nCount = buf.GetChar();
				if ( nCount >= 0 )
				{
					// If nCount is between 0 + 7F, it means copy the next nCount+1 bytes directly
					++nCount;
					Assert( (unsigned int)nCount <= nPixelsRemaining );
					buf.Get( pSrc, nCount );
				}
				else
				{
					// If nCount is between 80 and FF, it means replicate the next byte -Count+1 times
					nCount = -nCount + 1;
					Assert( (unsigned int)nCount <= nPixelsRemaining );
					unsigned char nPattern = buf.GetUnsignedChar();
					memset( pSrc, nPattern, nCount );
				}
				pSrc += nCount;
				nPixelsRemaining -= nCount;
			}
			Assert( nPixelsRemaining == 0 );

			// Collate the channels together
			for ( int k = 0; k < bitmap.m_nWidth; ++k, pDest += 4 )
			{
				pDest[nIndex] = pChannelRow[k];
			}
		}
	}

	PSDConvertToRGBA8888( nChannelsCount, mode, palette, bitmap );
}
Esempio n. 10
0
bool Unserialize( CUtlBuffer &buf, CUtlBinaryBlock &dest )
{
	if ( !buf.IsText() )
	{
		int nLen = buf.GetInt( );
		dest.SetLength( nLen );
		if ( dest.Length() != 0 )
		{
			buf.Get( dest.Get(), dest.Length() );
		}

		if ( nLen != dest.Length() )
		{
			buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nLen - dest.Length() );
			return false;
		}

		return buf.IsValid();
	}

	int nEndGet;
	int nByteCount = CountBinaryBytes( buf, &nEndGet );
	if ( nByteCount < 0 )
		return false;

	buf.EatWhiteSpace();
	int nDest = 0;
	dest.SetLength( nByteCount );
	while( buf.TellGet() < nEndGet )
	{
		char c1 = buf.GetChar();
		char c2 = buf.GetChar();

		unsigned char b1 = HexCharToInt( c1 );
		unsigned char b2 = HexCharToInt( c2 );
		if ( b1 == 0xFF || b2 == 0xFF )
			return false;

		dest[ nDest++ ] = b2 | ( b1 << 4 );
		buf.EatWhiteSpace();
	}

	return true;
}
Esempio n. 11
0
bool CChoreoChannel::RestoreFromBuffer( CUtlBuffer& buf, CChoreoScene *pScene, CChoreoActor *pActor, IChoreoStringPool *pStringPool )
{
	char sz[ 256 ];
	pStringPool->GetString( buf.GetShort(), sz, sizeof( sz ) );
	SetName( sz );

	int numEvents = (int)buf.GetUnsignedChar();
	for ( int i = 0 ; i < numEvents; ++i )
	{
		CChoreoEvent *e = pScene->AllocEvent();
		if ( e->RestoreFromBuffer( buf, pScene, pStringPool ) )
		{
			AddEvent( e );
			e->SetChannel( this );
			e->SetActor( pActor );
			continue;
		}
		return false;
	}

	SetActive( buf.GetChar() == 1 ? true : false );

	return true;
}
Esempio n. 12
0
void VMPI_DistributeLightData()
{
	if ( !g_bUseMPI )
		return;

	if ( g_bMPIMaster )
	{
		const char *pVirtualFilename = "--plightdata--";
		
		CUtlBuffer lightFaceData;

		// write out the light data
		lightFaceData.EnsureCapacity( pdlightdata->Count() + (numfaces * (MAXLIGHTMAPS+sizeof(int))) );
		Q_memcpy( lightFaceData.PeekPut(), pdlightdata->Base(), pdlightdata->Count() );
		lightFaceData.SeekPut( CUtlBuffer::SEEK_HEAD, pdlightdata->Count() );

		// write out the relevant face info into the stream
		for ( int i = 0; i < numfaces; i++ )
		{
			for ( int j = 0; j < MAXLIGHTMAPS; j++ )
			{
				lightFaceData.PutChar(g_pFaces[i].styles[j]);
			}
			lightFaceData.PutInt(g_pFaces[i].lightofs);
		}
		VMPI_FileSystem_CreateVirtualFile( pVirtualFilename, lightFaceData.Base(), lightFaceData.TellMaxPut() );

		char cPacketID[2] = { VMPI_VRAD_PACKET_ID, VMPI_SUBPACKETID_PLIGHTDATA_RESULTS };
		VMPI_Send2Chunks( cPacketID, sizeof( cPacketID ), pVirtualFilename, strlen( pVirtualFilename ) + 1, VMPI_PERSISTENT );
	}
	else
	{
		VMPI_SetCurrentStage( "VMPI_DistributeLightData" );

		// Wait until we've received the filename from the master.
		while ( g_LightResultsFilename.Count() == 0 )
		{
			VMPI_DispatchNextMessage();
		}

		// Open 
		FileHandle_t fp = g_pFileSystem->Open( g_LightResultsFilename.Base(), "rb", VMPI_VIRTUAL_FILES_PATH_ID );
		if ( !fp )
			Error( "Can't open '%s' to read lighting info.", g_LightResultsFilename.Base() );

		int size = g_pFileSystem->Size( fp );
		int faceSize = (numfaces*(MAXLIGHTMAPS+sizeof(int)));

		if ( size > faceSize )
		{
			int lightSize = size - faceSize;
			CUtlBuffer faceData;
			pdlightdata->EnsureCount( lightSize );
			faceData.EnsureCapacity( faceSize );

			g_pFileSystem->Read( pdlightdata->Base(), lightSize, fp );
			g_pFileSystem->Read( faceData.Base(), faceSize, fp );
			g_pFileSystem->Close( fp );

			faceData.SeekPut( CUtlBuffer::SEEK_HEAD, faceSize );

			// write out the face data
			for ( int i = 0; i < numfaces; i++ )
			{
				for ( int j = 0; j < MAXLIGHTMAPS; j++ )
				{
					g_pFaces[i].styles[j] = faceData.GetChar();
				}
				g_pFaces[i].lightofs = faceData.GetInt();
			}
		}
	}
}
Esempio n. 13
0
// This is obsolete, so it doesn't do anything with the data which is parsed.
void CSentence::ParseCloseCaption( CUtlBuffer& buf )
{
	char token[ 4096 ];
	while ( 1 )
	{
		// Format is 
		// language_name
		// {
		//   PHRASE char streamlength "streambytes" starttime endtime
		//   PHRASE unicode streamlength "streambytes" starttime endtime
		// }
		buf.GetString( token );
		if ( !stricmp( token, "}" ) )
			break;

		buf.GetString( token );
		if ( stricmp( token, "{" ) )
			break;

		buf.GetString( token );
		while ( 1 )
		{
			if ( !stricmp( token, "}" ) )
				break;

			if ( stricmp( token, "PHRASE" ) )
				break;

			char cc_type[32];
			char cc_stream[ 4096 ];
			int cc_length;

			memset( cc_stream, 0, sizeof( cc_stream ) );

			buf.GetString( token );
			Q_strncpy( cc_type, token, sizeof( cc_type ) );

			bool unicode = false;
			if ( !stricmp( cc_type, "unicode" ) )
			{
				unicode = true;
			}
			else if ( stricmp( cc_type, "char" ) )
			{
				Assert( 0 );
			}

			buf.GetString( token );
			cc_length = atoi( token );
			Assert( cc_length >= 0 && cc_length < sizeof( cc_stream ) );
			// Skip space
			buf.GetChar();
			buf.Get( cc_stream, cc_length );
			cc_stream[ cc_length ] = 0;
			
			// Skip space
			buf.GetChar();
			buf.GetString( token );
			buf.GetString( token );

			buf.GetString( token );
		}
	}
}
Esempio n. 14
0
void CSentence::ParseCloseCaption( CUtlBuffer& buf )
{
	char token[ 4096 ];
	while ( 1 )
	{
		// Format is 
		// language_name
		// {
		//   PHRASE char streamlength "streambytes" starttime endtime
		//   PHRASE unicode streamlength "streambytes" starttime endtime
		// }
		buf.GetString( token );
		if ( !stricmp( token, "}" ) )
			break;

		char language_name[ 128 ];
		int language_id;
		strcpy( language_name, token );
		language_id = CCloseCaptionPhrase::LanguageForName( language_name );
		Assert( language_id != -1 );

		buf.GetString( token );
		if ( stricmp( token, "{" ) )
			break;

		buf.GetString( token );
		while ( 1 )
		{

			if ( !stricmp( token, "}" ) )
				break;

			if ( stricmp( token, "PHRASE" ) )
				break;

			char cc_type[32];
			char cc_stream[ 512 ];
			int cc_length;
			float start, end;

			memset( cc_stream, 0, sizeof( cc_stream ) );

			buf.GetString( token );
			strcpy( cc_type, token );

			bool unicode = false;
			if ( !stricmp( cc_type, "unicode" ) )
			{
				unicode = true;
			}
			else if ( stricmp( cc_type, "char" ) )
			{
				Assert( 0 );
			}

			buf.GetString( token );
			cc_length = atoi( token );
			Assert( cc_length >= 0 && cc_length < sizeof( cc_stream ) );
			// Skip space
			buf.GetChar();
			buf.Get( cc_stream, cc_length );
			cc_stream[ cc_length ] = 0;
			
			wchar_t converted[ 256 ];
			// FIXME: Do unicode parsing, raw data parsing
			if ( unicode )
			{
				memcpy( converted, cc_stream, cc_length );
				cc_length /= 2;
				converted[ cc_length ] = L'\0';
			}
			else
			{
#ifndef SWDS // FIXME!!!!!!
				ConvertANSIToUnicode( cc_stream, converted, sizeof( converted ) );
#endif
			}
			
			// Skip space
			buf.GetChar();
			buf.GetString( token );
			start = atof( token );
			buf.GetString( token );
			end = atof( token );

			CCloseCaptionPhrase *phrase = new CCloseCaptionPhrase( converted );
			phrase->SetStartTime( start );
			phrase->SetEndTime( end );
			//phrase->SetType( cc_type );

			AddCloseCaptionPhrase( language_id, phrase );
			buf.GetString( token );
		}

	}
}