Xbox Cloud Gaming app for PS5 Homebrew
C
Confirm button: the new choice works from the next press
Rafael Abud Ferreira490c4e47323a
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 07fa578..5e7ccb2 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -26,7 +26,8 @@ bool uiSaved = false;bool settingsShot = false; // "settingstest": save the screen nowuint64_t homeSince = 0, launchSince = 0;bool launchSaved = false;-const char* pickerShot = nullptr; // "pickertest": save this screen next, once drawn+const char* pickerShot = nullptr;+bool confirmShot = false, confirmHome = false; // "confirmtest": save confirm2.ppm / check the home screen // "pickertest": save this screen next, once drawnbool acceptUpdate = false; // "updatetest": Cross on the pop-up, next pass ("updateskip": Circle)} // namespace@@ -78,6 +79,7 @@ void loadAutoplay() {if (opt == "settingsupdate") g_autoplay.settingsUpdate = true;if (opt == "pickertest") g_autoplay.pickerTest = true;if (opt == "menushot") g_autoplay.menuShot = true;+ if (opt == "confirmtest") g_autoplay.confirmTest = true;if (opt == "norestart") g_autoplay.noRestart = true;if (opt.rfind("threads=", 0) == 0) g_autoplay.decodeThreads = std::atoi(opt.c_str() + 8);}@@ -124,6 +126,25 @@ void autoplayPad(input::ControllerState& pad) {// Autoplay runs unattended: the physical pad must not interfere// (unless "pad": someone is playing along, and each press is logged).if (!g_autoplay.title.empty() && !g_autoplay.pad) pad = input::ControllerState{};+ if (g_autoplay.confirmTest && uiSaved) {+ // The buttons as the hands press them, swapped as input::poll swaps+ // them: Settings, down to the confirm button; Cross opens its list,+ // down, Cross (held over the change) picks Circle; Circle now opens+ // the list again (saved), Circle picks; Cross now leaves Settings.+ static uint64_t since = 0;+ uint64_t now = platform::nowMs();+ if (!since) since = now;+ uint64_t t = now - since;+ auto in = [&](uint64_t at, uint64_t len) { return t >= at && t < at + len; };+ bool cross = in(2700, 150) || in(3700, 500) || in(6800, 150), circle = in(4800, 150) || in(6000, 150);+ bool swapped = input::circleConfirms();+ pad.btnA = swapped ? circle : cross;+ pad.btnB = swapped ? cross : circle;+ pad.btnOptions = in(500, 150);+ pad.dpadDown = in(1000, 120) || in(1300, 120) || in(1600, 120) || in(1900, 120) || in(2200, 120) || in(3200, 120);+ if (in(5500, 20)) confirmShot = true;+ if (in(8000, 20)) confirmHome = true;+ }if (!g_autoplay.pad) return;static std::string lastPressed;std::string pressed;@@ -365,6 +386,16 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {saveCanvas("ui.ppm");}}+ if (confirmShot) {+ confirmShot = false;+ saveCanvas("confirm2.ppm");+ }+ if (confirmHome) {+ confirmHome = false;+ g_autoplay.confirmTest = false;+ saveCanvas("home.ppm");+ XC_LOGI("AUTOPLAY END: confirm test, on the %s screen", g_ui->screen() == ui::Screen::Home ? "home" : "WRONG");+ }if (pickerShot) {saveCanvas(pickerShot);if (std::string(pickerShot) == "settings.ppm") XC_LOGI("AUTOPLAY END: picker test");diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex 0c51c8b..a626fd1 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -60,6 +60,7 @@ struct Autoplay {bool updateTest = false; // updatetest: accept the update pop-up, save update.ppm / updating.ppmbool updateSkip = false; // updateskip: "Not now" on the update pop-upbool settingsUpdate = false; // settingsupdate: Settings > Updates, Cross+ bool confirmTest = false; // confirmtest: physical Cross / Circle presses through Settings > Confirm buttonbool menuShot = false; // menushot: the game menu open over the 10 s snapshot (screen.ppm)bool pickerTest = false; // pickertest: the confirm button's list (confirm.ppm), the light// bar's colour picker moved (picker.ppm), chosen (settings.ppm)diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex 02e4f93..56f58be 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -25,6 +25,7 @@#include <mutex>#include <string>#include <thread>+#include <utility>extern "C" int sceSystemServiceHideSplashScreen(void);@@ -279,6 +280,13 @@ int main(int argc, char** argv) {streamScreen.idle();ui::UiEvent ev = g_ui->handle(nav);+ if (bool circle = g_ui->circleConfirms(); circle != input::circleConfirms()) {+ // The confirm button just changed in Settings: the pad follows at+ // once, and a button still held from choosing it isn't a new press.+ input::setCircleConfirms(circle);+ std::swap(prev.btnA, prev.btnB);+ XC_LOGI("confirm button: %s", circle ? "circle" : "cross");+ }switch (ev.action) {case ui::Action::Play: {std::lock_guard<std::mutex> lock(g_argMutex);diff --git a/src/input/controller.cpp b/src/input/controller.cppindex ec48412..cbead29 100644--- a/src/input/controller.cpp+++ b/src/input/controller.cpp@@ -267,6 +267,7 @@ void setTriggerRumble(uint8_t left, uint8_t right, uint32_t durationMs, int pad)}void setCircleConfirms(bool on) { g_circleConfirms = on; }+bool circleConfirms() { return g_circleConfirms; }void setLightBar(uint8_t r, uint8_t g, uint8_t b, int pad) {if (pad >= 0 && pad < kMaxPads) g_pads[pad].lightWanted = (1u << 24) | (uint32_t(r) << 16) | (uint32_t(g) << 8) | b;@@ -419,6 +420,7 @@ void setRumble(uint8_t, uint8_t, uint32_t, int) {}void setTriggerRumble(uint8_t, uint8_t, uint32_t, int) {}void setDeadzone(float) {}void setCircleConfirms(bool) {}+bool circleConfirms() { return false; }void setLightBar(uint8_t, uint8_t, uint8_t, int) {}void resetLightBar(int) {}bool padConnected(int index) { return index == 0; }diff --git a/src/input/controller.h b/src/input/controller.hindex 755ce41..efa1ae4 100644--- a/src/input/controller.h+++ b/src/input/controller.h@@ -72,6 +72,7 @@ void setTriggerRumble(uint8_t left, uint8_t right, uint32_t durationMs, int padvoid setDeadzone(float deadzone);// Circle reported as Cross (Xbox A) and Cross as Circle, everywhere.void setCircleConfirms(bool on);+bool circleConfirms();// Off: setTriggerRumble() is ignored.void setTriggerRumbleEnabled(bool on);// The light bar eases (~0.4 s) to this colour; reset gives it back to thediff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 2afef61..207ab68 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -802,6 +802,11 @@ void AppUi::setCircleConfirms(bool on) {dirty_ = true;}+bool AppUi::circleConfirms() const {+ std::lock_guard<std::mutex> lock(mutex_);+ return circleConfirms_;+}+void AppUi::setPads(const PadSlots& pads) {std::lock_guard<std::mutex> lock(mutex_);bool changed = false;@@ -918,6 +923,7 @@ void AppUi::applySetting(int row, int index) {settings_.triggerRumble = index == 0;} else if (row == 5) {settings_.circleConfirms = index == 1;+ circleConfirms_ = settings_.circleConfirms; // in force at once: the next press already uses it} else if (row == 6) {settings_.lightBarMode = index;} else if (row == 7) {diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex ebb1334..c842418 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -174,6 +174,9 @@ public:// The confirm button in force (the hints show it); Settings may be// showing another choice not saved yet.void setCircleConfirms(bool on);+ // The confirm button in force now: Settings changes it as soon as it is+ // chosen there, before it is saved (the app makes the pad follow).+ bool circleConfirms() const;// The controllers in use (bottom left of the home screen).void setPads(const PadSlots& pads);// The colour of the game in focus (or being played), from its art, for