Skip to content

Commit

Permalink
Refactored AchievementManager LoadGameAsync to take a volume.
Browse files Browse the repository at this point in the history
This change also moves the Load Game call out of BootManager and into DVDInterface::SetDisc to be called whenever the set disc changes.
  • Loading branch information
LillyJadeKatrin committed Oct 1, 2023
1 parent cd366c4 commit a4c812c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
16 changes: 12 additions & 4 deletions Source/Core/Core/AchievementManager.cpp
Expand Up @@ -16,7 +16,7 @@
#include "Core/Core.h"
#include "Core/PowerPC/MMU.h"
#include "Core/System.h"
#include "DiscIO/Volume.h"
#include "DiscIO/Blob.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoEvents.h"

Expand Down Expand Up @@ -85,7 +85,7 @@ bool AchievementManager::IsLoggedIn() const
return !Config::Get(Config::RA_API_TOKEN).empty();
}

void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
void AchievementManager::LoadGameAsync(const DiscIO::Volume* volume,
const ResponseCallback& callback)
{
if (!m_is_runtime_initialized)
Expand All @@ -96,6 +96,7 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
return;
}
m_system = &Core::System::GetInstance();
m_loading_volume = volume;
struct FilereaderState
{
int64_t position = 0;
Expand All @@ -104,7 +105,8 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
rc_hash_filereader volume_reader{
.open = [](const char* path_utf8) -> void* {
auto state = std::make_unique<FilereaderState>();
state->volume = DiscIO::CreateVolume(path_utf8);
state->volume = DiscIO::CreateVolume(
AchievementManager::GetInstance()->GetLoadingVolume()->GetBlobReader().CopyReader());
if (!state->volume)
return nullptr;
return state.release();
Expand Down Expand Up @@ -146,11 +148,12 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
},
.close = [](void* file_handle) { delete reinterpret_cast<FilereaderState*>(file_handle); }};
rc_hash_init_custom_filereader(&volume_reader);
if (!rc_hash_generate_from_file(m_game_hash.data(), RC_CONSOLE_GAMECUBE, iso_path.c_str()))
if (!rc_hash_generate_from_file(m_game_hash.data(), RC_CONSOLE_GAMECUBE, ""))
{
ERROR_LOG_FMT(ACHIEVEMENTS, "Unable to generate achievement hash from game file.");
return;
}
m_loading_volume = nullptr;
m_queue.EmplaceItem([this, callback] {
const auto resolve_hash_response = ResolveHash(this->m_game_hash);
if (resolve_hash_response != ResponseType::SUCCESS || m_game_id == 0)
Expand Down Expand Up @@ -952,6 +955,11 @@ AchievementManager::ResponseType AchievementManager::FetchUnlockData(bool hardco
return r_type;
}

const DiscIO::Volume* AchievementManager::GetLoadingVolume()
{
return m_loading_volume;
}

void AchievementManager::ActivateDeactivateAchievement(AchievementId id, bool enabled,
bool unofficial, bool encore)
{
Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Core/AchievementManager.h
Expand Up @@ -18,6 +18,7 @@

#include "Common/Event.h"
#include "Common/WorkQueueThread.h"
#include "DiscIO/Volume.h"

namespace Core
{
Expand Down Expand Up @@ -89,7 +90,7 @@ class AchievementManager
ResponseType Login(const std::string& password);
void LoginAsync(const std::string& password, const ResponseCallback& callback);
bool IsLoggedIn() const;
void LoadGameByFilenameAsync(const std::string& iso_path, const ResponseCallback& callback);
void LoadGameAsync(const DiscIO::Volume* volume, const ResponseCallback& callback);
bool IsGameLoaded() const;

void LoadUnlockData(const ResponseCallback& callback);
Expand Down Expand Up @@ -130,6 +131,8 @@ class AchievementManager
ResponseType FetchGameData();
ResponseType FetchUnlockData(bool hardcore);

const DiscIO::Volume* GetLoadingVolume();

void ActivateDeactivateAchievement(AchievementId id, bool enabled, bool unofficial, bool encore);
void GenerateRichPresence();

Expand All @@ -152,6 +155,7 @@ class AchievementManager
Core::System* m_system{};
bool m_is_runtime_initialized = false;
UpdateCallback m_update_callback;
const DiscIO::Volume* m_loading_volume;
std::string m_display_name;
u32 m_player_score = 0;
BadgeStatus m_player_badge;
Expand Down
10 changes: 0 additions & 10 deletions Source/Core/Core/BootManager.cpp
Expand Up @@ -164,16 +164,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
}
}

#ifdef USE_RETRO_ACHIEVEMENTS
std::string path = "";
if (std::holds_alternative<BootParameters::Disc>(boot->parameters))
{
path = std::get<BootParameters::Disc>(boot->parameters).path;
}
AchievementManager::GetInstance()->LoadGameByFilenameAsync(
path, [](AchievementManager::ResponseType r_type) {});
#endif // USE_RETRO_ACHIEVEMENTS

const bool load_ipl = !StartUp.bWii && !Config::Get(Config::MAIN_SKIP_IPL) &&
std::holds_alternative<BootParameters::Disc>(boot->parameters);
if (load_ipl)
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/HW/DVD/DVDInterface.cpp
Expand Up @@ -20,6 +20,7 @@
#include "Common/Config/Config.h"
#include "Common/Logging/Log.h"

#include "Core/AchievementManager.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/SessionSettings.h"
#include "Core/CoreTiming.h"
Expand Down Expand Up @@ -396,6 +397,11 @@ void DVDInterface::SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
m_auto_disc_change_index = 0;
}

#ifdef USE_RETRO_ACHIEVEMENTS
AchievementManager::GetInstance()->LoadGameAsync(disc.get(),
[](AchievementManager::ResponseType r_type) {});
#endif // USE_RETRO_ACHIEVEMENTS

// Assume that inserting a disc requires having an empty disc before
if (had_disc != has_disc)
ExpansionInterface::g_rtc_flags[ExpansionInterface::RTCFlag::DiscChanged] = true;
Expand Down

0 comments on commit a4c812c

Please sign in to comment.