示例#1
0
//-----------------------------------------------------------------------------
// Purpose: chooses and loads the text page to display that describes mapName map
//-----------------------------------------------------------------------------
void CTeamMenu::LoadMapPage( const char *mapName )
{
	// Save off the map name so we can re-load the page in ApplySchemeSettings().
	Q_strncpy( m_szMapName, mapName, strlen( mapName ) + 1 );
	
	char mapRES[ MAX_PATH ];

	char uilanguage[ 64 ];
	engine->GetUILanguage( uilanguage, sizeof( uilanguage ) );

	Q_snprintf( mapRES, sizeof( mapRES ), "resource/maphtml/%s_%s.html", mapName, uilanguage );

	bool bFoundHTML = false;

	if ( !g_pFullFileSystem->FileExists( mapRES ) )
	{
		// try english
		Q_snprintf( mapRES, sizeof( mapRES ), "resource/maphtml/%s_english.html", mapName );
	}
	else
	{
		bFoundHTML = true;
	}

	if( bFoundHTML || g_pFullFileSystem->FileExists( mapRES ) )
	{
		// it's a local HTML file
		char localURL[ _MAX_PATH + 7 ];
		Q_strncpy( localURL, "file://", sizeof( localURL ) );

		char pPathData[ _MAX_PATH ];
		g_pFullFileSystem->GetLocalPath( mapRES, pPathData, sizeof(pPathData) );
		Q_strncat( localURL, pPathData, sizeof( localURL ), COPY_ALL_CHARACTERS );

		// force steam to dump a local copy
		g_pFullFileSystem->GetLocalCopy( pPathData );

		m_pMapInfo->SetVisible( false );

#if defined( ENABLE_HTML_WINDOW )
		m_pMapInfoHTML->SetVisible( true );
		m_pMapInfoHTML->OpenURL( localURL, NULL );
#endif
		InvalidateLayout();
		Repaint();		

		return;
	}
	else
	{
		m_pMapInfo->SetVisible( true );

#if defined( ENABLE_HTML_WINDOW )
		m_pMapInfoHTML->SetVisible( false );
#endif
	}

	Q_snprintf( mapRES, sizeof( mapRES ), "maps/%s.txt", mapName);

	// if no map specific description exists, load default text
	if( !g_pFullFileSystem->FileExists( mapRES ) )
	{
		if ( g_pFullFileSystem->FileExists( "maps/default.txt" ) )
		{
			Q_snprintf ( mapRES, sizeof( mapRES ), "maps/default.txt");
		}
		else
		{
			m_pMapInfo->SetText( "" );
			return; 
		}
	}

	FileHandle_t f = g_pFullFileSystem->Open( mapRES, "r" );

	// read into a memory block
	int fileSize = g_pFullFileSystem->Size(f);
	int dataSize = fileSize + sizeof( wchar_t );
	if ( dataSize % 2 )
		++dataSize;
	wchar_t *memBlock = (wchar_t *)malloc(dataSize);
	memset( memBlock, 0x0, dataSize);
	int bytesRead = g_pFullFileSystem->Read(memBlock, fileSize, f);
	if ( bytesRead < fileSize )
	{
		// NULL-terminate based on the length read in, since Read() can transform \r\n to \n and
		// return fewer bytes than we were expecting.
		char *data = reinterpret_cast<char *>( memBlock );
		data[ bytesRead ] = 0;
		data[ bytesRead+1 ] = 0;
	}

#ifndef WIN32
	if ( ((ucs2 *)memBlock)[0] == 0xFEFF )
	{
		// convert the win32 ucs2 data to wchar_t
		dataSize*=2;// need to *2 to account for ucs2 to wchar_t (4byte) growth
		wchar_t *memBlockConverted = (wchar_t *)malloc(dataSize);	
		V_UCS2ToUnicode( (ucs2 *)memBlock, memBlockConverted, dataSize );
		free(memBlock);
		memBlock = memBlockConverted;
	}
#else
	// null-terminate the stream (redundant, since we memset & then trimmed the transformed buffer already)
	memBlock[dataSize / sizeof(wchar_t) - 1] = 0x0000;
#endif
	// ensure little-endian unicode reads correctly on all platforms
	CByteswap byteSwap;
	byteSwap.SetTargetBigEndian( false );
	byteSwap.SwapBufferToTargetEndian( memBlock, memBlock, dataSize/sizeof(wchar_t) );

	// check the first character, make sure this a little-endian unicode file
	if ( memBlock[0] != 0xFEFF )
	{
		// its a ascii char file
		m_pMapInfo->SetText( reinterpret_cast<char *>( memBlock ) );
	}
	else
	{
		m_pMapInfo->SetText( memBlock+1 );
	}
	// go back to the top of the text buffer
	m_pMapInfo->GotoTextStart();

	g_pFullFileSystem->Close( f );
	free(memBlock);

	InvalidateLayout();
	Repaint();
}
//-----------------------------------------------------------------------------
// Load the bsp file
//-----------------------------------------------------------------------------
bool LoadBSPFile( const char* pFilename, void **ppBSPBuffer, int *pBSPSize )
{
	CByteswap	byteSwap;

	*ppBSPBuffer = NULL;
	*pBSPSize    = 0;

	FILE *fp = fopen( pFilename, "rb" );
	if ( fp )
	{
		fseek( fp, 0, SEEK_END );
		int size = ftell( fp );
		fseek( fp, 0, SEEK_SET );

		*ppBSPBuffer = malloc( size );
		if ( !*ppBSPBuffer )
		{
			Warning( "Failed to alloc %d bytes\n", size );
			goto cleanUp;
		}

		*pBSPSize = size;
		fread( *ppBSPBuffer, size, 1, fp );
		fclose( fp );
	}
	else
	{
		if ( !g_bQuiet )
		{
			Warning( "Missing %s\n", pFilename );
		}
		goto cleanUp;
	}	

	dheader_t *pBSPHeader = (dheader_t *)*ppBSPBuffer;

	if ( pBSPHeader->ident != IDBSPHEADER )
	{
		if ( pBSPHeader->ident != BigLong( IDBSPHEADER ) )
		{
			if ( !g_bQuiet )
			{
				Warning( "BSP %s has bad id: got %d, expected %d\n", pFilename, pBSPHeader->ident, IDBSPHEADER );
			}
			goto cleanUp;
		}
		else
		{
			// bsp is for 360, swap the header
			byteSwap.ActivateByteSwapping( true );
			byteSwap.SwapFieldsToTargetEndian( pBSPHeader );
		}
	}	

	if ( pBSPHeader->version < MINBSPVERSION || pBSPHeader->version > BSPVERSION )
	{
		if ( !g_bQuiet )
		{
			Warning( "BSP %s has bad version: got %d, expected %d\n", pFilename, pBSPHeader->version, BSPVERSION );
		}
		goto cleanUp;
	}	

	// sucess
	return true;

cleanUp:
	if ( *ppBSPBuffer )
	{
		free( *ppBSPBuffer );
		*ppBSPBuffer = NULL;
	}

	return false;
}
示例#3
0
	const void *FindSceneFile( CFlex *instance, const char *filename, bool allowBlockingIO )
	{
		// See if it's already loaded
		int i;
		for ( i = 0; i < m_FileList.Size(); i++ )
		{
			CFlexSceneFile *file = m_FileList[ i ];
			if ( file && !stricmp( file->filename, filename ) )
			{
				// Make sure translations (local to global flex controller) are set up for this instance
				EnsureTranslations( instance, ( const flexsettinghdr_t * )file->buffer );
				return file->buffer;
			}
		}

		if ( !allowBlockingIO )
		{
			return NULL;
		}

		// Load file into memory
		void *buffer = NULL;
		int len = filesystem->ReadFileEx( UTIL_VarArgs( "expressions/%s.vfe", filename ), "GAME", &buffer, false, true );

		if ( !len )
			return NULL;

		// Create scene entry
		CFlexSceneFile *pfile = new CFlexSceneFile;
		// Remember filename
		Q_strncpy( pfile->filename, filename, sizeof( pfile->filename ) );
		// Remember data pointer
		pfile->buffer = buffer;
		// Add to list
		m_FileList.AddToTail( pfile );

		// Swap the entire file
		if ( IsX360() )
		{
			CByteswap swap;
			swap.ActivateByteSwapping( true );
			byte *pData = (byte*)buffer;
			flexsettinghdr_t *pHdr = (flexsettinghdr_t*)pData;
			swap.SwapFieldsToTargetEndian( pHdr );

			// Flex Settings
			flexsetting_t *pFlexSetting = (flexsetting_t*)((byte*)pHdr + pHdr->flexsettingindex);
			for ( int i = 0; i < pHdr->numflexsettings; ++i, ++pFlexSetting )
			{
				swap.SwapFieldsToTargetEndian( pFlexSetting );
				
				flexweight_t *pWeight = (flexweight_t*)(((byte*)pFlexSetting) + pFlexSetting->settingindex );
				for ( int j = 0; j < pFlexSetting->numsettings; ++j, ++pWeight )
				{
					swap.SwapFieldsToTargetEndian( pWeight );
				}
			}

			// indexes
			pData = (byte*)pHdr + pHdr->indexindex;
			swap.SwapBufferToTargetEndian( (int*)pData, (int*)pData, pHdr->numindexes );

			// keymappings
			pData  = (byte*)pHdr + pHdr->keymappingindex;
			swap.SwapBufferToTargetEndian( (int*)pData, (int*)pData, pHdr->numkeys );

			// keyname indices
			pData = (byte*)pHdr + pHdr->keynameindex;
			swap.SwapBufferToTargetEndian( (int*)pData, (int*)pData, pHdr->numkeys );
		}

		// Fill in translation table
		EnsureTranslations( instance, ( const flexsettinghdr_t * )pfile->buffer );

		// Return data
		return pfile->buffer;
	}
