2023-08-23 12:06:48 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
#pragma once
|
2023-08-23 12:06:48 +00:00
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "common/string.h"
|
2022-07-11 13:03:29 +00:00
|
|
|
#include "common/types.h"
|
|
|
|
|
2023-08-23 12:06:48 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <optional>
|
2023-08-13 06:28:28 +00:00
|
|
|
#include <string>
|
2023-08-23 12:06:48 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2023-08-13 06:28:28 +00:00
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
class StateWrapper;
|
|
|
|
class CDImage;
|
|
|
|
|
|
|
|
namespace Achievements {
|
|
|
|
|
|
|
|
#ifdef WITH_CHEEVOS
|
|
|
|
|
2023-08-23 12:06:48 +00:00
|
|
|
enum class AchievementCategory : u8
|
|
|
|
{
|
|
|
|
Local = 0,
|
|
|
|
Core = 3,
|
|
|
|
Unofficial = 5
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
void UpdateSettings(const Settings& old_config);
|
|
|
|
void ResetRuntime();
|
|
|
|
|
|
|
|
/// 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();
|
|
|
|
|
|
|
|
/// Called when the system is being paused and resumed.
|
|
|
|
void OnSystemPaused(bool paused);
|
|
|
|
|
|
|
|
/// Called once a frame at vsync time on the CPU thread.
|
|
|
|
void FrameUpdate();
|
|
|
|
|
|
|
|
/// Called when the system is paused, because FrameUpdate() won't be getting called.
|
|
|
|
void ProcessPendingHTTPRequests();
|
|
|
|
|
|
|
|
/// 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();
|
|
|
|
|
|
|
|
const std::string& GetUsername();
|
|
|
|
const std::string& GetRichPresenceString();
|
|
|
|
|
|
|
|
bool LoginAsync(const char* username, const char* password);
|
|
|
|
bool Login(const char* username, const char* password);
|
|
|
|
void Logout();
|
|
|
|
|
|
|
|
void GameChanged(const std::string& path, CDImage* image);
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
/// Re-enables hardcode mode if it is enabled in the settings.
|
2023-08-23 12:06:48 +00:00
|
|
|
bool ResetChallengeMode();
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
/// Forces hardcore mode off until next reset.
|
2023-08-23 12:06:48 +00:00
|
|
|
void DisableChallengeMode();
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
/// Prompts the user to disable hardcore mode, if they agree, returns true.
|
2023-08-23 12:06:48 +00:00
|
|
|
bool ConfirmChallengeModeDisable(const char* trigger);
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
/// Returns true if features such as save states should be disabled.
|
2023-08-23 12:06:48 +00:00
|
|
|
bool ChallengeModeActive();
|
|
|
|
|
|
|
|
const std::string& GetGameTitle();
|
|
|
|
const std::string& GetGameIcon();
|
|
|
|
|
|
|
|
bool EnumerateAchievements(std::function<bool(const Achievement&)> callback);
|
|
|
|
u32 GetUnlockedAchiementCount();
|
|
|
|
u32 GetAchievementCount();
|
|
|
|
u32 GetMaximumPointsForGame();
|
|
|
|
u32 GetCurrentPointsForGame();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
#ifdef WITH_RAINTEGRATION
|
|
|
|
void SwitchToRAIntegration();
|
|
|
|
|
|
|
|
namespace RAIntegration {
|
|
|
|
void MainWindowChanged(void* new_handle);
|
|
|
|
void GameChanged();
|
|
|
|
std::vector<std::tuple<int, std::string, bool>> GetMenuItems();
|
|
|
|
void ActivateMenuItem(int item);
|
|
|
|
} // namespace RAIntegration
|
|
|
|
#endif
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// Make noops when compiling without cheevos.
|
2022-09-21 12:02:54 +00:00
|
|
|
static inline bool ConfirmSystemReset()
|
2022-07-11 13:03:29 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-23 12:06:48 +00:00
|
|
|
static inline void ResetRuntime()
|
|
|
|
{
|
|
|
|
}
|
2022-07-11 13:03:29 +00:00
|
|
|
static inline bool DoState(StateWrapper& sw)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static constexpr inline bool ChallengeModeActive()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-08 10:59:18 +00:00
|
|
|
static inline bool ResetChallengeMode()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2022-07-11 13:03:29 +00:00
|
|
|
|
2023-08-23 12:06:48 +00:00
|
|
|
static inline void DisableChallengeMode()
|
|
|
|
{
|
|
|
|
}
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
static inline bool ConfirmChallengeModeDisable(const char* trigger)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace Achievements
|
2023-08-23 12:06:48 +00:00
|
|
|
|
|
|
|
/// Functions implemented in the frontend.
|
|
|
|
namespace Host {
|
|
|
|
void OnAchievementsRefreshed();
|
|
|
|
void OnAchievementsChallengeModeChanged();
|
|
|
|
} // namespace Host
|