//----------------------------------------------------------------------------- // Generate spheremap based on the current images (only works for cubemaps) // The look dir indicates the direction of the center of the sphere //----------------------------------------------------------------------------- void CVTFTexture::GenerateSpheremap( LookDir_t lookDir ) { if (!IsCubeMap()) return; Assert( m_Format == IMAGE_FORMAT_RGBA8888 ); // We'll be doing our work in IMAGE_FORMAT_RGBA8888 mode 'cause it's easier unsigned char *pCubeMaps[6]; // Allocate the bits for the spheremap int iMemRequired = ImageLoader::GetMemRequired( m_nWidth, m_nHeight, IMAGE_FORMAT_RGBA8888, false ); unsigned char *pSphereMapBits = (unsigned char *)MemAllocScratch(iMemRequired); // Generate a spheremap for each frame of the cubemap for (int iFrame = 0; iFrame < m_nFrameCount; ++iFrame) { // Point to our own textures (highest mip level) for (int iFace = 0; iFace < 6; ++iFace) { pCubeMaps[iFace] = ImageData( iFrame, iFace, 0 ); } // Compute the spheremap of the top LOD ComputeSpheremapFrame( pCubeMaps, pSphereMapBits, lookDir ); // Compute the mip levels of the spheremap, converting from RGBA8888 to our format unsigned char *pFinalSphereMapBits = ImageData( iFrame, CUBEMAP_FACE_SPHEREMAP, 0 ); ImageLoader::GenerateMipmapLevels( pSphereMapBits, pFinalSphereMapBits, m_nWidth, m_nHeight, m_Format, 2.2, 2.2 ); } // Free memory MemFreeScratch(); }
bool KeyValues::LoadFromFile(IFileSystem *filesystem, const char *resourceName, const char *pathID) { assert(filesystem); assert(IsX360() || (IsPC() && _heapchk() == _HEAPOK)); FileHandle_t f = filesystem->Open(resourceName, "rb", pathID); if (!f) return false; s_LastFileLoadingFrom = (char *)resourceName; int fileSize = filesystem->Size(f); char *buffer = (char *)MemAllocScratch(fileSize + 1); Assert(buffer); bool bRetOK = (filesystem->Read(buffer, fileSize, f) != 0); filesystem->Close(f); if (bRetOK) { buffer[fileSize] = 0; bRetOK = LoadFromBuffer(resourceName, buffer, filesystem); } MemFreeScratch(); return bRetOK; }
KeyValues* ReadEncryptedKVPlayerClassFile( IFileSystem *filesystem, const char *szFilenameWithoutExtension, const unsigned char *pICEKey ) { Assert( strchr( szFilenameWithoutExtension, '.' ) == NULL ); char szFullName[512]; // Open the weapon data file, and abort if we can't KeyValues *pKV = new KeyValues( "PlayerClassDatafile" ); Q_snprintf(szFullName,sizeof(szFullName), "%s.txt", szFilenameWithoutExtension); if ( !pKV->LoadFromFile( filesystem, szFullName, "GAME" ) ) // try to load the normal .txt file first { if ( pICEKey ) { Q_snprintf(szFullName,sizeof(szFullName), "%s.ctx", szFilenameWithoutExtension); // fall back to the .ctx file FileHandle_t f = filesystem->Open( szFullName, "rb", "GAME"); if (!f) { pKV->deleteThis(); return NULL; } // load file into a null-terminated buffer int fileSize = filesystem->Size(f); char *buffer = (char*)MemAllocScratch(fileSize + 1); Assert(buffer); filesystem->Read(buffer, fileSize, f); // read into local buffer buffer[fileSize] = 0; // null terminate file as EOF filesystem->Close( f ); // close file after reading UTIL_DecodeICE( (unsigned char*)buffer, fileSize, pICEKey ); bool retOK = pKV->LoadFromBuffer( szFullName, buffer, filesystem ); MemFreeScratch(); if ( !retOK ) { pKV->deleteThis(); return NULL; } } else { pKV->deleteThis(); return NULL; } } return pKV; }
bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID) { #if defined METAMOD_PLAPI_VERSION if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL) #else if (strcasecmp(g_SourceMod.GetGameFolderName(), "ship") == 0) #endif { Assert(filesystem); #ifdef _MSC_VER Assert(_heapchk() == _HEAPOK); #endif FileHandle_t f = filesystem->Open(resourceName, "rb", pathID); if (!f) return false; // load file into a null-terminated buffer int fileSize = filesystem->Size(f); char *buffer = (char *)MemAllocScratch(fileSize + 1); Assert(buffer); filesystem->Read(buffer, fileSize, f); // read into local buffer buffer[fileSize] = 0; // null terminate file as EOF filesystem->Close( f ); // close file after reading bool retOK = kv->LoadFromBuffer( resourceName, buffer, filesystem ); MemFreeScratch(); return retOK; } else { return kv->LoadFromFile(filesystem, resourceName, pathID); } }
//----------------------------------------------------------------------------- // Converts the texture's image format. Use IMAGE_FORMAT_DEFAULT // if you want to be able to use various tool functions below //----------------------------------------------------------------------------- void CVTFTexture::ConvertImageFormat( ImageFormat fmt, bool bNormalToDUDV ) { if ( !m_pImageData ) return; if (fmt == IMAGE_FORMAT_DEFAULT) fmt = IMAGE_FORMAT_RGBA8888; if( bNormalToDUDV && !( fmt == IMAGE_FORMAT_UV88 || fmt == IMAGE_FORMAT_UVWQ8888 ) ) { Assert( 0 ); return; } if (m_Format == fmt) return; // FIXME: Should this be re-written to not do an allocation? int iConvertedSize = ComputeTotalSize( fmt ); unsigned char *pConvertedImage = (unsigned char*)MemAllocScratch(iConvertedSize); for (int iMip = 0; iMip < m_nMipCount; ++iMip) { int nMipWidth, nMipHeight; ComputeMipLevelDimensions( iMip, &nMipWidth, &nMipHeight ); for (int iFrame = 0; iFrame < m_nFrameCount; ++iFrame) { for (int iFace = 0; iFace < m_nFaceCount; ++iFace) { unsigned char *pSrcData = ImageData( iFrame, iFace, iMip ); unsigned char *pDstData = pConvertedImage + GetImageOffset( iFrame, iFace, iMip, fmt ); if( bNormalToDUDV ) { if( fmt == IMAGE_FORMAT_UV88 ) { ImageLoader::ConvertNormalMapRGBA8888ToDUDVMapUV88( pSrcData, nMipWidth, nMipHeight, pDstData ); } else if( fmt == IMAGE_FORMAT_UVWQ8888 ) { ImageLoader::ConvertNormalMapRGBA8888ToDUDVMapUVWQ8888( pSrcData, nMipWidth, nMipHeight, pDstData ); } else { Assert( 0 ); return; } } else { ImageLoader::ConvertImageFormat( pSrcData, m_Format, pDstData, fmt, nMipWidth, nMipHeight ); } } } } AllocateImageData(iConvertedSize); memcpy( m_pImageData, pConvertedImage, iConvertedSize ); m_Format = fmt; MemFreeScratch(); }
void C_ASW_Medal_Store::LoadMedalStore() { #if defined(NO_STEAM) AssertMsg( false, "SteamCloud not available." ); #else ISteamRemoteStorage *pRemoteStorage = SteamClient() ? ( ISteamRemoteStorage * )SteamClient()->GetISteamGenericInterface( SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), STEAMREMOTESTORAGE_INTERFACE_VERSION ) : NULL; ISteamUser *pSteamUser = steamapicontext ? steamapicontext->SteamUser() : NULL; if ( !pSteamUser ) return; char szMedalFile[ 256 ]; Q_snprintf( szMedalFile, sizeof( szMedalFile ), "cfg/clientc_%I64u.dat", pSteamUser->GetSteamID().ConvertToUint64() ); int len = Q_strlen( szMedalFile ); for ( int i = 0; i < len; i++ ) { if ( szMedalFile[ i ] == ':' ) szMedalFile[i] = '_'; } if ( asw_steam_cloud.GetBool() && pRemoteStorage ) { if ( !GetFileFromRemoteStorage( pRemoteStorage, "PersistentMarines.dat", szMedalFile ) ) { #ifdef _DEBUG Warning( "Failed to get client.dat from Steam Cloud.\n" ); #endif } } #endif // clear out the currently loaded medals, if any for (int i=0;i<ASW_NUM_MARINE_PROFILES;i++) { m_MarineMedals[i].Purge(); m_OfflineMarineMedals[i].Purge(); } m_PlayerMedals.Purge(); m_OfflinePlayerMedals.Purge(); m_bLoaded = true; FileHandle_t f = filesystem->Open( szMedalFile, "rb", "MOD" ); if ( !f ) return; // if we get here, it means the player has no clientc.dat file and therefore no medals int fileSize = filesystem->Size(f); char *file_buffer = (char*)MemAllocScratch(fileSize + 1); Assert(file_buffer); filesystem->Read(file_buffer, fileSize, f); // read into local buffer file_buffer[fileSize] = 0; // null terminate file as EOF filesystem->Close( f ); // close file after reading UTIL_DecodeICE( (unsigned char*)file_buffer, fileSize, g_ucMedalStoreEncryptionKey ); KeyValues *kv = new KeyValues( "CLIENTDAT" ); if ( !kv->LoadFromBuffer( "CLIENTDAT", file_buffer, filesystem ) ) { return; } MemFreeScratch(); m_bFoundNewClientDat = true; // pull out missions/campaigns/kills m_iMissionsCompleted = kv->GetInt("MC"); m_iCampaignsCompleted = kv->GetInt("CC"); m_iAliensKilled = kv->GetInt("AK"); m_iOfflineMissionsCompleted = kv->GetInt("OMC"); m_iOfflineCampaignsCompleted = kv->GetInt("OCC"); m_iOfflineAliensKilled = kv->GetInt("OAK"); m_iXP = kv->GetInt( "LPL" ); m_iPromotion = kv->GetInt( "LPP" ); // new equip m_NewEquipment.Purge(); KeyValues *pkvEquip = kv->FindKey("NEWEQUIP"); char buffer[64]; if ( pkvEquip ) { for ( KeyValues *pKey = pkvEquip->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey() ) { m_NewEquipment.AddToTail( pKey->GetInt() ); } } // first subsection is player medals //KeyValues *pkvPlayerMedals = kv->GetFirstSubKey(); KeyValues *pkvPlayerMedals = kv->FindKey("LP"); int iMedalNum = 0; if (pkvPlayerMedals) { int iMedal = 0; while (iMedal != -1) { Q_snprintf(buffer, sizeof(buffer), "M%d", iMedalNum); iMedal = pkvPlayerMedals->GetInt(buffer, -1); if (iMedal != -1 && IsPlayerMedal(iMedal)) { m_PlayerMedals.AddToTail(iMedal); } iMedalNum++; } } // now go through each marine for (int i=0;i<ASW_NUM_MARINE_PROFILES;i++) { Q_snprintf(buffer, sizeof(buffer), "LA%d", i); KeyValues *pkvMarineMedals = kv->FindKey(buffer); if (pkvMarineMedals) { iMedalNum = 0; int iMedal = 0; while (iMedal != -1) { Q_snprintf(buffer, sizeof(buffer), "M%d", iMedalNum); iMedal = pkvMarineMedals->GetInt(buffer, -1); if (iMedal != -1 && !IsPlayerMedal(iMedal)) { m_MarineMedals[i].AddToTail(iMedal); } iMedalNum++; } } } // offline medal store pkvPlayerMedals = kv->FindKey("FP"); iMedalNum = 0; if (pkvPlayerMedals) { int iMedal = 0; while (iMedal != -1) { Q_snprintf(buffer, sizeof(buffer), "M%d", iMedalNum); iMedal = pkvPlayerMedals->GetInt(buffer, -1); if (iMedal != -1 && IsPlayerMedal(iMedal)) { m_OfflinePlayerMedals.AddToTail(iMedal); } iMedalNum++; } } // now go through each marine for (int i=0;i<ASW_NUM_MARINE_PROFILES;i++) { Q_snprintf(buffer, sizeof(buffer), "FA%d", i); KeyValues *pkvMarineMedals = kv->FindKey(buffer); if (pkvMarineMedals) { iMedalNum = 0; int iMedal = 0; while (iMedal != -1) { Q_snprintf(buffer, sizeof(buffer), "M%d", iMedalNum); iMedal = pkvMarineMedals->GetInt(buffer, -1); if (iMedal != -1 && !IsPlayerMedal(iMedal)) { m_OfflineMarineMedals[i].AddToTail(iMedal); } iMedalNum++; } } } }