Add DoState to AchievementManager
While state loading is not allowed in the hardcore mode that most players will use, it is allowed in softcore mode; more importantly, if something fails to unlock or unlocks when it shouldn't in either mode the player can create a save that retains the current achievement state.
This commit is contained in:
parent
70116b222d
commit
0627209131
|
@ -396,6 +396,46 @@ std::vector<std::string> AchievementManager::GetActiveLeaderboards() const
|
||||||
return display_values;
|
return display_values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AchievementManager::DoState(PointerWrap& p)
|
||||||
|
{
|
||||||
|
if (!m_client || !Config::Get(Config::RA_ENABLED))
|
||||||
|
return;
|
||||||
|
size_t size = 0;
|
||||||
|
if (!p.IsReadMode())
|
||||||
|
size = rc_client_progress_size(m_client);
|
||||||
|
p.Do(size);
|
||||||
|
auto buffer = std::make_unique<u8[]>(size);
|
||||||
|
if (!p.IsReadMode())
|
||||||
|
{
|
||||||
|
int result = rc_client_serialize_progress_sized(m_client, buffer.get(), size);
|
||||||
|
if (result != RC_OK)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(ACHIEVEMENTS, "Failed serializing achievement client with error code {}",
|
||||||
|
result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.DoArray(buffer.get(), (u32)size);
|
||||||
|
if (p.IsReadMode())
|
||||||
|
{
|
||||||
|
int result = rc_client_deserialize_progress_sized(m_client, buffer.get(), size);
|
||||||
|
if (result != RC_OK)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(ACHIEVEMENTS, "Failed deserializing achievement client with error code {}",
|
||||||
|
result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t new_size = rc_client_progress_size(m_client);
|
||||||
|
if (size != new_size)
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(ACHIEVEMENTS, "Loaded client size {} does not match size in state {}", new_size,
|
||||||
|
size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.DoMarker("AchievementManager");
|
||||||
|
}
|
||||||
|
|
||||||
void AchievementManager::CloseGame()
|
void AchievementManager::CloseGame()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
|
@ -148,6 +148,8 @@ public:
|
||||||
const NamedIconMap& GetChallengeIcons() const;
|
const NamedIconMap& GetChallengeIcons() const;
|
||||||
std::vector<std::string> GetActiveLeaderboards() const;
|
std::vector<std::string> GetActiveLeaderboards() const;
|
||||||
|
|
||||||
|
void DoState(PointerWrap& p);
|
||||||
|
|
||||||
void CloseGame();
|
void CloseGame();
|
||||||
void Logout();
|
void Logout();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
|
@ -98,7 +98,7 @@ static size_t s_state_writes_in_queue;
|
||||||
static std::condition_variable s_state_write_queue_is_empty;
|
static std::condition_variable s_state_write_queue_is_empty;
|
||||||
|
|
||||||
// Don't forget to increase this after doing changes on the savestate system
|
// Don't forget to increase this after doing changes on the savestate system
|
||||||
constexpr u32 STATE_VERSION = 167; // Last changed in PR 12494
|
constexpr u32 STATE_VERSION = 168; // Last changed in PR 12639
|
||||||
|
|
||||||
// Increase this if the StateExtendedHeader definition changes
|
// Increase this if the StateExtendedHeader definition changes
|
||||||
constexpr u32 EXTENDED_HEADER_VERSION = 1; // Last changed in PR 12217
|
constexpr u32 EXTENDED_HEADER_VERSION = 1; // Last changed in PR 12217
|
||||||
|
@ -198,6 +198,10 @@ static void DoState(Core::System& system, PointerWrap& p)
|
||||||
p.DoMarker("Wiimote");
|
p.DoMarker("Wiimote");
|
||||||
Gecko::DoState(p);
|
Gecko::DoState(p);
|
||||||
p.DoMarker("Gecko");
|
p.DoMarker("Gecko");
|
||||||
|
|
||||||
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||||
|
AchievementManager::GetInstance().DoState(p);
|
||||||
|
#endif // USE_RETRO_ACHIEVEMENTS
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadFromBuffer(Core::System& system, std::vector<u8>& buffer)
|
void LoadFromBuffer(Core::System& system, std::vector<u8>& buffer)
|
||||||
|
|
Loading…
Reference in New Issue