Achievements: Switch to rc_client
This commit is contained in:
@ -3,105 +3,44 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "settings.h"
|
||||
#include "types.h"
|
||||
|
||||
#include "common/string.h"
|
||||
#include "common/types.h"
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class Error;
|
||||
class StateWrapper;
|
||||
class CDImage;
|
||||
|
||||
struct Settings;
|
||||
|
||||
namespace Achievements {
|
||||
|
||||
#ifdef WITH_CHEEVOS
|
||||
|
||||
enum class AchievementCategory : u8
|
||||
enum class LoginRequestReason
|
||||
{
|
||||
Local = 0,
|
||||
Core = 3,
|
||||
Unofficial = 5
|
||||
UserInitiated,
|
||||
TokenInvalid,
|
||||
};
|
||||
|
||||
struct Achievement
|
||||
{
|
||||
u32 id;
|
||||
std::string title;
|
||||
std::string description;
|
||||
std::string memaddr;
|
||||
std::string badge_name;
|
||||
|
||||
// badge paths are mutable because they're resolved when they're needed.
|
||||
mutable std::string locked_badge_path;
|
||||
mutable std::string unlocked_badge_path;
|
||||
|
||||
u32 points;
|
||||
AchievementCategory category;
|
||||
bool locked;
|
||||
bool active;
|
||||
bool primed;
|
||||
};
|
||||
|
||||
struct Leaderboard
|
||||
{
|
||||
u32 id;
|
||||
std::string title;
|
||||
std::string description;
|
||||
int format;
|
||||
};
|
||||
|
||||
struct LeaderboardEntry
|
||||
{
|
||||
std::string user;
|
||||
std::string formatted_score;
|
||||
time_t submitted;
|
||||
u32 rank;
|
||||
bool is_self;
|
||||
};
|
||||
|
||||
// RAIntegration only exists for Windows, so no point checking it on other platforms.
|
||||
#ifdef WITH_RAINTEGRATION
|
||||
|
||||
bool IsUsingRAIntegration();
|
||||
|
||||
#else
|
||||
|
||||
static ALWAYS_INLINE bool IsUsingRAIntegration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool IsActive();
|
||||
bool IsLoggedIn();
|
||||
bool ChallengeModeActive();
|
||||
bool LeaderboardsActive();
|
||||
bool IsTestModeActive();
|
||||
bool IsUnofficialTestModeActive();
|
||||
bool IsRichPresenceEnabled();
|
||||
bool HasActiveGame();
|
||||
|
||||
u32 GetGameID();
|
||||
|
||||
/// Acquires the achievements lock. Must be held when accessing any achievement state from another thread.
|
||||
std::unique_lock<std::recursive_mutex> GetLock();
|
||||
|
||||
void Initialize();
|
||||
/// Initializes the RetroAchievments client.
|
||||
bool Initialize();
|
||||
|
||||
/// Updates achievements settings.
|
||||
void UpdateSettings(const Settings& old_config);
|
||||
void ResetRuntime();
|
||||
|
||||
/// Resets the internal state of all achievement tracking. Call on system reset.
|
||||
void ResetClient();
|
||||
|
||||
/// Called when the system is being reset. If it returns false, the reset should be aborted.
|
||||
bool ConfirmSystemReset();
|
||||
|
||||
/// Called when the system is being shut down. If Shutdown() returns false, the shutdown should be aborted.
|
||||
bool Shutdown();
|
||||
bool Shutdown(bool allow_cancel);
|
||||
|
||||
/// Called when the system is being paused and resumed.
|
||||
void OnSystemPaused(bool paused);
|
||||
@ -110,60 +49,86 @@ void OnSystemPaused(bool paused);
|
||||
void FrameUpdate();
|
||||
|
||||
/// Called when the system is paused, because FrameUpdate() won't be getting called.
|
||||
void ProcessPendingHTTPRequests();
|
||||
void IdleUpdate();
|
||||
|
||||
/// Saves/loads state.
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
||||
/// Returns true if the current game has any achievements or leaderboards.
|
||||
/// Does not need to have the lock held.
|
||||
bool SafeHasAchievementsOrLeaderboards();
|
||||
/// Attempts to log in to RetroAchievements using the specified credentials.
|
||||
/// If the login is successful, the token returned by the server will be saved.
|
||||
bool Login(const char* username, const char* password, Error* error);
|
||||
|
||||
const std::string& GetUsername();
|
||||
const std::string& GetRichPresenceString();
|
||||
|
||||
bool LoginAsync(const char* username, const char* password);
|
||||
bool Login(const char* username, const char* password);
|
||||
/// Logs out of RetroAchievements, clearing any credentials.
|
||||
void Logout();
|
||||
|
||||
/// Called when the system changes game, or is booting.
|
||||
void GameChanged(const std::string& path, CDImage* image);
|
||||
|
||||
/// Re-enables hardcode mode if it is enabled in the settings.
|
||||
bool ResetChallengeMode();
|
||||
bool ResetHardcoreMode();
|
||||
|
||||
/// Forces hardcore mode off until next reset.
|
||||
void DisableChallengeMode();
|
||||
void DisableHardcoreMode();
|
||||
|
||||
/// Prompts the user to disable hardcore mode, if they agree, returns true.
|
||||
bool ConfirmChallengeModeDisable(const char* trigger);
|
||||
bool ConfirmHardcoreModeDisable(const char* trigger);
|
||||
|
||||
/// Returns true if features such as save states should be disabled.
|
||||
bool ChallengeModeActive();
|
||||
/// Returns true if hardcore mode is active, and functionality should be restricted.
|
||||
bool IsHardcoreModeActive();
|
||||
|
||||
/// RAIntegration only exists for Windows, so no point checking it on other platforms.
|
||||
bool IsUsingRAIntegration();
|
||||
|
||||
/// Returns true if the achievement system is active. Achievements can be active without a valid client.
|
||||
bool IsActive();
|
||||
|
||||
/// Returns true if RetroAchievements game data has been loaded.
|
||||
bool HasActiveGame();
|
||||
|
||||
/// Returns the RetroAchievements ID for the current game.
|
||||
u32 GetGameID();
|
||||
|
||||
/// Returns true if the current game has any achievements or leaderboards.
|
||||
bool HasAchievementsOrLeaderboards();
|
||||
|
||||
/// Returns true if the current game has any leaderboards.
|
||||
bool HasLeaderboards();
|
||||
|
||||
/// Returns true if the game supports rich presence.
|
||||
bool HasRichPresence();
|
||||
|
||||
/// Returns the current rich presence string.
|
||||
/// Should be called with the lock held.
|
||||
const std::string& GetRichPresenceString();
|
||||
|
||||
/// Returns the RetroAchievements title for the current game.
|
||||
/// Should be called with the lock held.
|
||||
const std::string& GetGameTitle();
|
||||
const std::string& GetGameIcon();
|
||||
|
||||
bool EnumerateAchievements(std::function<bool(const Achievement&)> callback);
|
||||
u32 GetUnlockedAchiementCount();
|
||||
u32 GetAchievementCount();
|
||||
u32 GetMaximumPointsForGame();
|
||||
u32 GetCurrentPointsForGame();
|
||||
/// Clears all cached state used to render the UI.
|
||||
void ClearUIState();
|
||||
|
||||
bool EnumerateLeaderboards(std::function<bool(const Leaderboard&)> callback);
|
||||
std::optional<bool> TryEnumerateLeaderboardEntries(u32 id, std::function<bool(const LeaderboardEntry&)> callback);
|
||||
const Leaderboard* GetLeaderboardByID(u32 id);
|
||||
u32 GetLeaderboardCount();
|
||||
bool IsLeaderboardTimeType(const Leaderboard& leaderboard);
|
||||
u32 GetPrimedAchievementCount();
|
||||
/// Draws ImGui overlays when not paused.
|
||||
void DrawGameOverlays();
|
||||
|
||||
const Achievement* GetAchievementByID(u32 id);
|
||||
std::pair<u32, u32> GetAchievementProgress(const Achievement& achievement);
|
||||
TinyString GetAchievementProgressText(const Achievement& achievement);
|
||||
const std::string& GetAchievementBadgePath(const Achievement& achievement, bool download_if_missing = true,
|
||||
bool force_unlocked_icon = false);
|
||||
std::string GetAchievementBadgeURL(const Achievement& achievement);
|
||||
/// Draws ImGui overlays when paused.
|
||||
void DrawPauseMenuOverlays();
|
||||
|
||||
/// Queries the achievement list, and if no achievements are available, returns false.
|
||||
bool PrepareAchievementsWindow();
|
||||
|
||||
/// Renders the achievement list.
|
||||
void DrawAchievementsWindow();
|
||||
|
||||
/// Queries the leaderboard list, and if no leaderboards are available, returns false.
|
||||
bool PrepareLeaderboardsWindow();
|
||||
|
||||
/// Renders the leaderboard list.
|
||||
void DrawLeaderboardsWindow();
|
||||
|
||||
#ifdef WITH_RAINTEGRATION
|
||||
/// Prevents the internal implementation from being used. Instead, RAIntegration will be
|
||||
/// called into when achievement-related events occur.
|
||||
void SwitchToRAIntegration();
|
||||
|
||||
namespace RAIntegration {
|
||||
@ -173,46 +138,20 @@ std::vector<std::tuple<int, std::string, bool>> GetMenuItems();
|
||||
void ActivateMenuItem(int item);
|
||||
} // namespace RAIntegration
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// Make noops when compiling without cheevos.
|
||||
static inline bool ConfirmSystemReset()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
static inline void ResetRuntime()
|
||||
{
|
||||
}
|
||||
static inline bool DoState(StateWrapper& sw)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
static constexpr inline bool ChallengeModeActive()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool ResetChallengeMode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void DisableChallengeMode()
|
||||
{
|
||||
}
|
||||
|
||||
static inline bool ConfirmChallengeModeDisable(const char* trigger)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace Achievements
|
||||
|
||||
/// Functions implemented in the frontend.
|
||||
namespace Host {
|
||||
/// Called if the big picture UI requests achievements login, or token login fails.
|
||||
void OnAchievementsLoginRequested(Achievements::LoginRequestReason reason);
|
||||
|
||||
/// Called when achievements login completes.
|
||||
void OnAchievementsLoginSuccess(const char* display_name, u32 points, u32 sc_points, u32 unread_messages);
|
||||
|
||||
/// Called whenever game details or rich presence information is updated.
|
||||
/// Implementers can assume the lock is held when this is called.
|
||||
void OnAchievementsRefreshed();
|
||||
void OnAchievementsChallengeModeChanged();
|
||||
|
||||
/// Called whenever hardcore mode is toggled.
|
||||
void OnAchievementsHardcoreModeChanged();
|
||||
} // namespace Host
|
||||
|
||||
Reference in New Issue
Block a user