| 1631 | } |
| 1632 | |
| 1633 | void Achievements::LoadState(std::span<const u8> data) |
| 1634 | { |
| 1635 | const auto lock = GetLock(); |
| 1636 | |
| 1637 | if (!IsActive()) |
| 1638 | return; |
| 1639 | |
| 1640 | // this assumes that the CRC and ELF name has been loaded prior to the cheevos state (it should be). |
| 1641 | GameChanged(VMManager::GetDiscCRC(), VMManager::GetCurrentCRC()); |
| 1642 | |
| 1643 | #ifdef ENABLE_RAINTEGRATION |
| 1644 | if (IsUsingRAIntegration()) |
| 1645 | { |
| 1646 | if (data.empty()) |
| 1647 | { |
| 1648 | Console.Warning("State is missing cheevos data, resetting RAIntegration"); |
| 1649 | RA_OnReset(); |
| 1650 | } |
| 1651 | else |
| 1652 | { |
| 1653 | RA_RestoreState(reinterpret_cast<const char*>(data.data())); |
| 1654 | } |
| 1655 | |
| 1656 | return; |
| 1657 | } |
| 1658 | #endif |
| 1659 | |
| 1660 | // if we're active, make sure we've downloaded and activated all the achievements |
| 1661 | // before deserializing, otherwise that state's going to get lost. |
| 1662 | if (s_http_downloader->HasAnyRequests()) |
| 1663 | { |
| 1664 | bool was_running_idle; |
| 1665 | BeginLoadingScreen("Downloading achievements data...", &was_running_idle); |
| 1666 | s_http_downloader->WaitForAllRequests(); |
| 1667 | EndLoadingScreen(was_running_idle); |
| 1668 | } |
| 1669 | |
| 1670 | if (data.empty()) |
| 1671 | { |
| 1672 | // reset runtime, no data (state might've been created without cheevos) |
| 1673 | Console.Warning("State is missing cheevos data, resetting runtime"); |
| 1674 | rc_client_reset(s_client); |
| 1675 | return; |
| 1676 | } |
| 1677 | |
| 1678 | // These routines scare me a bit.. the data isn't bounds checked. |
| 1679 | // Really hope that nobody puts any thing malicious in a save state... |
| 1680 | const int result = rc_client_deserialize_progress_sized(s_client, data.data(), data.size()); |
| 1681 | if (result != RC_OK) |
| 1682 | { |
| 1683 | Console.Warning("Failed to deserialize cheevos state (%d), resetting", result); |
| 1684 | rc_client_reset(s_client); |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | void Achievements::SaveState(SaveStateBase& writer) |
| 1689 | { |
nothing calls this directly
no test coverage detected