void CSentence::ParseEmphasis( CUtlBuffer& buf ) { char token[ 4096 ]; while ( 1 ) { buf.GetString( token ); if ( !stricmp( token, "}" ) ) break; char t[ 256 ]; Q_strncpy( t, token, sizeof( t ) ); buf.GetString( token ); char value[ 256 ]; Q_strncpy( value, token, sizeof( value ) ); CEmphasisSample sample; sample.SetSelected( false ); sample.time = atof( t ); sample.value = atof( value ); m_EmphasisSamples.AddToTail( sample ); } }
void CSentence::ParseOptions( CUtlBuffer& buf ) { char token[ 4096 ]; while ( 1 ) { buf.GetString( token ); if ( !stricmp( token, "}" ) ) break; if ( Q_strlen( token ) == 0 ) break; char key[ 256 ]; Q_strncpy( key, token, sizeof( key ) ); char value[ 256 ]; buf.GetString( token ); Q_strncpy( value, token, sizeof( value ) ); if ( !strcmpi( key, "voice_duck" ) ) { SetVoiceDuck( atoi(value) ? true : false ); } else if ( !strcmpi( key, "checksum" ) ) { SetDataCheckSum( (unsigned int)atoi( value ) ); } } }
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; }
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; }
//----------------------------------------------------------------------------- // Purpose: VERSION 1.0 parser, need to implement new ones if // file format changes!!! // Input : buf - //----------------------------------------------------------------------------- void CSentence::ParseDataVersionOnePointZero( CUtlBuffer& buf ) { char token[ 4096 ]; while ( 1 ) { buf.GetString( token ); if ( strlen( token ) <= 0 ) break; // end of block, return if ( !V_strcmp( token, "}" ) ) break; char section[ 256 ]; Q_strncpy( section, token, sizeof( section ) ); buf.GetString( token ); if ( stricmp( token, "{" ) ) break; if ( !stricmp( section, "PLAINTEXT" ) ) { ParsePlaintext( buf ); } else if ( !stricmp( section, "WORDS" ) ) { ParseWords( buf ); } else if ( !stricmp( section, "EMPHASIS" ) ) { ParseEmphasis( buf ); } else if ( !stricmp( section, "CLOSECAPTION" ) ) { // NOTE: CLOSECAPTION IS NO LONGER VALID // This just skips the section of data. ParseCloseCaption( buf ); } else if ( !stricmp( section, "OPTIONS" ) ) { ParseOptions( buf ); } } }
bool GetStringHelper( CUtlBuffer & cmd, char *outBuf, int bufSize ) { outBuf[0] = 0; cmd.GetString(outBuf, bufSize); if ( !cmd.IsValid() ) { cmd.Purge(); return false; } return true; }
void CSentence::ParseOptions( CUtlBuffer& buf ) { char token[ 4096 ]; while ( 1 ) { buf.GetString( token ); if ( !stricmp( token, "}" ) ) break; char key[ 256 ]; strcpy( key, token ); char value[ 256 ]; buf.GetString( token ); strcpy( value, token ); if ( !strcmpi( key, "voice_duck" ) ) { SetVoiceDuck( atoi(value) ? true : false ); } } }
//----------------------------------------------------------------------------- // Purpose: VERSION 1.0 parser, need to implement new ones if // file format changes!!! // Input : buf - //----------------------------------------------------------------------------- void CSentence::ParseDataVersionOnePointZero( CUtlBuffer& buf ) { char token[ 4096 ]; while ( 1 ) { buf.GetString( token ); if ( strlen( token ) <= 0 ) break; char section[ 256 ]; strcpy( section, token ); buf.GetString( token ); if ( stricmp( token, "{" ) ) break; if ( !stricmp( section, "PLAINTEXT" ) ) { ParsePlaintext( buf ); } else if ( !stricmp( section, "WORDS" ) ) { ParseWords( buf ); } else if ( !stricmp( section, "EMPHASIS" ) ) { ParseEmphasis( buf ); } else if ( !stricmp( section, "CLOSECAPTION" ) ) { ParseCloseCaption( buf ); } else if ( !stricmp( section, "OPTIONS" ) ) { ParseOptions( buf ); } } }
//----------------------------------------------------------------------------- // Purpose: // Input : buf - //----------------------------------------------------------------------------- void CSentence::InitFromBuffer( CUtlBuffer& buf ) { Assert( buf.IsText() ); Reset(); char token[ 4096 ]; buf.GetString( token ); if ( stricmp( token, "VERSION" ) ) return; buf.GetString( token ); if ( atof( token ) == 1.0f ) { ParseDataVersionOnePointZero( buf ); m_bIsValid = true; } else { assert( 0 ); return; } }
void CSentence::ParsePlaintext( CUtlBuffer& buf ) { char token[ 4096 ]; char text[ 4096 ]; text[ 0 ] = 0; while ( 1 ) { buf.GetString( token ); if ( !stricmp( token, "}" ) ) break; strcat( text, token ); strcat( text, " " ); } SetText( text ); }
void CSentence::ParsePlaintext( CUtlBuffer& buf ) { char token[ 4096 ]; char text[ 4096 ]; text[ 0 ] = 0; while ( 1 ) { buf.GetString( token ); if ( !stricmp( token, "}" ) ) break; Q_strncat( text, token, sizeof( text ), COPY_ALL_CHARACTERS ); Q_strncat( text, " ", sizeof( text ), COPY_ALL_CHARACTERS ); } SetText( text ); }
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; }
bool CNetworkStringTableContainer::ReadStringTables( CUtlBuffer& buf ) { int numTables = buf.GetInt(); for ( int i = 0 ; i < numTables; i++ ) { char tablename[ 256 ]; buf.GetString( tablename, sizeof( tablename ) ); // Find this table by name CNetworkStringTable *table = (CNetworkStringTable*)FindTable( tablename ); Assert( table ); // Now read the data for the table if ( !table->ReadStringTable( buf ) ) { Host_Error( "Error reading string table %s\n", tablename ); } } return true; }
void CModelSoundsCache::Restore( CUtlBuffer& buf ) { MEM_ALLOC_CREDIT(); unsigned short c; c = (unsigned short)buf.GetShort(); for ( int i = 0; i < c; ++i ) { char soundname[ 512 ]; buf.GetString( soundname, sizeof( soundname ) ); int idx = soundemitterbase->GetSoundIndex( soundname ); if ( idx != -1 ) { Assert( idx <= 65535 ); if ( sounds.Find( idx ) == sounds.InvalidIndex() ) { sounds.AddToTail( (unsigned short)idx ); } } } }
bool KeyValues::ReadAsBinary(CUtlBuffer &buffer) { if (buffer.IsText()) return false; if (!buffer.IsValid()) return false; RemoveEverything(); Init(); char token[KEYVALUES_TOKEN_SIZE]; KeyValues *dat = this; types_t type = (types_t)buffer.GetUnsignedChar(); while (true) { if (type == TYPE_NUMTYPES) break; dat->m_iDataType = type; buffer.GetString(token, KEYVALUES_TOKEN_SIZE - 1); token[KEYVALUES_TOKEN_SIZE - 1] = 0; dat->SetName(token); switch (type) { case TYPE_NONE: { dat->m_pSub = new KeyValues(""); dat->m_pSub->ReadAsBinary(buffer); break; } case TYPE_STRING: { buffer.GetString(token, KEYVALUES_TOKEN_SIZE - 1); token[KEYVALUES_TOKEN_SIZE - 1] = 0; int len = Q_strlen(token); dat->m_sValue = new char[len + 1]; Q_memcpy(dat->m_sValue, token, len + 1); break; } case TYPE_WSTRING: { Assert(!"TYPE_WSTRING"); break; } case TYPE_INT: { dat->m_iValue = buffer.GetInt(); break; } case TYPE_UINT64: { dat->m_sValue = new char[sizeof(uint64)]; *((double *)dat->m_sValue) = buffer.GetDouble(); } case TYPE_FLOAT: { dat->m_flValue = buffer.GetFloat(); break; } case TYPE_COLOR: { dat->m_Color[0] = buffer.GetUnsignedChar(); dat->m_Color[1] = buffer.GetUnsignedChar(); dat->m_Color[2] = buffer.GetUnsignedChar(); dat->m_Color[3] = buffer.GetUnsignedChar(); break; } case TYPE_PTR: { dat->m_pValue = (void *)buffer.GetUnsignedInt(); } default: { break; } } if (!buffer.IsValid()) return false; type = (types_t)buffer.GetUnsignedChar(); if (type == TYPE_NUMTYPES) break; dat->m_pPeer = new KeyValues(""); dat = dat->m_pPeer; } return buffer.IsValid(); }
void CSentence::ParseWords( CUtlBuffer& buf ) { char token[ 4096 ]; char word[ 256 ]; float start, end; while ( 1 ) { buf.GetString( token ); if ( !stricmp( token, "}" ) ) break; if ( stricmp( token, "WORD" ) ) break; buf.GetString( token ); Q_strncpy( word, token, sizeof( word ) ); buf.GetString( token ); start = atof( token ); buf.GetString( token ); end = atof( token ); CWordTag *wt = new CWordTag( word ); assert( wt ); wt->m_flStartTime = start; wt->m_flEndTime = end; AddWordTag( wt ); buf.GetString( token ); if ( stricmp( token, "{" ) ) break; while ( 1 ) { buf.GetString( token ); if ( !stricmp( token, "}" ) ) break; // Parse phoneme int code; char phonemename[ 256 ]; float start, end; float volume; code = atoi( token ); buf.GetString( token ); Q_strncpy( phonemename, token, sizeof( phonemename ) ); buf.GetString( token ); start = atof( token ); buf.GetString( token ); end = atof( token ); buf.GetString( token ); volume = atof( token ); CPhonemeTag *pt = new CPhonemeTag(); assert( pt ); pt->SetPhonemeCode( code ); pt->SetTag( phonemename ); pt->SetStartTime( start ); pt->SetEndTime( end ); AddPhonemeTag( wt, pt ); } } }
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 ); } } }
// 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 ); } } }