SB_API HSteamUser S_CALLTYPE GetHSteamUser_() { return SteamAPI_GetHSteamUser(); }
bool C_ASW_Medal_Store::SaveMedalStore() { if ( !m_bLoaded ) return false; KeyValues *kv = new KeyValues( "CLIENTDAT" ); // output missions/campaigns/kills kv->SetInt("MC", m_iMissionsCompleted); kv->SetInt("CC", m_iCampaignsCompleted); kv->SetInt("AK", m_iAliensKilled); kv->SetInt("OMC", m_iOfflineMissionsCompleted); kv->SetInt("OCC", m_iOfflineCampaignsCompleted); kv->SetInt("OAK", m_iOfflineAliensKilled); kv->SetInt( "LPL", m_iXP ); kv->SetInt( "LPP", m_iPromotion ); KeyValues *pSubSection = new KeyValues("NEWEQUIP"); char buffer[64]; if (pSubSection) { for (int i=0;i<m_NewEquipment.Count();i++) { pSubSection->SetInt( "EQUIP", m_NewEquipment[i]); } kv->AddSubKey(pSubSection); } // output player medals pSubSection = new KeyValues("LP"); if (pSubSection) { for (int i=0;i<m_PlayerMedals.Count();i++) { Q_snprintf(buffer, sizeof(buffer), "M%d", i); pSubSection->SetInt(buffer, m_PlayerMedals[i]); } kv->AddSubKey(pSubSection); } for (int k=0;k<ASW_NUM_MARINE_PROFILES;k++) { Q_snprintf(buffer, sizeof(buffer), "LA%d", k); pSubSection = new KeyValues(buffer); if (pSubSection) { for (int i=0;i<m_MarineMedals[k].Count();i++) { Q_snprintf(buffer, sizeof(buffer), "M%d", i); pSubSection->SetInt(buffer, m_MarineMedals[k][i]); } kv->AddSubKey(pSubSection); } } // offline medal store pSubSection = new KeyValues("FP"); if (pSubSection) { for (int i=0;i<m_OfflinePlayerMedals.Count();i++) { Q_snprintf(buffer, sizeof(buffer), "M%d", i); pSubSection->SetInt(buffer, m_OfflinePlayerMedals[i]); } kv->AddSubKey(pSubSection); } for (int k=0;k<ASW_NUM_MARINE_PROFILES;k++) { Q_snprintf(buffer, sizeof(buffer), "FA%d", k); pSubSection = new KeyValues(buffer); if (pSubSection) { for (int i=0;i<m_OfflineMarineMedals[k].Count();i++) { Q_snprintf(buffer, sizeof(buffer), "M%d", i); pSubSection->SetInt(buffer, m_OfflineMarineMedals[k][i]); } kv->AddSubKey(pSubSection); } } CUtlBuffer buf; //( 0, 0, CUtlBuffer::TEXT_BUFFER ); kv->RecursiveSaveToFile( buf, 0 ); // pad buffer with zeroes to make a multiple of 8 int nExtra = buf.TellPut() % 8; while ( nExtra != 0 && nExtra < 8 ) { buf.PutChar( 0 ); nExtra++; } UTIL_EncodeICE( (unsigned char*) buf.Base(), buf.TellPut(), g_ucMedalStoreEncryptionKey ); ISteamUser *pSteamUser = steamapicontext ? steamapicontext->SteamUser() : NULL; if ( !pSteamUser ) return false; 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] = '_'; } bool bResult = filesystem->WriteFile( szMedalFile, "MOD", buf ); if ( bResult ) { #if defined(NO_STEAM) AssertMsg( false, "SteamCloud not available." ); #else ISteamRemoteStorage *pRemoteStorage = SteamClient() ? ( ISteamRemoteStorage * )SteamClient()->GetISteamGenericInterface( SteamAPI_GetHSteamUser(), SteamAPI_GetHSteamPipe(), STEAMREMOTESTORAGE_INTERFACE_VERSION ) : NULL; if ( asw_steam_cloud.GetBool() && pRemoteStorage ) { WriteFileToRemoteStorage( pRemoteStorage, "PersistentMarines.dat", szMedalFile ); } #endif } return bResult; }
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++; } } } }
STEAM_API_PROXY_API HSteamUser GetHSteamUser() { __TRACE("()"); return SteamAPI_GetHSteamUser(); }