Esempio n. 1
0
bool Unserialize( CUtlBuffer &buf, Color &dest )
{
	if ( buf.IsText() )
	{
		int r = 0, g = 0, b = 0, a = 255;
		int nRetVal = buf.Scanf( "%d %d %d %d", &r, &g, &b, &a );
		dest.SetColor( r, g, b, a );
		return (nRetVal == 4) && buf.IsValid();
	}

	dest[0] = buf.GetUnsignedChar( );
	dest[1] = buf.GetUnsignedChar( );
	dest[2] = buf.GetUnsignedChar( );
	dest[3] = buf.GetUnsignedChar( );
	return buf.IsValid();
}
Esempio n. 2
0
void CMomRunStats::Deserialize(CUtlBuffer &reader)
{
    SetTotalZones(reader.GetUnsignedChar());

    // NOTE: This range checking might result in unread data.
    if (m_iTotalZones > MAX_ZONES)
        SetTotalZones(MAX_ZONES);

    for (int i = 0; i < m_iTotalZones + 1; ++i)
    {
        SetZoneJumps(i, reader.GetUnsignedInt());
        SetZoneStrafes(i, reader.GetUnsignedInt());

        SetZoneStrafeSyncAvg(i, reader.GetFloat());
        SetZoneStrafeSync2Avg(i, reader.GetFloat());
        SetZoneEnterTick(i, reader.GetUnsignedInt());
        SetZoneTicks(i, reader.GetUnsignedInt());

        float vel3D = 0.0f, vel2D = 0.0f;
        vel3D = reader.GetFloat();
        vel2D = reader.GetFloat();
        SetZoneVelocityMax(i, vel3D, vel2D);
        vel3D = reader.GetFloat();
        vel2D = reader.GetFloat();
        SetZoneVelocityAvg(i, vel3D, vel2D);
        vel3D = reader.GetFloat();
        vel2D = reader.GetFloat();
        SetZoneEnterSpeed(i, vel3D, vel2D);
        vel3D = reader.GetFloat();
        vel2D = reader.GetFloat();
        SetZoneExitSpeed(i, vel3D, vel2D);
    }
}
Esempio n. 3
0
/// load the directory
void PlaceDirectory::Load( CUtlBuffer &fileBuffer, int version )
{
	// read number of entries
	IndexType count = fileBuffer.GetUnsignedShort();

	m_directory.RemoveAll();

	// read each entry
	char placeName[256];
	unsigned short len;
	for( int i=0; i<count; ++i )
	{
		len = fileBuffer.GetUnsignedShort();
		fileBuffer.Get( placeName, MIN( sizeof( placeName ), len ) );

		Place place = TheNavMesh->NameToPlace( placeName );
		if (place == UNDEFINED_PLACE)
		{
			Warning( "Warning: NavMesh place %s is undefined?\n", placeName );
		}
		AddPlace( place );
	}

	if ( version > 11 )
	{
		m_hasUnnamedAreas = fileBuffer.GetUnsignedChar() != 0;
	}
}
Esempio n. 4
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. 5
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. 6
0
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();
}