// // This method handles parsing a single file, it can be called // many times if a wildcard path was passed to InitParser. // Input: pszFilePath - FS path to a KeyValue file for parsing. // bWildcard - Is this file the only one to be parsed? or will more come... // bool CScriptParser::ParseFile( const char *pszFilePath ) { // Load the file into a buffer (null-terminated) char *buffer = (char*) UTIL_LoadFileForMe( pszFilePath, NULL ); if ( !buffer ) return false; // If we are encrypted, decrypt us const char *fileName = Q_UnqualifiedFileName( pszFilePath ); if( CompareExtensions( fileName, GetEncryptedEXT() ) ) UTIL_DecodeICE( (unsigned char*)buffer, Q_strlen(buffer), g_pGameRules->GetEncryptionKey() ); // Remove the extension char fileNameNoExt[64]; Q_StripExtension( fileName, fileNameNoExt, 64 ); KeyValues *pKV = new KeyValues( fileNameNoExt ); if( !pKV->LoadFromBuffer( fileNameNoExt, buffer ) ) { pKV->deleteThis(); delete [] buffer; return false; } Parse( pKV, fileNameNoExt ); pKV->deleteThis(); delete[] buffer; return true; }
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; }
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++; } } } }