Implement RetroAchivements

This commit is contained in:
Connor McLaughlin
2021-02-27 00:44:53 +10:00
parent ef524d7dea
commit 0ec2c87a0e
34 changed files with 2419 additions and 65 deletions

View File

@ -43,6 +43,10 @@
#include "discord_rpc.h"
#endif
#ifdef WITH_CHEEVOS
#include "cheevos.h"
#endif
#ifdef WIN32
#include "common/windows_headers.h"
#include <KnownFolders.h>
@ -89,6 +93,10 @@ bool CommonHostInterface::Initialize()
CreateImGuiContext();
#ifdef WITH_CHEEVOS
UpdateCheevosActive();
#endif
return true;
}
@ -102,6 +110,10 @@ void CommonHostInterface::Shutdown()
ShutdownDiscordPresence();
#endif
#ifdef WITH_CHEEVOS
Cheevos::Shutdown();
#endif
if (m_controller_interface)
{
m_controller_interface->Shutdown();
@ -127,11 +139,17 @@ void CommonHostInterface::InitializeUserDirectory()
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("bios").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cache").c_str(), false);
result &= FileSystem::CreateDirectory(
GetUserDirectoryRelativePath("cache" FS_OSPATH_SEPARATOR_STR "achievement_badge").c_str(), false);
result &= FileSystem::CreateDirectory(
GetUserDirectoryRelativePath("cache" FS_OSPATH_SEPARATOR_STR "achievement_gameicon").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("cheats").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("covers").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump/audio").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump/textures").c_str(), false);
result &=
FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump" FS_OSPATH_SEPARATOR_STR "audio").c_str(), false);
result &=
FileSystem::CreateDirectory(GetUserDirectoryRelativePath("dump" FS_OSPATH_SEPARATOR_STR "textures").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("inputprofiles").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("memcards").c_str(), false);
result &= FileSystem::CreateDirectory(GetUserDirectoryRelativePath("savestates").c_str(), false);
@ -192,6 +210,15 @@ void CommonHostInterface::PowerOffSystem()
RequestExit();
}
void CommonHostInterface::ResetSystem()
{
HostInterface::ResetSystem();
#ifdef WITH_CHEEVOS
Cheevos::Reset();
#endif
}
static void PrintCommandLineVersion(const char* frontend_name)
{
const bool was_console_enabled = Log::IsConsoleOutputEnabled();
@ -434,11 +461,23 @@ bool CommonHostInterface::ParseCommandLineParameters(int argc, char* argv[],
return true;
}
void CommonHostInterface::OnAchievementsRefreshed()
{
#ifdef WITH_CHEEVOS
// noop
#endif
}
void CommonHostInterface::PollAndUpdate()
{
#ifdef WITH_DISCORD_PRESENCE
PollDiscordPresence();
#endif
#ifdef WITH_CHEEVOS
if (Cheevos::IsActive())
Cheevos::Update();
#endif
}
bool CommonHostInterface::IsFullscreen() const
@ -612,6 +651,20 @@ void CommonHostInterface::UpdateControllerInterface()
}
}
bool CommonHostInterface::LoadState(const char* filename)
{
const bool system_was_valid = System::IsValid();
const bool result = HostInterface::LoadState(filename);
if (system_was_valid || !result)
{
#ifdef WITH_CHEEVOS
Cheevos::Reset();
#endif
}
return result;
}
bool CommonHostInterface::LoadState(bool global, s32 slot)
{
if (!global && (System::IsShutdown() || System::GetRunningCode().empty()))
@ -924,6 +977,11 @@ void CommonHostInterface::OnRunningGameChanged(const std::string& path, CDImage*
#ifdef WITH_DISCORD_PRESENCE
UpdateDiscordPresence();
#endif
#ifdef WITH_CHEEVOS
if (Cheevos::IsLoggedIn())
Cheevos::GameChanged(path, image);
#endif
}
void CommonHostInterface::OnControllerTypeChanged(u32 slot)
@ -2448,6 +2506,14 @@ void CommonHostInterface::SetDefaultSettings(SettingsInterface& si)
#ifdef WITH_DISCORD_PRESENCE
si.SetBoolValue("Main", "EnableDiscordPresence", false);
#endif
#ifdef WITH_CHEEVOS
si.SetBoolValue("Cheevos", "Enabled", false);
si.SetBoolValue("Cheevos", "TestMode", false);
si.SetBoolValue("Cheevos", "UseFirstDiscFromPlaylist", true);
si.DeleteValue("Cheevos", "Username");
si.DeleteValue("Cheevos", "Token");
#endif
}
void CommonHostInterface::LoadSettings()
@ -2482,8 +2548,15 @@ void CommonHostInterface::LoadSettings(SettingsInterface& si)
SetDiscordPresenceEnabled(si.GetBoolValue("Main", "EnableDiscordPresence", false));
#endif
#ifdef WITH_CHEEVOS
UpdateCheevosActive();
const bool cheevos_active = Cheevos::IsActive();
#else
const bool cheevos_active = false;
#endif
const bool fullscreen_ui_enabled =
si.GetBoolValue("Main", "EnableFullscreenUI", false) || m_flags.force_fullscreen_ui;
si.GetBoolValue("Main", "EnableFullscreenUI", false) || cheevos_active || m_flags.force_fullscreen_ui;
if (fullscreen_ui_enabled != m_fullscreen_ui_enabled)
{
m_fullscreen_ui_enabled = fullscreen_ui_enabled;
@ -3211,3 +3284,27 @@ void CommonHostInterface::PollDiscordPresence()
}
#endif
#ifdef WITH_CHEEVOS
void CommonHostInterface::UpdateCheevosActive()
{
const bool cheevos_enabled = GetBoolSettingValue("Cheevos", "Enabled", false);
const bool cheevos_test_mode = GetBoolSettingValue("Cheevos", "TestMode", false);
const bool cheevos_use_first_disc_from_playlist = GetBoolSettingValue("Cheevos", "UseFirstDiscFromPlaylist", true);
const bool cheevos_rich_presence = GetBoolSettingValue("Cheevos", "RichPresence", true);
if (cheevos_enabled != Cheevos::IsActive() || cheevos_test_mode != Cheevos::IsTestModeActive() ||
cheevos_use_first_disc_from_playlist != Cheevos::IsUsingFirstDiscFromPlaylist() ||
cheevos_rich_presence != Cheevos::IsRichPresenceEnabled())
{
Cheevos::Shutdown();
if (cheevos_enabled)
{
if (!Cheevos::Initialize(this, cheevos_test_mode, cheevos_use_first_disc_from_playlist, cheevos_rich_presence))
ReportError("Failed to initialize cheevos after settings change.");
}
}
}
#endif