diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index d2650bf961..0801870912 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1430,7 +1430,7 @@ static Path GetSecretPath(const char *nameOfSecret) { // name should be simple alphanumerics to avoid problems on Windows. void NativeSaveSecret(const char *nameOfSecret, const std::string &data) { Path path = GetSecretPath(nameOfSecret); - if (!File::WriteDataToFile(false, data.data(), data.size(), path)) { + if (!File::WriteDataToFile(false, data.data(), (unsigned int)data.size(), path)) { WARN_LOG(SYSTEM, "Failed to write secret '%s' to path '%s'", nameOfSecret, path.c_str()); } } diff --git a/UI/RetroAchievementScreens.cpp b/UI/RetroAchievementScreens.cpp index e3a81f2a54..cce576695c 100644 --- a/UI/RetroAchievementScreens.cpp +++ b/UI/RetroAchievementScreens.cpp @@ -51,11 +51,11 @@ void RetroAchievementsSettingsScreen::CreateTabs() { using namespace UI; - LinearLayout *account = AddTab("AchievementsAccount", ac->T("Account")); - CreateAccountTab(account); - - LinearLayout *settings = AddTab("AchievementsSettings", di->T("Settings")); - CreateSettingsTab(settings); + CreateAccountTab(AddTab("AchievementsAccount", ac->T("Account"))); + CreateSettingsTab(AddTab("AchievementsSettings", di->T("Settings"))); +#ifdef _DEBUG + CreateStatisticsTab(AddTab("AchievementsStatistics", ac->T("Statistics"))); +#endif } void RetroAchievementsSettingsScreen::sendMessage(const char *message, const char *value) { @@ -136,6 +136,16 @@ void RetroAchievementsSettingsScreen::CreateSettingsTab(UI::ViewGroup *viewGroup // viewGroup->Add(new CheckBox(&g_Config.bAchievementsUnofficialTestMode, ac->T("Unofficial Test Mode"))); } +void RetroAchievementsSettingsScreen::CreateStatisticsTab(UI::ViewGroup *viewGroup) { + auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS); + + using namespace UI; + + Achievements::Statistics stats = Achievements::GetStatistics(); + viewGroup->Add(new ItemHeader(ac->T("Statistics"))); + viewGroup->Add(new InfoItem(ac->T("Bad memory accesses"), StringFromFormat("%d", stats.badMemoryAccessCount))); +} + void MeasureAchievement(const UIContext &dc, const Achievements::Achievement &achievement, float *w, float *h) { *w = 0.0f; *h = 72.0f; diff --git a/UI/RetroAchievementScreens.h b/UI/RetroAchievementScreens.h index 9698eacdc8..1fd1e4a776 100644 --- a/UI/RetroAchievementScreens.h +++ b/UI/RetroAchievementScreens.h @@ -35,6 +35,7 @@ protected: private: void CreateAccountTab(UI::ViewGroup *viewGroup); void CreateSettingsTab(UI::ViewGroup *viewGroup); + void CreateStatisticsTab(UI::ViewGroup *viewGroup); std::string username_; std::string password_; diff --git a/UI/RetroAchievements.cpp b/UI/RetroAchievements.cpp index fffefcd46b..df5f465ad9 100644 --- a/UI/RetroAchievements.cpp +++ b/UI/RetroAchievements.cpp @@ -244,12 +244,13 @@ static u32 s_last_queried_lboard = 0; static u32 s_submitting_lboard_id = 0; static std::optional> s_lboard_entries; -// TODO: Make this show up somewhere. -static u64 g_badMemoryAccessCount = 0; +static Achievements::Statistics g_stats; const std::string g_gameIconCachePrefix = "game:"; const std::string g_iconCachePrefix = "badge:"; + + #define PSP_MEMORY_OFFSET 0x08000000 // TODO: Add an icon cache as a string map. We won't cache achievement icons across sessions, let's just @@ -485,6 +486,9 @@ void Achievements::ClearGameInfo(bool clear_achievements, bool clear_leaderboard s_game_id = 0; } + // Reset statistics + g_stats = {}; + if (had_game) Host::OnAchievementsRefreshed(); } @@ -1080,6 +1084,10 @@ void Achievements::DownloadImage(std::string url, std::string cache_filename) } } +Achievements::Statistics Achievements::GetStatistics() { + return g_stats; +} + std::string Achievements::GetGameAchievementSummary() { auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS); @@ -2092,7 +2100,7 @@ unsigned Achievements::PeekMemory(unsigned address, unsigned num_bytes, void *ud if (!Memory::IsValidAddress(address)) { // Some achievement packs are really, really spammy. // So we'll just count the bad accesses. - g_badMemoryAccessCount++; + g_stats.badMemoryAccessCount++; if (g_Config.bAchievementsLogBadMemReads) { WARN_LOG(G3D, "RetroAchievements PeekMemory: Bad address %08x (%d bytes)", address, num_bytes); diff --git a/UI/RetroAchievements.h b/UI/RetroAchievements.h index 4c78bafd07..0e739df5e4 100644 --- a/UI/RetroAchievements.h +++ b/UI/RetroAchievements.h @@ -23,6 +23,7 @@ class Path; class PointerWrap; namespace Achievements { + enum class AchievementCategory : u8 { Local = 0, @@ -63,6 +64,12 @@ struct LeaderboardEntry bool is_self; }; +struct Statistics +{ + // Debug stats + int badMemoryAccessCount; +}; + // RAIntegration only exists for Windows, so no point checking it on other platforms. #ifdef WITH_RAINTEGRATION @@ -148,6 +155,8 @@ u32 GetAchievementCount(); u32 GetMaximumPointsForGame(); u32 GetCurrentPointsForGame(); +Statistics GetStatistics(); + bool EnumerateLeaderboards(std::function callback); std::optional TryEnumerateLeaderboardEntries(u32 id, std::function callback); const Leaderboard *GetLeaderboardByID(u32 id);