Remove filename option from achievement manager load

The only option that was currently using this was a pass-by-executable that wouldn't hash correctly anyways.
This commit is contained in:
LillyJadeKatrin
2025-04-29 23:56:58 -04:00
parent 999c7aed98
commit c796691d00
4 changed files with 18 additions and 24 deletions

View File

@ -161,13 +161,13 @@ bool AchievementManager::HasAPIToken() const
return !Config::Get(Config::RA_API_TOKEN).empty(); return !Config::Get(Config::RA_API_TOKEN).empty();
} }
void AchievementManager::LoadGame(const std::string& file_path, const DiscIO::Volume* volume) void AchievementManager::LoadGame(const DiscIO::Volume* volume)
{ {
if (!Config::Get(Config::RA_ENABLED) || !HasAPIToken()) if (!Config::Get(Config::RA_ENABLED) || !HasAPIToken())
{ {
return; return;
} }
if (file_path.empty() && volume == nullptr) if (volume == nullptr)
{ {
WARN_LOG_FMT(ACHIEVEMENTS, "Called Load Game without a game."); WARN_LOG_FMT(ACHIEVEMENTS, "Called Load Game without a game.");
return; return;
@ -184,7 +184,13 @@ void AchievementManager::LoadGame(const std::string& file_path, const DiscIO::Vo
{ {
std::lock_guard lg{m_lock}; std::lock_guard lg{m_lock};
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION #ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
SplitPath(file_path, nullptr, &m_title_estimate, nullptr); const auto& names = volume->GetLongNames();
if (names.contains(DiscIO::Language::English))
m_title_estimate = names.at(DiscIO::Language::English);
else if (!names.empty())
m_title_estimate = names.begin()->second;
else
m_title_estimate = "";
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION #endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
if (volume) if (volume)
{ {
@ -196,8 +202,7 @@ void AchievementManager::LoadGame(const std::string& file_path, const DiscIO::Vo
} }
std::lock_guard lg{m_filereader_lock}; std::lock_guard lg{m_filereader_lock};
rc_hash_filereader volume_reader{ rc_hash_filereader volume_reader{
.open = (volume) ? &AchievementManager::FilereaderOpenByVolume : .open = &AchievementManager::FilereaderOpen,
&AchievementManager::FilereaderOpenByFilepath,
.seek = &AchievementManager::FilereaderSeek, .seek = &AchievementManager::FilereaderSeek,
.tell = &AchievementManager::FilereaderTell, .tell = &AchievementManager::FilereaderTell,
.read = &AchievementManager::FilereaderRead, .read = &AchievementManager::FilereaderRead,
@ -206,12 +211,12 @@ void AchievementManager::LoadGame(const std::string& file_path, const DiscIO::Vo
rc_hash_init_custom_filereader(&volume_reader); rc_hash_init_custom_filereader(&volume_reader);
if (rc_client_get_game_info(m_client)) if (rc_client_get_game_info(m_client))
{ {
rc_client_begin_change_media(m_client, file_path.c_str(), NULL, 0, ChangeMediaCallback, NULL); rc_client_begin_change_media(m_client, "", NULL, 0, ChangeMediaCallback, NULL);
} }
else else
{ {
rc_client_set_read_memory_function(m_client, MemoryVerifier); rc_client_set_read_memory_function(m_client, MemoryVerifier);
rc_client_begin_identify_and_load_game(m_client, RC_CONSOLE_GAMECUBE, file_path.c_str(), NULL, rc_client_begin_identify_and_load_game(m_client, RC_CONSOLE_GAMECUBE, "", NULL,
0, LoadGameCallback, NULL); 0, LoadGameCallback, NULL);
} }
} }
@ -237,8 +242,9 @@ void AchievementManager::SetBackgroundExecutionAllowed(bool allowed)
std::string AchievementManager::CalculateHash(const std::string& file_path) std::string AchievementManager::CalculateHash(const std::string& file_path)
{ {
char hash_result[33] = "0"; char hash_result[33] = "0";
GetInstance().m_loading_volume = std::move(DiscIO::CreateVolume(file_path));
rc_hash_filereader volume_reader{ rc_hash_filereader volume_reader{
.open = &AchievementManager::FilereaderOpenByFilepath, .open = &AchievementManager::FilereaderOpen,
.seek = &AchievementManager::FilereaderSeek, .seek = &AchievementManager::FilereaderSeek,
.tell = &AchievementManager::FilereaderTell, .tell = &AchievementManager::FilereaderTell,
.read = &AchievementManager::FilereaderRead, .read = &AchievementManager::FilereaderRead,
@ -774,16 +780,7 @@ void AchievementManager::Shutdown()
} }
} }
void* AchievementManager::FilereaderOpenByFilepath(const char* path_utf8) void* AchievementManager::FilereaderOpen(const char* path_utf8)
{
auto state = std::make_unique<FilereaderState>();
state->volume = DiscIO::CreateVolume(path_utf8);
if (!state->volume)
return nullptr;
return state.release();
}
void* AchievementManager::FilereaderOpenByVolume(const char* path_utf8)
{ {
auto state = std::make_unique<FilereaderState>(); auto state = std::make_unique<FilereaderState>();
{ {

View File

@ -122,7 +122,7 @@ public:
void SetUpdateCallback(UpdateCallback callback); void SetUpdateCallback(UpdateCallback callback);
void Login(const std::string& password); void Login(const std::string& password);
bool HasAPIToken() const; bool HasAPIToken() const;
void LoadGame(const std::string& file_path, const DiscIO::Volume* volume); void LoadGame(const DiscIO::Volume* volume);
bool IsGameLoaded() const; bool IsGameLoaded() const;
void SetBackgroundExecutionAllowed(bool allowed); void SetBackgroundExecutionAllowed(bool allowed);
@ -193,8 +193,7 @@ private:
static picojson::value LoadApprovedList(); static picojson::value LoadApprovedList();
static void* FilereaderOpenByFilepath(const char* path_utf8); static void* FilereaderOpen(const char* path_utf8);
static void* FilereaderOpenByVolume(const char* path_utf8);
static void FilereaderSeek(void* file_handle, int64_t offset, int origin); static void FilereaderSeek(void* file_handle, int64_t offset, int origin);
static int64_t FilereaderTell(void* file_handle); static int64_t FilereaderTell(void* file_handle);
static size_t FilereaderRead(void* file_handle, void* buffer, size_t requested_bytes); static size_t FilereaderRead(void* file_handle, void* buffer, size_t requested_bytes);

View File

@ -597,8 +597,6 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
SetupGCMemory(system, guard); SetupGCMemory(system, guard);
} }
AchievementManager::GetInstance().LoadGame(executable.path, nullptr);
if (!executable.reader->LoadIntoMemory(system)) if (!executable.reader->LoadIntoMemory(system))
{ {
PanicAlertFmtT("Failed to load the executable to memory."); PanicAlertFmtT("Failed to load the executable to memory.");

View File

@ -398,7 +398,7 @@ void DVDInterface::SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
m_auto_disc_change_index = 0; m_auto_disc_change_index = 0;
} }
AchievementManager::GetInstance().LoadGame("", disc.get()); AchievementManager::GetInstance().LoadGame(disc.get());
// Assume that inserting a disc requires having an empty disc before // Assume that inserting a disc requires having an empty disc before
if (had_disc != has_disc) if (had_disc != has_disc)