Add achievement support for Wii and WiiWare

Add a method to detect console ID from an input file and instruct rcheevos to load as Gamecube or Wii accordingly. Also, hash .wads upon loading, to support achievements on WiiWare titles.
This commit is contained in:
LillyJadeKatrin
2025-04-18 07:59:47 -04:00
parent c796691d00
commit 1633011d2a
3 changed files with 26 additions and 9 deletions

View File

@ -11,7 +11,6 @@
#include <fmt/format.h>
#include <rcheevos/include/rc_api_info.h>
#include <rcheevos/include/rc_hash.h>
#include "Common/Assert.h"
#include "Common/BitUtils.h"
@ -192,12 +191,9 @@ void AchievementManager::LoadGame(const DiscIO::Volume* volume)
else
m_title_estimate = "";
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
if (volume)
if (!m_loading_volume)
{
if (!m_loading_volume)
{
m_loading_volume = DiscIO::CreateVolume(volume->GetBlobReader().CopyReader());
}
m_loading_volume = DiscIO::CreateVolume(volume->GetBlobReader().CopyReader());
}
}
std::lock_guard lg{m_filereader_lock};
@ -215,9 +211,10 @@ void AchievementManager::LoadGame(const DiscIO::Volume* volume)
}
else
{
u32 console_id = FindConsoleID(volume->GetVolumeType());
rc_client_set_read_memory_function(m_client, MemoryVerifier);
rc_client_begin_identify_and_load_game(m_client, RC_CONSOLE_GAMECUBE, "", NULL,
0, LoadGameCallback, NULL);
rc_client_begin_identify_and_load_game(m_client, console_id, "", NULL, 0, LoadGameCallback,
NULL);
}
}
@ -251,7 +248,8 @@ std::string AchievementManager::CalculateHash(const std::string& file_path)
.close = &AchievementManager::FilereaderClose,
};
rc_hash_init_custom_filereader(&volume_reader);
rc_hash_generate_from_file(hash_result, RC_CONSOLE_GAMECUBE, file_path.c_str());
u32 console_id = FindConsoleID(GetInstance().m_loading_volume->GetVolumeType());
rc_hash_generate_from_file(hash_result, console_id, file_path.c_str());
return std::string(hash_result);
}
@ -835,6 +833,20 @@ void AchievementManager::FilereaderClose(void* file_handle)
delete static_cast<FilereaderState*>(file_handle);
}
u32 AchievementManager::FindConsoleID(const DiscIO::Platform& platform)
{
switch (platform)
{
case DiscIO::Platform::GameCubeDisc:
return RC_CONSOLE_GAMECUBE;
case DiscIO::Platform::WiiDisc:
case DiscIO::Platform::WiiWAD:
return RC_CONSOLE_WII;
default:
return RC_CONSOLE_UNKNOWN;
}
}
void AchievementManager::LoadDefaultBadges()
{
std::lock_guard lg{m_lock};

View File

@ -23,6 +23,7 @@
#include <rcheevos/include/rc_api_runtime.h>
#include <rcheevos/include/rc_api_user.h>
#include <rcheevos/include/rc_client.h>
#include <rcheevos/include/rc_hash.h>
#include <rcheevos/include/rc_runtime.h>
#include "Common/CommonTypes.h"
@ -199,6 +200,8 @@ private:
static size_t FilereaderRead(void* file_handle, void* buffer, size_t requested_bytes);
static void FilereaderClose(void* file_handle);
static u32 FindConsoleID(const DiscIO::Platform& platform);
void LoadDefaultBadges();
static void LoginCallback(int result, const char* error_message, rc_client_t* client,
void* userdata);

View File

@ -623,6 +623,8 @@ bool CBoot::BootUp(Core::System& system, const Core::CPUThreadGuard& guard,
if (!Boot_WiiWAD(system, wad))
return false;
AchievementManager::GetInstance().LoadGame(&wad);
SConfig::OnTitleDirectlyBooted(guard);
return true;
}