Skip to content

Commit

Permalink
Achievements: Fix progress database corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Feb 21, 2025
1 parent 90cb92b commit fa3815d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/core/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4208,7 +4208,7 @@ void Achievements::UpdateProgressDatabase(bool force)
return;

// update the game list, this should be fairly quick
if (!s_state.game_hash.has_value())
if (s_state.game_hash.has_value())
{
GameList::UpdateAchievementData(s_state.game_hash.value(), s_state.game_id,
s_state.game_summary.num_core_achievements,
Expand Down Expand Up @@ -4302,19 +4302,19 @@ void Achievements::UpdateProgressDatabase(bool force)
{
// if the file is empty, need to write the header
writer.WriteU32(1);
writer.WriteU32(game_id);
}
else
{
// update the count
if (!FileSystem::FSeek64(fp.get(), 0, SEEK_SET, &error) || !writer.WriteU32(game_count + 1) ||
!FileSystem::FSeek64(fp.get(), SEEK_END, 0, &error))
!FileSystem::FSeek64(fp.get(), 0, SEEK_END, &error))
{
ERROR_LOG("Failed to write seek/update header in progress database: {}", error.GetDescription());
return;
}
}

writer.WriteU32(game_id);
writer.WriteU16(Truncate16(hardcore ? 0 : achievements_unlocked));
writer.WriteU16(Truncate16(hardcore ? achievements_unlocked : 0));
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/game_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void GameList::UpdateAchievementData(const std::span<u8, 16> hash, u32 game_id,
entry.achievements_game_id = game_id;
entry.num_achievements = Truncate16(num_achievements);
if (hardcore)
entry.unlocked_achievements_hc = Truncate16(num_achievements);
entry.unlocked_achievements_hc = Truncate16(num_unlocked);
else
entry.unlocked_achievements = Truncate16(num_unlocked);

Expand Down

0 comments on commit fa3815d

Please sign in to comment.