Esempio n. 1
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. 2
0
//-----------------------------------------------------------------------------
// Get PSD file image resources
//-----------------------------------------------------------------------------
PSDImageResources PSDGetImageResources( CUtlBuffer &buf )
{
	int nGet = buf.TellGet();

	// Header
	PSDHeader_t header;
	buf.Get( &header, sizeof( header ) );

	// Then palette
	unsigned int numBytesPalette = BigLong( buf.GetUnsignedInt() );
	buf.SeekGet( CUtlBuffer::SEEK_CURRENT, numBytesPalette );

	// Then image resources
	unsigned int numBytesImgResources = BigLong( buf.GetUnsignedInt() );
	PSDImageResources imgres( numBytesImgResources, ( unsigned char * ) buf.PeekGet() );

	// Restore the seek
	buf.SeekGet( CUtlBuffer::SEEK_HEAD, nGet );

	return imgres;
}
Esempio n. 3
0
void CSceneCache::Restore( CUtlBuffer& buf  )
{
	MEM_ALLOC_CREDIT();

	msecs = buf.GetUnsignedInt();

	unsigned short 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 );
			}
		}
	}
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// Reads the PSD file into the specified buffer
//-----------------------------------------------------------------------------
bool PSDReadFileRGBA8888( CUtlBuffer &buf, Bitmap_t &bitmap )
{
	PSDHeader_t header;
	buf.Get( &header, sizeof(header) );

	if ( BigLong( header.m_nSignature ) != PSD_SIGNATURE )
		return false;
	if ( BigShort( header.m_nVersion ) != 1 )
		return false;
	if ( BigShort( header.m_nDepth ) != 8 )
		return false;

	PSDMode_t mode = (PSDMode_t)BigShort( header.m_nMode );
	int nChannelsCount = BigShort( header.m_nChannels );

	if ( mode == MODE_MULTICHANNEL || mode == MODE_LAB )
		return false;

	switch ( mode )
	{
	case MODE_RGBA:
		if ( nChannelsCount < 3 )
			return false;
		break;

	case MODE_GREYSCALE:
	case MODE_PALETTIZED:
		if ( nChannelsCount != 1 && nChannelsCount != 2 )
			return false;
		break;

	case MODE_CMYK:
		if ( nChannelsCount < 4 )
			return false;
		break;

	default:
		Warning( "Unsupported PSD color mode!\n" );
		return false;
	}

	int nWidth = BigLong( header.m_nColumns );
	int nHeight = BigLong( header.m_nRows );

	// Skip parts of memory we don't care about
	int nColorModeSize = BigLong( buf.GetUnsignedInt() );
	Assert( nColorModeSize % 3 == 0 );
	unsigned char *pPaletteBits = (unsigned char*)_alloca( nColorModeSize );
	PSDPalette_t palette;
	palette.m_pRed = palette.m_pGreen = palette.m_pBlue = 0;
	if ( nColorModeSize )
	{
		int nPaletteSize = nColorModeSize / 3;
		buf.Get( pPaletteBits, nColorModeSize );
		palette.m_pRed = pPaletteBits;
		palette.m_pGreen = palette.m_pRed + nPaletteSize;
		palette.m_pBlue = palette.m_pGreen + nPaletteSize;
	}
 	int nImageResourcesSize = BigLong( buf.GetUnsignedInt() );
	buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nImageResourcesSize );
	int nLayersSize = BigLong( buf.GetUnsignedInt() );
	buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nLayersSize );

	unsigned short nCompressionType = BigShort( buf.GetShort() );

	bitmap.Init( nWidth, nHeight, IMAGE_FORMAT_RGBA8888 );

	bool bSecondPassCMYKA = ( nChannelsCount > 4 && mode == MODE_CMYK );
	if ( nCompressionType == 0 )
	{
		PSDReadUncompressedChannels( buf, ( nChannelsCount > 4 ) ? 4 : nChannelsCount, mode, palette, bitmap );
	}
	else
	{
		// Skip the data that indicates the length of each compressed row in bytes
		// NOTE: There are two bytes per row per channel
		unsigned int nLineLengthData = sizeof(unsigned short) * bitmap.m_nHeight * nChannelsCount;
		buf.SeekGet( CUtlBuffer::SEEK_CURRENT, nLineLengthData );
		PSDReadCompressedChannels( buf, ( nChannelsCount > 4 ) ? 4 : nChannelsCount, mode, palette, bitmap );
	}

	// Read the alpha in a second pass for CMYKA
	if ( bSecondPassCMYKA )
	{
		if ( nCompressionType == 0 )
		{
			PSDReadUncompressedChannels( buf, 1, MODE_COUNT, palette, bitmap );
		}
		else
		{
			PSDReadCompressedChannels( buf, 1, MODE_COUNT, palette, bitmap );
		}
	}

	return true;
}
Esempio n. 5
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();
}