示例#4
0
//-----------------------------------------------------------------------------
// Purpose: creates the font.  returns false if the font cannot be mounted.
//-----------------------------------------------------------------------------
bool CBitmapFont::Create( const char *pFontFilename, float scalex, float scaley, int flags )
{
	MEM_ALLOC_CREDIT();

	if ( !pFontFilename || !pFontFilename[0] )
	{
		return false;
	}

	CUtlSymbol symbol;
	char fontName[MAX_PATH];
	Q_FileBase( pFontFilename, fontName, MAX_PATH );
	Q_strlower( fontName );
	symbol = fontName;

	// find a match that can use same entries
	BitmapFontTable_t *pFontTable = NULL;
	for ( int i=0; i<g_BitmapFontTable.Count(); i++ )
	{
		if ( symbol == g_BitmapFontTable[i].m_szName )
		{
			m_bitmapFontHandle = i;
			pFontTable = &g_BitmapFontTable[m_bitmapFontHandle];
			break;
		}
	}

	if ( !pFontTable )
	{
		void *pBuf = NULL;
		int nLength; 

		nLength = FontManager().FileSystem()->ReadFileEx( pFontFilename, "GAME", &pBuf ); 
		if ( nLength <= 0 || !pBuf )
		{
			// not found
			return false;
		}

		if ( ((BitmapFont_t*)pBuf)->m_id != LittleLong( BITMAPFONT_ID ) || ((BitmapFont_t*)pBuf)->m_Version != LittleLong( BITMAPFONT_VERSION ) )
		{
			// bad version
			return false;
		}

		if ( IsX360() )
		{
			CByteswap swap;
			swap.ActivateByteSwapping( true );
			swap.SwapFieldsToTargetEndian( (BitmapFont_t*)pBuf );
			swap.SwapFieldsToTargetEndian( (BitmapGlyph_t*)((char*)pBuf + sizeof( BitmapFont_t )), ((BitmapFont_t*)pBuf)->m_NumGlyphs );
		}

		// create it
		m_bitmapFontHandle = g_BitmapFontTable.AddToTail();
		pFontTable = &g_BitmapFontTable[m_bitmapFontHandle];

		pFontTable->m_szName = fontName;

		pFontTable->m_pBitmapFont = new BitmapFont_t;
		memcpy( pFontTable->m_pBitmapFont, pBuf, sizeof( BitmapFont_t ) );

		pFontTable->m_pBitmapGlyphs = new BitmapGlyph_t[pFontTable->m_pBitmapFont->m_NumGlyphs];
		memcpy( pFontTable->m_pBitmapGlyphs, (unsigned char*)pBuf + sizeof(BitmapFont_t), pFontTable->m_pBitmapFont->m_NumGlyphs*sizeof(BitmapGlyph_t) );

		FontManager().FileSystem()->FreeOptimalReadBuffer( pBuf );

		// load the art resources
		char textureName[MAX_PATH];
		Q_snprintf( textureName, MAX_PATH, "vgui/fonts/%s", fontName );
		pFontTable->m_pTexture = FontManager().MaterialSystem()->FindTexture( textureName, TEXTURE_GROUP_VGUI );

#ifdef _DEBUG
		if ( pFontTable->m_pBitmapFont->m_PageWidth != pFontTable->m_pTexture->GetActualWidth() ||
			pFontTable->m_pBitmapFont->m_PageHeight != pFontTable->m_pTexture->GetActualHeight() )
		{
			// font is out of sync with its art
			Assert( 0 );
			return false;
		}
#endif
		// the font texture lives forever, ensure it doesn't get purged
		pFontTable->m_pTexture->IncrementReferenceCount();
	}

	// setup font properties
	m_scalex = scalex;
	m_scaley = scaley;

	// flags are derived from the baked font
	m_iFlags = vgui::ISurface::FONTFLAG_BITMAP;
	int bitmapFlags = pFontTable->m_pBitmapFont->m_Flags;

	if ( bitmapFlags & BF_ANTIALIASED )
	{
		m_iFlags |= vgui::ISurface::FONTFLAG_ANTIALIAS;
	}

	if ( bitmapFlags & BF_ITALIC )
	{
		m_iFlags |= vgui::ISurface::FONTFLAG_ITALIC;
	}

	if ( bitmapFlags & BF_BLURRED )
	{
		m_iFlags |= vgui::ISurface::FONTFLAG_GAUSSIANBLUR;
		m_iBlur = 1;
	}

	if ( bitmapFlags & BF_SCANLINES )
	{
		m_iScanLines = 1;
	}

	if ( bitmapFlags & BF_OUTLINED )
	{
		m_iFlags |= vgui::ISurface::FONTFLAG_OUTLINE;
		m_iOutlineSize = 1;
	}

	if ( bitmapFlags & BF_DROPSHADOW )
	{
		m_iFlags |= vgui::ISurface::FONTFLAG_DROPSHADOW;
		m_iDropShadowOffset = 1;
	}

	if ( flags & vgui::ISurface::FONTFLAG_ADDITIVE )
	{
		m_bAdditive = true;
		m_iFlags |= vgui::ISurface::FONTFLAG_ADDITIVE;
	}

	m_iMaxCharWidth = (float)pFontTable->m_pBitmapFont->m_MaxCharWidth * m_scalex;
	m_iHeight       = (float)pFontTable->m_pBitmapFont->m_MaxCharHeight * m_scaley;
	m_iAscent       = (float)pFontTable->m_pBitmapFont->m_Ascent * m_scaley;

	// mark as valid
	m_szName = symbol;

	return true;
}