Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Fix sign-in QR code and missing art on the loading screen

Rafael Abud Ferreira9832247d558d
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index 3f981fe..baa81a1 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -14,9 +14,11 @@
#include "ui/app_ui.h"
#include "ui/strings.h"
#include "util/log.h"
+#include "xcloud/catalog.h"
#include "xcloud/gssv.h"
#include <atomic>
+#include <map>
#include <cstdio>
#include <memory>
#include <mutex>
@@ -191,6 +193,20 @@ std::string play(auth::AuthManager& am, xcloud::GssvClient& gssv, const ui::Game
g_ui->showLaunching(game, ui::tr(ui::Str::Connecting));
std::string err;
if (!gssv.startSession(game.titleId, "en-US", err)) return err;
+ if (game.heroUrl.empty() && !game.productId.empty()) {
+ // Picked before the background hydration reached it: fetch the hero
+ // art for the loading screen while the session queues.
+ std::map<std::string, xcloud::Product> full;
+ std::string e;
+ if (xcloud::fetchProducts({game.productId}, gssv.session().market.empty() ? "US" : gssv.session().market,
+ ui::catalogLanguage(), full, e, true) &&
+ full.count(game.productId)) {
+ ui::GameTile withArt = game;
+ withArt.heroUrl = full[game.productId].heroUrl;
+ XC_LOGI("launch art: %s", withArt.heroUrl.empty() ? "(none)" : withArt.heroUrl.c_str());
+ g_ui->showLaunching(withArt, ui::tr(ui::Str::Connecting));
+ }
+ }
bool connected = false;
std::string result = "timed out waiting for the session";
for (int i = 0; i < 900 && !g_cancel; ++i) {
@@ -381,8 +397,8 @@ int main(int argc, char** argv) {
input::ControllerState prev{}, pad{};
Repeater up, down, left, right;
uint64_t exitHeldSince = 0;
- uint64_t homeSince = 0;
- bool uiSaved = false;
+ uint64_t homeSince = 0, launchSince = 0;
+ bool uiSaved = false, launchSaved = false;
for (;;) {
input::poll(pad);
// Autoplay runs unattended: the physical pad must not interfere.
@@ -437,20 +453,31 @@ int main(int argc, char** argv) {
case ui::Action::None: break;
}
- // Autoplay: save the rendered home screen once its images are in.
+ // Autoplay: save the rendered home and loading screens.
+ auto saveCanvas = [&](const char* name) {
+ std::string ppm = "P6\n1920 1080\n255\n";
+ ppm.reserve(ppm.size() + 1920u * 1080u * 3u);
+ for (size_t i = 0; i < 1920u * 1080u; ++i) {
+ uint32_t p = canvas.data()[i];
+ ppm += static_cast<char>(p & 0xFF);
+ ppm += static_cast<char>((p >> 8) & 0xFF);
+ ppm += static_cast<char>((p >> 16) & 0xFF);
+ }
+ XC_LOGI("ui snapshot %s: %s", name,
+ platform::writeFileAtomic(platform::dataDir() + "/" + name, ppm) ? "ok" : "failed");
+ };
+ if (!g_autoplayTitle.empty() && !launchSaved && g_ui->screen() == ui::Screen::Launching) {
+ if (!launchSince) launchSince = now;
+ if (now - launchSince > 8000) {
+ launchSaved = true;
+ saveCanvas("launch.ppm");
+ }
+ }
if (!g_autoplayTitle.empty() && !uiSaved && g_ui->screen() == ui::Screen::Home) {
if (!homeSince) homeSince = now;
if (now - homeSince > 5000) {
uiSaved = true;
- std::string ppm = "P6\n1920 1080\n255\n";
- ppm.reserve(ppm.size() + 1920u * 1080u * 3u);
- for (size_t i = 0; i < 1920u * 1080u; ++i) {
- uint32_t p = canvas.data()[i];
- ppm += static_cast<char>(p & 0xFF);
- ppm += static_cast<char>((p >> 8) & 0xFF);
- ppm += static_cast<char>((p >> 16) & 0xFF);
- }
- XC_LOGI("ui snapshot: %s", platform::writeFileAtomic(platform::dataDir() + "/ui.ppm", ppm) ? "ok" : "failed");
+ saveCanvas("ui.ppm");
}
}
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index 906c853..397c1a6 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -380,8 +380,10 @@ void AppUi::drawSignIn(Canvas& c, uint64_t nowMs) {
drawSpinner(c, left + 18, 830, 14, nowMs);
fonts_.regular.draw(c, tr(Str::SignInWaiting), left + 48, 815, 26, kDim);
- // QR code for https://www.microsoft.com/link?otc=<code>.
- std::string target = "https://www.microsoft.com/link?otc=" + code_;
+ // QR code for the sign-in page. Not "?otc=<code>": that prefilled link
+ // goes through a consent flow that rejects this client id ("first party
+ // application ... pre-authorization"), so the code is typed on the phone.
+ std::string target = codeUrl_.empty() ? "https://www.microsoft.com/link" : codeUrl_;
uint8_t qr[qrcodegen_BUFFER_LEN_MAX], tmp[qrcodegen_BUFFER_LEN_MAX];
if (qrcodegen_encodeText(target.c_str(), tmp, qr, qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN,
qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true)) {
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index ba31a93..3f15025 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -17,7 +17,7 @@ constexpr std::array<const char*, static_cast<size_t>(Str::Count)> kEnglish = {
"Sign in to play", // SignInTitle
"On your phone or computer, go to", // SignInStep1
"and enter this code", // SignInStep2
- "Or scan with your phone", // SignInScan
+ "Scan to open the page, then enter the code", // SignInScan
"Waiting for you to sign in...", // SignInWaiting
"Jump back in", // JumpBackIn
"Play", // Play
diff --git a/tools/ps5/autotest.sh b/tools/ps5/autotest.sh
index 8be2d3f..97a24b8 100755
--- a/tools/ps5/autotest.sh
+++ b/tools/ps5/autotest.sh
@@ -35,7 +35,7 @@ import io, sys
from ftplib import FTP, error_perm, error_reply
host, port, d, line = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4]
f = FTP(); f.connect(host, port, timeout=15); f.login(); f.cwd(d)
-for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm"):
+for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "launch.ppm"):
try: f.sendcmd(f"DELE {name}")
except (error_perm, error_reply): pass
f.storbinary("STOR autoplay.txt", io.BytesIO(line.encode() + b"\n"))
@@ -80,7 +80,7 @@ PY
if [[ $status != *"$title_id"* ]]; then result=crashed; break; fi
fi
done
-fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm || true
+fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm || true
ctl kill "$title_id" >/dev/null 2>&1 || true
# Remove the request so a manual launch behaves normally.
python3 - "$PS5_HOST" "${FTP_PORT:-2121}" "/data/homebrew/$title_id" <<'PY'