Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/PCSX2/pcsx2
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Aug 22, 2024
2 parents f94ddc5 + 83f9add commit fe65ddf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pcsx2/Achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ namespace Achievements
static std::string s_game_hash;
static std::string s_game_title;
static std::string s_game_icon;
static std::string s_game_icon_url;
static u32 s_game_crc;
static rc_client_user_game_summary_t s_game_summary;
static u32 s_game_id = 0;
Expand Down Expand Up @@ -401,6 +402,10 @@ const std::string& Achievements::GetRichPresenceString()
return s_rich_presence_string;
}

const std::string& Achievements::GetGameIconURL()
{
return s_game_icon_url;
}

bool Achievements::Initialize()
{
Expand Down Expand Up @@ -945,6 +950,7 @@ void Achievements::ClientLoadGameCallback(int result, const char* error_message,
s_has_leaderboards = has_leaderboards;
s_has_rich_presence = rc_client_has_rich_presence(client);
s_game_icon = {};
s_game_icon_url = {};

// ensure fullscreen UI is ready for notifications
MTGS::RunOnGSThread(&ImGuiManager::InitializeFullscreenUI);
Expand All @@ -966,6 +972,16 @@ void Achievements::ClientLoadGameCallback(int result, const char* error_message,
}
}

char icon_url[64];
if (int err = rc_client_game_get_image_url(info, icon_url, std::size(icon_url)); err == RC_OK)
{
s_game_icon_url = icon_url;
}
else
{
ReportRCError(err, "rc_client_game_get_image_url() failed: ");
}

UpdateGameSummary();
DisplayAchievementSummary();

Expand All @@ -990,6 +1006,7 @@ void Achievements::ClearGameInfo()
s_game_id = 0;
s_game_title = {};
s_game_icon = {};
s_game_icon_url = {};
s_has_achievements = false;
s_has_leaderboards = false;
s_has_rich_presence = false;
Expand Down
4 changes: 4 additions & 0 deletions pcsx2/Achievements.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ namespace Achievements
/// Should be called with the lock held.
const std::string& GetRichPresenceString();

/// Returns the current game icon url.
/// Should be called with the lock held.
const std::string& GetGameIconURL();

/// Returns the RetroAchievements title for the current game.
/// Should be called with the lock held.
const std::string& GetGameTitle();
Expand Down
11 changes: 10 additions & 1 deletion pcsx2/Pcsx2Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ namespace EmuFolders
std::string Videos;

static bool ShouldUsePortableMode();
static std::string GetPortableModePath();
} // namespace EmuFolders

TraceFiltersEE::TraceFiltersEE()
Expand Down Expand Up @@ -1912,6 +1913,14 @@ bool EmuFolders::ShouldUsePortableMode()
return FileSystem::FileExists(Path::Combine(AppRoot, "portable.ini").c_str()) || FileSystem::FileExists(Path::Combine(AppRoot, "portable.txt").c_str());
}

std::string EmuFolders::GetPortableModePath()
{
const auto portable_txt_path = Path::Combine(AppRoot, "portable.txt");
const auto portable_path = FileSystem::ReadFileToString(portable_txt_path.c_str()).value_or("");
const auto trimmed_path = StringUtil::StripWhitespace(portable_path);
return std::string(trimmed_path);
}

bool EmuFolders::SetDataDirectory(Error* error)
{
if (!ShouldUsePortableMode())
Expand Down Expand Up @@ -1956,7 +1965,7 @@ bool EmuFolders::SetDataDirectory(Error* error)

// couldn't determine the data directory, or using portable mode? fallback to portable.
if (DataRoot.empty())
DataRoot = AppRoot;
DataRoot = Path::Combine(AppRoot, GetPortableModePath());

// inis is always below the data root
Settings = Path::Combine(DataRoot, "inis");
Expand Down
8 changes: 7 additions & 1 deletion pcsx2/VMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3739,15 +3739,21 @@ void VMManager::UpdateDiscordPresence(bool update_session_time)
// https://discord.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
DiscordRichPresence rp = {};
rp.largeImageKey = "4k-pcsx2";
rp.largeImageText = "PCSX2 Emulator";
rp.largeImageText = "PCSX2 PS2 Emulator";
rp.startTimestamp = s_discord_presence_time_epoch;
rp.details = s_title.empty() ? TRANSLATE("VMManager","No Game Running") : s_title.c_str();

std::string state_string;

if (Achievements::HasRichPresence())
{
auto lock = Achievements::GetLock();

state_string = StringUtil::Ellipsise(Achievements::GetRichPresenceString(), 128);
rp.state = state_string.c_str();

rp.largeImageKey = Achievements::GetGameIconURL().c_str();
rp.largeImageText = s_title.c_str();
}

Discord_UpdatePresence(&rp);
Expand Down

0 comments on commit fe65ddf

Please sign in to comment.