You can now log into RetroAchievements with hardcoded user/pass

This commit is contained in:
Henrik Rydgård 2023-06-16 16:29:44 +02:00
parent 66d9c24f72
commit b84a6f83e1
6 changed files with 80 additions and 6 deletions

View File

@ -265,7 +265,20 @@ static bool DefaultSasThread() {
}
static const ConfigSetting achievementSettings[] = {
ConfigSetting("Enable", &g_Config.bAchievementsEnable, true, CfgFlag::PER_GAME),
ConfigSetting("AchievementsEnable", &g_Config.bAchievementsEnable, true, CfgFlag::DEFAULT),
ConfigSetting("AchievementsLeaderboards", &g_Config.bAchievementsLeaderboards, false, CfgFlag::DEFAULT),
ConfigSetting("AchievementsTestMode", &g_Config.bAchievementsTestMode, false, CfgFlag::DEFAULT),
ConfigSetting("AchievementsUnofficialTestMode", &g_Config.bAchievementsUnofficialTestMode, false, CfgFlag::DEFAULT),
ConfigSetting("AchievementsRichPresence", &g_Config.bAchievementsRichPresence, true, CfgFlag::DEFAULT),
ConfigSetting("AchievementsChallengeMode", &g_Config.bAchievementsChallengeMode, false, CfgFlag::DEFAULT),
ConfigSetting("AchievementsSoundEffects", &g_Config.bAchievementsSoundEffects, true, CfgFlag::DEFAULT),
ConfigSetting("AchievementsNotifications", &g_Config.bAchievementsNotifications, true, CfgFlag::DEFAULT),
// Achievements login info. Note that password is NOT stored, only a login token.
// Still, we may wanna store it more securely than in PPSSPP.ini, especially on Android.
ConfigSetting("AchievementsUserName", &g_Config.sAchievementsUserName, "", CfgFlag::DEFAULT),
ConfigSetting("AchievementsToken", &g_Config.sAchievementsToken, "", CfgFlag::DEFAULT),
ConfigSetting("AchievementsLoginTimestamp", &g_Config.sAchievementsLoginTimestamp, "", CfgFlag::DEFAULT),
};
static const ConfigSetting cpuSettings[] = {

View File

@ -53,6 +53,7 @@
#include "UI/GPUDriverTestScreen.h"
#include "UI/MemStickScreen.h"
#include "UI/Theme.h"
#include "UI/RetroAchievementScreens.h"
#include "Common/File/FileUtil.h"
#include "Common/File/AndroidContentURI.h"
@ -850,6 +851,11 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) {
auto vr = GetI18NCategory(I18NCat::VR);
auto th = GetI18NCategory(I18NCat::THEMES);
systemSettings->Add(new Choice(sy->T("Achievements")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
screenManager()->push(new RetroAchievementsSettingsScreen(gamePath_));
return UI::EVENT_DONE;
});
systemSettings->Add(new ItemHeader(sy->T("UI")));
auto langCodeToName = [](const char *value) -> std::string {

View File

@ -1,7 +1,47 @@
#include "UI/RetroAchievementScreens.h"
#include "RetroAchievements.h"
#include "UI/RetroAchievements.h"
#include "Common/UI/View.h"
#include "Common/UI/ViewGroup.h"
#include "Common/Data/Text/I18n.h"
void RetroAchievementsListScreen::CreateViews() {
auto di = GetI18NCategory(I18NCat::DIALOG);
}
void RetroAchievementsSettingsScreen::CreateTabs() {
auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS);
using namespace UI;
LinearLayout *account = AddTab("AchievementsAccount", ac->T("Account"));
CreateAccountTab(account);
}
void RetroAchievementsSettingsScreen::sendMessage(const char *message, const char *value) {
TabbedUIDialogScreenWithGameBackground::sendMessage(message, value);
if (!strcmp(message, "achievements_loginstatechange")) {
RecreateViews();
}
}
void RetroAchievementsSettingsScreen::CreateAccountTab(UI::ViewGroup *viewGroup) {
auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS);
using namespace UI;
if (Achievements::IsLoggedIn()) {
viewGroup->Add(new InfoItem(ac->T("User Name"), Achievements::GetUsername()));
viewGroup->Add(new Choice(ac->T("Log out")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
Achievements::Logout();
return UI::EVENT_DONE;
});
} else {
viewGroup->Add(new Choice(ac->T("Log in to RetroAchievements")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
// TODO: Actually allow entering user/pass.
Achievements::LoginAsync("fakeuser", "fakepassword");
return UI::EVENT_DONE;
});
}
}

View File

@ -3,6 +3,7 @@
#include "Common/UI/UIScreen.h"
#include "Common/UI/ViewGroup.h"
#include "UI/MiscScreens.h"
#include "UI/TabbedDialogScreen.h"
#include "Common/File/Path.h"
class RetroAchievementsListScreen : public UIDialogScreenWithGameBackground {
@ -13,8 +14,14 @@ public:
void CreateViews() override;
};
class RetroAchievementsSetupScreen : public UIDialogScreenWithGameBackground {
class RetroAchievementsSettingsScreen : public TabbedUIDialogScreenWithGameBackground {
public:
RetroAchievementsSetupScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {}
RetroAchievementsSettingsScreen(const Path &gamePath) : TabbedUIDialogScreenWithGameBackground(gamePath) {}
const char *tag() const override { return "RetroAchievementsSettingsScreen"; }
void CreateTabs() override;
void sendMessage(const char *message, const char *value) override;
private:
void CreateAccountTab(UI::ViewGroup *viewGroup);
};

View File

@ -75,6 +75,9 @@ namespace Common {
void CreatePostRequest(std::string &&url, const char *post_data, Request::Callback &&callback) {
Request::Callback movedCallback = std::move(callback);
std::string post_data_str(post_data);
NOTICE_LOG(ACHIEVEMENTS, "Request: post_data=%s", post_data);
downloader_.AsyncPostWithCallback(url, post_data_str, "application/x-www-form-urlencoded", [=](http::Download &download) {
std::string data;
download.buffer().TakeAll(&data);
@ -109,6 +112,9 @@ namespace Host {
void OnAchievementsRefreshed() {
System_PostUIMessage("achievements_refreshed", "");
}
void OnAchievementsLoginStateChange() {
System_PostUIMessage("achievements_loginstatechange", "");
}
}
namespace Achievements {
@ -978,6 +984,8 @@ void Achievements::LoginCallback(s32 status_code, std::string content_type, Comm
if (!s_game_hash.empty())
SendGetGameId();
}
Host::OnAchievementsLoginStateChange();
}
void Achievements::LoginASyncCallback(s32 status_code, std::string content_type,
@ -1050,7 +1058,7 @@ void Achievements::Logout()
std::string().swap(s_username);
std::string().swap(s_api_token);
s_logged_in = false;
Host::OnAchievementsRefreshed();
Host::OnAchievementsLoginStateChange();
}
}

View File

@ -21,11 +21,11 @@ protected:
virtual bool ShowSearchControls() { return true; }
void RecreateViews() override;
void sendMessage(const char *message, const char *value) override;
SettingInfoMessage *settingInfo_ = nullptr;
private:
void sendMessage(const char *message, const char *value) override;
void ApplySearchFilter();
UI::TabHolder *tabHolder_ = nullptr;