Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Autoplay tests leave the user's settings as they were: gamesettingstest puts the game's profile back, keystest the keys

Rafael Abud Ferreirabf42dcfa1758
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cpp
index d471bbf..7ada912 100644
--- a/src/app/autoplay.cpp
+++ b/src/app/autoplay.cpp
@@ -18,6 +18,7 @@
#include <csignal>
#include <cstdio>
#include <cstdlib>
+#include <optional>
namespace xc::app {
@@ -36,6 +37,9 @@ bool confirmShot = false, confirmHome = false;
const char* tuneShot = nullptr; // "tunetest": save this screen next // "confirmtest": save confirm2.ppm / check the home screen // "pickertest": save this screen next, once drawn
const char* gridShot = nullptr; // "gridtest": save grid screenshot
const char* gameSettingsShot = nullptr; // "gamesettingstest": save screenshot
+std::string gameSettingsKey; // the game whose profile the test changes
+std::optional<GameProfile> gameSettingsBefore; // its profile before (none: it had none)
+std::optional<input::KeyMap> keysBefore; // "keystest": the keys before, put back at the end
const char* regionShot = nullptr; // "regiontest": save this screen next
bool acceptUpdate = false; // "updatetest": Cross on the pop-up, next pass ("updateskip": Circle)
} // namespace
@@ -199,6 +203,12 @@ void autoplayPad(input::ControllerState& pad) {
if (found) {
g_ui->showDetails(tile);
step = 1;
+ // The test changes and saves this game's profile: what it was
+ // is put back at the end (it is the user's real settings).
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ gameSettingsKey = app::gameProfileKey(tile.productId, tile.titleId);
+ auto it = g_settings.perGame.find(gameSettingsKey);
+ gameSettingsBefore = it != g_settings.perGame.end() ? std::optional<GameProfile>(it->second) : std::nullopt;
}
}
// Step 1: Wait for details to draw, then take screenshot
@@ -256,6 +266,16 @@ void autoplayPad(input::ControllerState& pad) {
}
// Step 8: Finish
if (step == 8 && t >= 13000) {
+ {
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ if (gameSettingsBefore)
+ g_settings.perGame[gameSettingsKey] = *gameSettingsBefore;
+ else
+ g_settings.perGame.erase(gameSettingsKey);
+ g_settings.save(settingsPath());
+ g_ui->setPerGameSettings(g_settings.perGame);
+ }
+ XC_LOGI("autoplay: the game's profile put back as it was");
g_autoplay.gameSettingsTest = false;
XC_LOGI("AUTOPLAY END: game settings test");
step = 9;
@@ -475,6 +495,10 @@ void autoplayNav(ui::NavInput& nav, bool& menuCombo, uint64_t now) {
static const char* shots[] = {"keys_settings.ppm", "keys.ppm", "keys_capture.ppm", "keys_after.ppm",
"keys_settings_after.ppm"};
static int shot = 0;
+ if (!keysBefore) {
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ keysBefore = g_settings.keyMap;
+ }
if (step < static_cast<int>(std::size(steps)) && now - since >= steps[step].at) {
switch (steps[step].what) {
case Options: nav.options = true; break;
@@ -485,11 +509,22 @@ void autoplayNav(ui::NavInput& nav, bool& menuCombo, uint64_t now) {
case Shot: keysShot = shots[shot++]; break;
case Reserved: g_ui->captureKey(0x7B); break;
case KeyG: g_ui->captureKey('G'); break;
- case End:
+ case End: {
+ // The user's own keys back (the test ends on the defaults,
+ // which Settings saved on the way out).
+ ui::SettingsChoice choice = g_ui->settings();
+ choice.keyMap = *keysBefore;
+ g_ui->setSettings(choice);
+ {
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ g_settings.keyMap = *keysBefore;
+ g_settings.save(settingsPath());
+ }
g_autoplay.keysTest = false;
- XC_LOGI("AUTOPLAY END: keys test");
+ XC_LOGI("AUTOPLAY END: keys test (the keys put back as they were)");
break;
}
+ }
++step;
}
}
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index a2a7441..4836d8a 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -1202,6 +1202,11 @@ void AppUi::setSettings(const SettingsChoice& choice) {
dirty_ = true;
}
+SettingsChoice AppUi::settings() const {
+ std::lock_guard<std::mutex> lock(mutex_);
+ return settings_;
+}
+
void AppUi::setGyroDefaults(int mode, int level) {
std::lock_guard<std::mutex> lock(mutex_);
gyroMode_ = mode;
diff --git a/src/ui/app_ui.h b/src/ui/app_ui.h
index 0f404e6..aa8b920 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -245,6 +245,7 @@ public:
// another country (Square), and Settings (Options).
void showRegionRefused(const std::string& message);
void setSettings(const SettingsChoice& choice);
+ SettingsChoice settings() const; // what Settings holds now (the autoplay tests put it back)
// Per-game settings
void setPerGameSettings(const std::map<std::string, app::GameProfile>& perGame);
// The general gyro aiming (set from the in-game menu): what a game