@ -1,4 +1,5 @@
# include "cheevos.h"
# include "common/assert.h"
# include "common/cd_image.h"
# include "common/file_system.h"
# include "common/http_downloader.h"
@ -7,14 +8,13 @@
# include "common/platform.h"
# include "common/string_util.h"
# include "common/timestamp.h"
# include "common_host_interface.h"
# include "core/bios.h"
# include "core/bus.h"
# include "core/cpu_core.h"
# include "core/host_display.h"
# include "core/imgui_fullscreen.h"
# include "core/system.h"
# include "fullscreen_ui.h"
# include "host_interface.h"
# include "imgui_fullscreen.h"
# include "rapidjson/document.h"
# include "rc_url.h"
# include "rcheevos.h"
@ -86,11 +86,6 @@ static u32 s_total_image_downloads;
static u32 s_completed_image_downloads ;
static bool s_image_download_progress_active ;
static ALWAYS_INLINE CommonHostInterface * GetHostInterface ( )
{
return static_cast < CommonHostInterface * > ( g_host_interface ) ;
}
static void FormattedError ( const char * format , . . . ) printflike ( 1 , 2 ) ;
static void FormattedError ( const char * format , . . . )
{
@ -103,7 +98,7 @@ static void FormattedError(const char* format, ...)
va_end ( ap ) ;
GetHostInterface( ) - > AddOSDMessage ( str . GetCharArray ( ) , 10.0f ) ;
g_host_interface - > AddOSDMessage ( str . GetCharArray ( ) , 10.0f ) ;
Log_ErrorPrint ( str . GetCharArray ( ) ) ;
}
@ -222,7 +217,7 @@ static void ClearGameInfo(bool clear_achievements = true, bool clear_leaderboard
}
if ( had_game )
GetHostInterface( ) - > OnAchievementsRefreshed ( ) ;
g_host_interface - > OnAchievementsRefreshed ( ) ;
}
static void ClearGamePath ( )
@ -255,8 +250,8 @@ bool Initialize(bool test_mode, bool use_first_disc_from_playlist, bool enable_r
rc_runtime_init ( & s_rcheevos_runtime ) ;
s_last_ping_time . Reset ( ) ;
s_username = GetHostInterface( ) - > GetStringSettingValue ( " Cheevos " , " Username " ) ;
s_login_token = GetHostInterface( ) - > GetStringSettingValue ( " Cheevos " , " Token " ) ;
s_username = g_host_interface - > GetStringSettingValue ( " Cheevos " , " Username " ) ;
s_login_token = g_host_interface - > GetStringSettingValue ( " Cheevos " , " Token " ) ;
s_logged_in = ( ! s_username . empty ( ) & & ! s_login_token . empty ( ) ) ;
if ( IsLoggedIn ( ) & & System : : IsValid ( ) )
@ -288,7 +283,7 @@ void Shutdown()
std : : string ( ) . swap ( s_username ) ;
std : : string ( ) . swap ( s_login_token ) ;
s_logged_in = false ;
GetHostInterface( ) - > OnAchievementsRefreshed ( ) ;
g_host_interface - > OnAchievementsRefreshed ( ) ;
g_active = false ;
rc_runtime_destroy ( & s_rcheevos_runtime ) ;
@ -367,12 +362,12 @@ static void LoginCallback(s32 status_code, const FrontendCommon::HTTPDownloader:
// save to config
{
std : : lock_guard < std : : recursive_mutex > guard ( GetHostInterface( ) - > GetSettingsLock ( ) ) ;
GetHostInterface( ) - > GetSettingsInterface ( ) - > SetStringValue ( " Cheevos " , " Username " , username . c_str ( ) ) ;
GetHostInterface( ) - > GetSettingsInterface ( ) - > SetStringValue ( " Cheevos " , " Token " , login_token . c_str ( ) ) ;
GetHostInterface( ) - > GetSettingsInterface ( ) - > SetStringValue (
std : : lock_guard < std : : recursive_mutex > guard ( g_host_interface - > GetSettingsLock ( ) ) ;
g_host_interface - > GetSettingsInterface ( ) - > SetStringValue ( " Cheevos " , " Username " , username . c_str ( ) ) ;
g_host_interface - > GetSettingsInterface ( ) - > SetStringValue ( " Cheevos " , " Token " , login_token . c_str ( ) ) ;
g_host_interface - > GetSettingsInterface ( ) - > SetStringValue (
" Cheevos " , " LoginTimestamp " , TinyString : : FromFormat ( " % " PRIu64 , Timestamp : : Now ( ) . AsUnixTimestamp ( ) ) ) ;
GetHostInterface( ) - > GetSettingsInterface ( ) - > Save ( ) ;
g_host_interface - > GetSettingsInterface ( ) - > Save ( ) ;
}
if ( g_active )
@ -389,7 +384,7 @@ static void LoginCallback(s32 status_code, const FrontendCommon::HTTPDownloader:
static void LoginASyncCallback ( s32 status_code , const FrontendCommon : : HTTPDownloader : : Request : : Data & data )
{
if ( GetHostInterface( ) - > IsFullscreenUIEnabl ed( ) )
if ( ImGuiFullscreen: : IsInitializ ed( ) )
ImGuiFullscreen : : CloseBackgroundProgressDialog ( " cheevos_async_login " ) ;
LoginCallback ( status_code , data ) ;
@ -412,10 +407,10 @@ bool LoginAsync(const char* username, const char* password)
if ( s_logged_in | | std : : strlen ( username ) = = 0 | | std : : strlen ( password ) = = 0 )
return false ;
if ( GetHostInterface( ) - > IsFullscreenUIEnabl ed( ) )
if ( ImGuiFullscreen: : IsInitializ ed( ) )
{
ImGuiFullscreen : : OpenBackgroundProgressDialog (
" cheevos_async_login " , GetHostInterface( ) - > TranslateStdString ( " Cheevos " , " Logging in to RetroAchivements... " ) , 0 ,
" cheevos_async_login " , g_host_interface - > TranslateStdString ( " Cheevos " , " Logging in to RetroAchivements... " ) , 0 ,
1 , 0 ) ;
}
@ -448,7 +443,7 @@ bool Login(const char* username, const char* password)
SendLogin ( username , password , http_downloader . get ( ) , LoginCallback ) ;
http_downloader - > WaitForAllRequests ( ) ;
return ! GetHostInterface( ) - > GetStringSettingValue ( " Cheevos " , " Token " ) . empty ( ) ;
return ! g_host_interface - > GetStringSettingValue ( " Cheevos " , " Token " ) . empty ( ) ;
}
void Logout ( )
@ -462,17 +457,17 @@ void Logout()
std : : string ( ) . swap ( s_username ) ;
std : : string ( ) . swap ( s_login_token ) ;
s_logged_in = false ;
GetHostInterface( ) - > OnAchievementsRefreshed ( ) ;
g_host_interface - > OnAchievementsRefreshed ( ) ;
}
}
// remove from config
std : : lock_guard < std : : recursive_mutex > guard ( GetHostInterface( ) - > GetSettingsLock ( ) ) ;
std : : lock_guard < std : : recursive_mutex > guard ( g_host_interface - > GetSettingsLock ( ) ) ;
{
GetHostInterface( ) - > GetSettingsInterface ( ) - > DeleteValue ( " Cheevos " , " Username " ) ;
GetHostInterface( ) - > GetSettingsInterface ( ) - > DeleteValue ( " Cheevos " , " Token " ) ;
GetHostInterface( ) - > GetSettingsInterface ( ) - > DeleteValue ( " Cheevos " , " LoginTimestamp " ) ;
GetHostInterface( ) - > GetSettingsInterface ( ) - > Save ( ) ;
g_host_interface - > GetSettingsInterface ( ) - > DeleteValue ( " Cheevos " , " Username " ) ;
g_host_interface - > GetSettingsInterface ( ) - > DeleteValue ( " Cheevos " , " Token " ) ;
g_host_interface - > GetSettingsInterface ( ) - > DeleteValue ( " Cheevos " , " LoginTimestamp " ) ;
g_host_interface - > GetSettingsInterface ( ) - > Save ( ) ;
}
}
@ -494,7 +489,7 @@ static void UpdateImageDownloadProgress()
return ;
}
if ( ! GetHostInterface( ) - > IsFullscreenUIEnabl ed( ) )
if ( ! ImGuiFullscreen: : IsInitializ ed( ) )
return ;
std : : string message ( g_host_interface - > TranslateStdString ( " Cheevos " , " Downloading achievement resources... " ) ) ;
@ -528,7 +523,7 @@ static void DownloadImage(std::string url, std::string cache_filename)
return ;
}
FullscreenUI : : InvalidateCachedTexture ( cache_filename ) ;
ImGui Fullscreen: : InvalidateCachedTexture ( cache_filename ) ;
UpdateImageDownloadProgress ( ) ;
} ;
@ -549,7 +544,7 @@ static std::string GetBadgeImageFilename(const char* badge_name, bool locked, bo
// well, this comes from the internet.... :)
SmallString clean_name ( badge_name ) ;
FileSystem : : SanitizeFileName ( clean_name ) ;
return GetHostInterface( ) - > GetUserDirectoryRelativePath ( " cache " FS_OSPATH_SEPARATOR_STR
return g_host_interface - > GetUserDirectoryRelativePath ( " cache " FS_OSPATH_SEPARATOR_STR
" achievement_badge " FS_OSPATH_SEPARATOR_STR " %s%s.png " ,
clean_name . GetCharArray ( ) , locked ? " _lock " : " " ) ;
}
@ -575,30 +570,30 @@ static void DisplayAchievementSummary()
{
std : : string title = s_game_title ;
if ( g_challenge_mode )
title + = GetHostInterface( ) - > TranslateString ( " Cheevos " , " (Hardcore Mode) " ) ;
title + = g_host_interface - > TranslateString ( " Cheevos " , " (Hardcore Mode) " ) ;
std : : string summary ;
if ( GetAchievementCount ( ) > 0 )
{
summary = StringUtil : : StdStringFromFormat (
GetHostInterface( ) - > TranslateString ( " Cheevos " , " You have earned %u of %u achievements, and %u of %u points. " ) ,
g_host_interface - > TranslateString ( " Cheevos " , " You have earned %u of %u achievements, and %u of %u points. " ) ,
GetUnlockedAchiementCount ( ) , GetAchievementCount ( ) , GetCurrentPointsForGame ( ) , GetMaximumPointsForGame ( ) ) ;
}
else
{
summary = GetHostInterface( ) - > TranslateString ( " Cheevos " , " This game has no achievements. " ) ;
summary = g_host_interface - > TranslateString ( " Cheevos " , " This game has no achievements. " ) ;
}
if ( GetLeaderboardCount ( ) > 0 )
{
summary . push_back ( ' \n ' ) ;
if ( g_challenge_mode )
{
summary . append ( GetHostInterface( ) - > TranslateString ( " Cheevos " , " Leaderboards are enabled. " ) ) ;
summary . append ( g_host_interface - > TranslateString ( " Cheevos " , " Leaderboards are enabled. " ) ) ;
}
else
{
summary . append (
GetHostInterface( ) - > TranslateString ( " Cheevos " , " Leaderboards are DISABLED because Hardcore Mode is off. " ) ) ;
g_host_interface - > TranslateString ( " Cheevos " , " Leaderboards are DISABLED because Hardcore Mode is off. " ) ) ;
}
}
@ -649,7 +644,7 @@ static void GetUserUnlocksCallback(s32 status_code, const FrontendCommon::HTTPDo
SendPlaying ( ) ;
UpdateRichPresence ( ) ;
SendPing ( ) ;
GetHostInterface( ) - > OnAchievementsRefreshed ( ) ;
g_host_interface - > OnAchievementsRefreshed ( ) ;
}
static void GetUserUnlocks ( )
@ -694,7 +689,7 @@ static void GetPatchesCallback(s32 status_code, const FrontendCommon::HTTPDownlo
std : : string icon_name ( GetOptionalString ( patch_data , " ImageIcon " ) ) ;
if ( ! icon_name . empty ( ) )
{
s_game_icon = GetHostInterface( ) - > GetUserDirectoryRelativePath (
s_game_icon = g_host_interface - > GetUserDirectoryRelativePath (
" cache " FS_OSPATH_SEPARATOR_STR " achievement_gameicon " FS_OSPATH_SEPARATOR_STR " %u.png " , g_game_id ) ;
if ( ! FileSystem : : FileExists ( s_game_icon . c_str ( ) ) )
{
@ -825,7 +820,7 @@ static void GetPatchesCallback(s32 status_code, const FrontendCommon::HTTPDownlo
{
ActivateLockedAchievements ( ) ;
DisplayAchievementSummary ( ) ;
GetHostInterface( ) - > OnAchievementsRefreshed ( ) ;
g_host_interface - > OnAchievementsRefreshed ( ) ;
}
}
else
@ -1024,7 +1019,7 @@ void GameChanged(const std::string& path, CDImage* image)
if ( s_game_hash . empty ( ) )
{
GetHostInterface( ) - > AddOSDMessage ( GetHostInterface ( ) - > TranslateStdString (
g_host_interface- > AddOSDMessage ( g_host_interface - > TranslateStdString (
" OSDMessage " , " Failed to read executable from disc. Achievements disabled. " ) ,
10.0f ) ;
return ;
@ -1070,7 +1065,7 @@ static void UpdateRichPresence()
const bool had_rich_presence = ! s_rich_presence_string . empty ( ) ;
s_rich_presence_string . clear ( ) ;
if ( had_rich_presence )
GetHostInterface( ) - > OnAchievementsRefreshed ( ) ;
g_host_interface - > OnAchievementsRefreshed ( ) ;
return ;
}
@ -1079,7 +1074,7 @@ static void UpdateRichPresence()
return ;
s_rich_presence_string . assign ( buffer ) ;
GetHostInterface( ) - > OnAchievementsRefreshed ( ) ;
g_host_interface - > OnAchievementsRefreshed ( ) ;
}
static void SendPingCallback ( s32 status_code , const FrontendCommon : : HTTPDownloader : : Request : : Data & data )