//----------------------------------------------------------------------------- // 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(); }
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; }