Xbox Cloud Gaming app for PS5 Homebrew
C
Free-to-play games: their own row, free to get, a clear message (#10)
Rafael Abud Ferreirab2ba4a2c6380
diff --git a/src/app/library.cpp b/src/app/library.cppindex b4bfb8a..4baf77b 100644--- a/src/app/library.cpp+++ b/src/app/library.cpp@@ -103,8 +103,10 @@ ui::GameTile Library::tile(const std::string& productId, const std::string& titlt.heroUrl = p.heroUrl;t.categories = p.categories;if (ownershipKnown_) t.playable = ownedTitles_.count(t.titleId) || ownedProducts_.count(t.productId);- t.purchasable = !t.playable && purchasableSet_.count(productId);t.freeInStore = freeInStore_.count(productId) > 0;+ // A free-to-play game not on the account yet is got like one bought+ // (the store page's QR code), only free.+ t.purchasable = !t.playable && (purchasableSet_.count(productId) || t.freeInStore);if (siblingsFor_ != products_.size()) {seriesSiblings_.clear();for (const auto& [id, prod] : products_) {@@ -321,6 +323,7 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, constconst ListSpec lists[] = {{xcloud::sigl::kRecentlyAdded, 40},{xcloud::sigl::kMostPopular, 40},+ {xcloud::sigl::kFreeToPlay, 40},{xcloud::sigl::kLeavingSoon, 40},{xcloud::sigl::kAllGames, 120}};for (const auto& spec : lists) {@@ -335,7 +338,14 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, const// "Most popular on cloud" also lists games to buy first (Cuphead...):// those go to "Your games" (in this order), not to the Game Pass tab.if (spec.sigl == xcloud::sigl::kMostPopular) popular_ = list.productIds;- if (!gamePass_.empty()) {+ // Free-to-play: no Game Pass needed, so not filtered; each one the+ // account hasn't got yet shows as free to get (tile()).+ bool freeToPlay = spec.sigl == xcloud::sigl::kFreeToPlay;+ if (freeToPlay) {+ freeInStore_.insert(list.productIds.begin(), list.productIds.end());+ XC_LOGI("library: %s: %zu games", list.title.c_str(), list.productIds.size());+ }+ if (!gamePass_.empty() && !freeToPlay) {size_t before = list.productIds.size();list.productIds.erase(std::remove_if(list.productIds.begin(), list.productIds.end(),[&](const std::string& id) { return !gamePass_.count(id); }),@@ -353,7 +363,7 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, constlastErr = e;continue;}- RowIds r{list.title, true, {}};+ RowIds r{list.title, !freeToPlay, {}};for (const auto& id : list.productIds) r.items.emplace_back(id, std::string());layout_.push_back(std::move(r));changed();diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex aa7be49..501da7e 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -701,8 +701,16 @@ void worker() {if (!failed) g_regionFallback[tile.titleId] = next;}}- if (failed)+ if (failed && result.find("NoEntitlement") != std::string::npos) {+ // Not on the account: a free game not got yet in the+ // store (it can be, on the phone, and tried again here),+ // or one outside the subscription.+ g_ui->showPlayError(ui::trf(tile.freeInStore ? ui::Str::NoEntitlementFree : ui::Str::NoEntitlement,+ tile.name),+ tile);+ } else if (failed) {g_ui->showError(result.rfind("ERROR: ", 0) == 0 ? result.substr(7) : result);+ }elseg_ui->showHome(ui::tr(ui::Str::StreamEnded));autoplayFinished(result);@@ -1153,12 +1161,21 @@ int main(int argc, char** argv) {g_autoplayImeTest = false;}}+ if (!g_autoplayTitle.empty() && g_ui->screen() == ui::Screen::Error) {+ // The error the run ended on, as shown (error.ppm), once drawn.+ static uint64_t errorSince = 0;+ if (!errorSince) errorSince = now;+ else if (errorSince != 1 && now - errorSince > 500) {+ saveCanvas("error.ppm");+ errorSince = 1;+ }+ }if (g_autoplayDetailTest && uiSaved) {// A game to buy far down the list (no prefetched details): its- // page must fill in on its own.+ // page must fill in on its own. Or the game named, when known.static uint64_t openedAt = 0;ui::GameTile tile;- if (!openedAt && g_ui->purchasableAt(40, tile)) {+ if (!openedAt && (g_ui->findTile(g_autoplayTitle, tile) || g_ui->purchasableAt(40, tile))) {XC_LOGI("autoplay: opening %s (%s)", tile.name.c_str(), tile.productId.c_str());g_ui->showDetails(tile);openedAt = now;diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 1c3838a..63b5f81 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -461,6 +461,21 @@ void AppUi::setDetailInfo(const std::string& productId, const std::string& descrdirty_ = true;}+bool AppUi::findTile(const std::string& titleId, GameTile& out) const {+ std::lock_guard<std::mutex> lock(mutex_);+ std::vector<const GameTile*> all;+ for (const auto& row : rows_)+ for (const auto& t : row.tiles) all.push_back(&t);+ for (const auto* list : {&owned_, &purchasable_})+ for (const auto& t : *list) all.push_back(&t);+ for (const GameTile* t : all)+ if (t->titleId == titleId) {+ out = *t;+ return true;+ }+ return false;+}+bool AppUi::purchasableAt(size_t index, GameTile& out) const {std::lock_guard<std::mutex> lock(mutex_);if (index >= purchasable_.size()) return false;@@ -618,6 +633,15 @@ void AppUi::showError(const std::string& message) {std::lock_guard<std::mutex> lock(mutex_);screen_ = Screen::Error;error_ = message;+ errorGame_ = {};+ dirty_ = true;+}++void AppUi::showPlayError(const std::string& message, const GameTile& game) {+ std::lock_guard<std::mutex> lock(mutex_);+ screen_ = Screen::Error;+ error_ = message;+ errorGame_ = game;dirty_ = true;}@@ -1079,7 +1103,9 @@ UiEvent AppUi::handle(const NavInput& in) {}break;case Screen::Details:- if (in.accept && detail_.playable && !detail_.titleId.empty()) {+ // A free game not on the account yet may already be (got on the+ // phone a moment ago): Play tries, and the server says.+ if (in.accept && (detail_.playable || detail_.freeInStore) && !detail_.titleId.empty()) {ev.action = Action::Play;ev.game = detail_;}@@ -1093,7 +1119,16 @@ UiEvent AppUi::handle(const NavInput& in) {if (in.back) ev.action = Action::CancelLaunch;break;case Screen::Error:- if (in.accept) ev.action = Action::Retry;+ if (!errorGame_.productId.empty()) {+ if (in.accept) {+ ev.action = Action::Play;+ ev.game = errorGame_;+ } else if (in.back) {+ openDetails(errorGame_);+ }+ } else if (in.accept) {+ ev.action = Action::Retry;+ }break;default: break;}@@ -1383,7 +1418,9 @@ void AppUi::drawCard(Canvas& c, const GameTile& t, int x, int y, bool focused, bif (t.purchasable) {c.fillRect({x, y, kCard, kCard}, rgba(0, 0, 0, 70), 10);auto price = prices_.find(t.productId);- std::string label = price != prices_.end() ? price->second.now : tr(Str::BuyBadge);+ std::string label = t.freeInStore ? tr(Str::Free)+ : price != prices_.end() ? price->second.now+ : tr(Str::BuyBadge);int w = fonts_.bold.measure(label, 13) + 42;Rect badge{x + 10, y + kCard - 34, w, 24};c.fillRect(badge, rgba(16, 124, 16, 235), 4);@@ -1687,7 +1724,9 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {y += 44;}y += 10;- for (const auto& line : fonts_.regular.wrap(g->description, 24, 880, 6)) {+ // Shorter for a free game, whose page also has the hint and Play below.+ int descLines = g->purchasable && g->freeInStore ? 4 : 6;+ for (const auto& line : fonts_.regular.wrap(g->description, 24, 880, descLines)) {fonts_.regular.draw(c, line, kMargin, y, 24, kGray);y += 34;}@@ -1697,7 +1736,25 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {// console's browser can't run the xbox.com store, so no button.int ty = y + 30;auto price = prices_.find(g->productId);- if (price != prices_.end()) {+ if (g->freeInStore) {+ // Free to play: got once in the store (the QR code), then Play.+ fonts_.bold.draw(c, tr(Str::Free), kMargin, ty, 52, kWhite);+ ty += 84;+ fonts_.semibold.draw(c, tr(Str::FreeToPlay), kMargin, ty, 28, kWhite);+ ty += 48;+ for (const auto& line : fonts_.regular.wrap(tr(Str::FreeHint), 24, 820, 3)) {+ fonts_.regular.draw(c, line, kMargin, ty, 24, kGray);+ ty += 34;+ }+ Rect play{kMargin, ty + 30, 300, 76};+ c.strokeRect({play.x - 7, play.y - 7, play.w + 14, play.h + 14}, kWhite, 4, 45);+ c.fillRect(play, kGreen, 38);+ float tx = play.x + 70, my = play.y + play.h / 2.0f;+ c.line(tx - 8, my - 13, tx - 8, my + 13, 4, kWhite);+ c.line(tx - 8, my - 13, tx + 13, my, 4, kWhite);+ c.line(tx - 8, my + 13, tx + 13, my, 4, kWhite);+ fonts_.semibold.draw(c, tr(Str::Play), play.x + 108, play.y + 20, 32, kWhite);+ } else if (price != prices_.end()) {// The price, and the regular one crossed out while on sale.int px = kMargin;fonts_.bold.draw(c, price->second.now, px, ty, 52, kWhite);@@ -1710,12 +1767,14 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {}ty += 84;}- drawBag(c, kMargin + 12, ty + 16, kGreen);- fonts_.semibold.draw(c, tr(Str::BuyToPlay), kMargin + 36, ty, 28, kWhite);- ty += 48;- for (const auto& line : fonts_.regular.wrap(tr(Str::BuyHint), 24, 820, 3)) {- fonts_.regular.draw(c, line, kMargin, ty, 24, kGray);- ty += 34;+ if (!g->freeInStore) {+ drawBag(c, kMargin + 12, ty + 16, kGreen);+ fonts_.semibold.draw(c, tr(Str::BuyToPlay), kMargin + 36, ty, 28, kWhite);+ ty += 48;+ for (const auto& line : fonts_.regular.wrap(tr(Str::BuyHint), 24, 820, 3)) {+ fonts_.regular.draw(c, line, kMargin, ty, 24, kGray);+ ty += 34;+ }}std::string url = "https://www.xbox.com/games/store/p/" + g->productId;uint8_t qr[qrcodegen_BUFFER_LEN_MAX], tmp[qrcodegen_BUFFER_LEN_MAX];@@ -1729,10 +1788,17 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {for (int yy = 0; yy < n; ++yy)for (int xx = 0; xx < n; ++xx)if (qrcodegen_getModule(qr, xx, yy)) c.fillRect({ox + xx * module, oy + yy * module, module, module}, kBg);- int w = fonts_.semibold.measure(tr(Str::ScanToBuy), 26);- fonts_.semibold.draw(c, tr(Str::ScanToBuy), box.x + (box.w - w) / 2, box.y + box.h + 22, 26, kWhite);+ const char* scan = tr(g->freeInStore ? Str::ScanToGet : Str::ScanToBuy);+ int w = fonts_.semibold.measure(scan, 26);+ fonts_.semibold.draw(c, scan, box.x + (box.w - w) / 2, box.y + box.h + 22, 26, kWhite);}- drawHints(c, {{kIconSquare, tr(hidden_.count(g->productId) ? Str::Unhide : Str::Hide)}, {kIconCircle, tr(Str::Back)}});+ if (g->freeInStore)+ drawHints(c, {{kIconCross, tr(Str::Play)},+ {kIconSquare, tr(hidden_.count(g->productId) ? Str::Unhide : Str::Hide)},+ {kIconCircle, tr(Str::Back)}});+ else+ drawHints(c, {{kIconSquare, tr(hidden_.count(g->productId) ? Str::Unhide : Str::Hide)},+ {kIconCircle, tr(Str::Back)}});drawToast(c, nowMs);return;}@@ -1785,7 +1851,10 @@ void AppUi::drawError(Canvas& c) {fonts_.regular.draw(c, line, panel.x + 56, y, 26, kGray);y += 38;}- drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconTouchpad, tr(Str::HoldSignOut)}});+ if (!errorGame_.productId.empty())+ drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconCircle, tr(Str::Back)}});+ else+ drawHints(c, {{kIconCross, tr(Str::TryAgain)}, {kIconTouchpad, tr(Str::HoldSignOut)}});}void AppUi::drawSettings(Canvas& c) {diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex ed7392a..65ce88b 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -140,11 +140,16 @@ public:void showDetails(const GameTile& tile);// The `index`-th game to buy, if loaded (autoplay tests).bool purchasableAt(size_t index, GameTile& out) const;+ // The game with this xCloud title id on the home screen or in Your games.+ bool findTile(const std::string& titleId, GameTile& out) const;void showHome(const std::string& toast = {});void showLaunching(const GameTile& game, const std::string& status);void setLaunchStatus(const std::string& status);void showStreaming();void showError(const std::string& message);+ // A game that could not start but may on another try (a free game got+ // on the phone meanwhile): Cross plays it again, Circle opens its page.+ void showPlayError(const std::string& message, const GameTile& game);void setSettings(const SettingsChoice& choice);// The confirm button in force (the hints show it); Settings may be// showing another choice not saved yet.@@ -273,6 +278,7 @@ private:GameTile detail_; // the game the details page showsGameTile launching_;std::string error_;+ GameTile errorGame_; // showPlayError()'s game; empty for other errorsSettingsChoice settings_;bool circleConfirms_ = false;PadSlots pads_{};diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex f28c003..61adec1 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -152,6 +152,11 @@ constexpr Column kEnglish = {"Light bar in the game's colour", // LightBar"Upscaling", // MenuUpscaler"AI (Anime4K)", // UpscalerAi+ "Free to play", // FreeToPlay+ "Get it once, free, on xbox.com or in the Xbox app (scan the code with your phone), then press Play.", // FreeHint+ "Scan to get it free", // ScanToGet+ "%s is not on your account yet. It is free: scan the code on its page, choose Get, then try again (it can take a minute).", // NoEntitlementFree+ "Your account can't play %s: it is not in your subscription or not bought.", // NoEntitlement};constexpr Column kPortugueseBR = {@@ -274,6 +279,11 @@ constexpr Column kPortugueseBR = {"Barra de luz com a cor do jogo","Ampliação","IA (Anime4K)",+ "Grátis para jogar",+ "Pegue uma vez, de graça, no xbox.com ou no app Xbox (escaneie o código com o celular) e depois aperte Jogar.",+ "Escaneie para pegar grátis",+ "%s ainda não está na sua conta. É grátis: escaneie o código na página do jogo, escolha Obter e tente de novo (pode levar um minuto).",+ "Sua conta não pode jogar %s: não está na sua assinatura ou não foi comprado.",};constexpr Column kSpanish = {@@ -396,6 +406,11 @@ constexpr Column kSpanish = {"Barra de luz con el color del juego","Escalado","IA (Anime4K)",+ "Gratis para jugar",+ "Consíguelo una vez, gratis, en xbox.com o en la app de Xbox (escanea el código con el móvil) y luego pulsa Jugar.",+ "Escanea para conseguirlo gratis",+ "%s aún no está en tu cuenta. Es gratis: escanea el código en su página, elige Obtener y vuelve a intentarlo (puede tardar un minuto).",+ "Tu cuenta no puede jugar a %s: no está en tu suscripción o no lo has comprado.",};constexpr Column kFrench = {@@ -518,6 +533,11 @@ constexpr Column kFrench = {"Barre lumineuse aux couleurs du jeu","Mise à l'échelle","IA (Anime4K)",+ "Gratuit",+ "Obtenez-le une fois, gratuitement, sur xbox.com ou dans l'app Xbox (scannez le code avec votre téléphone), puis appuyez sur Jouer.",+ "Scannez pour l'obtenir gratuitement",+ "%s n'est pas encore sur votre compte. Il est gratuit : scannez le code sur sa page, choisissez Obtenir, puis réessayez (cela peut prendre une minute).",+ "Votre compte ne peut pas jouer à %s : il n'est pas dans votre abonnement ou n'a pas été acheté.",};constexpr Column kGerman = {@@ -640,6 +660,11 @@ constexpr Column kGerman = {"Lichtleiste in der Farbe des Spiels","Hochskalierung","KI (Anime4K)",+ "Free-to-play",+ "Einmal kostenlos auf xbox.com oder in der Xbox-App holen (Code mit dem Handy scannen), dann Spielen drücken.",+ "Scannen, um es kostenlos zu holen",+ "%s ist noch nicht in deinem Konto. Es ist kostenlos: Code auf seiner Seite scannen, Abrufen wählen und erneut versuchen (kann eine Minute dauern).",+ "Dein Konto kann %s nicht spielen: nicht in deinem Abo oder nicht gekauft.",};constexpr Column kItalian = {@@ -762,6 +787,11 @@ constexpr Column kItalian = {"Barra luminosa con il colore del gioco","Upscaling","IA (Anime4K)",+ "Free to play",+ "Ottienilo una volta, gratis, su xbox.com o nell'app Xbox (scansiona il codice con il telefono), poi premi Gioca.",+ "Scansiona per ottenerlo gratis",+ "%s non è ancora nel tuo account. È gratis: scansiona il codice nella sua pagina, scegli Ottieni e riprova (può volerci un minuto).",+ "Il tuo account non può giocare a %s: non è nel tuo abbonamento o non è stato acquistato.",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 251e415..f68b4a4 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -129,6 +129,11 @@ enum class Str {LightBar, // settings: the light bar takes the game's colourMenuUpscaler, // game menu: how the picture is upscaled to 4KUpscalerAi, // the Anime4K network+ FreeToPlay, // details: a free-to-play game not on the account yet+ FreeHint,+ ScanToGet,+ NoEntitlementFree, // "%s" = the game+ NoEntitlement, // "%s" = the gameCount};diff --git a/src/xcloud/catalog.h b/src/xcloud/catalog.hindex 51bbac2..c7063ff 100644--- a/src/xcloud/catalog.h+++ b/src/xcloud/catalog.h@@ -31,6 +31,9 @@ constexpr const char* kRecentlyAdded = "06323672-b8c8-43cc-b0de-32d5a9834749";constexpr const char* kMostPopular = "6a589fa0-d493-472b-8e20-3813699d7056";constexpr const char* kLeavingSoon = "31ff2361-2772-4622-849b-f4f1abb4ad1b";constexpr const char* kAllGames = "af206485-e87d-4624-9007-cb7f6d0cc42e";+// "Stream free-to-play games": no Game Pass needed, but each must be on the+// account (a free "Get" in the store) before it starts.+constexpr const char* kFreeToPlay = "d8f4afcd-882a-49e3-86b3-f61fa0172b75";} // namespace siglstruct ProductList {diff --git a/tools/ps5/autotest.sh b/tools/ps5/autotest.shindex d36002e..6e3b44e 100755--- a/tools/ps5/autotest.sh+++ b/tools/ps5/autotest.sh@@ -37,7 +37,7 @@ import io, sysfrom ftplib import FTP, error_perm, error_replyhost, 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", "launch.ppm", "screen.ppm", "detail.ppm", "library.ppm", "library2.ppm"):+for name in ("xcloud.log", "frame.ppm", "frame2.ppm", "stream.aus", "ui.ppm", "launch.ppm", "screen.ppm", "detail.ppm", "library.ppm", "library2.ppm", "error.ppm"):try: f.sendcmd(f"DELE {name}")except (error_perm, error_reply): passf.storbinary("STOR autoplay.txt", io.BytesIO(line.encode() + b"\n"))@@ -82,7 +82,7 @@ PYif [[ $status != *"$title_id"* ]]; then result=crashed; break; fifidone-fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm screen.ppm detail.ppm library.ppm library2.ppm || true+fetch xcloud.log frame.ppm frame2.ppm stream.aus ui.ppm launch.ppm screen.ppm detail.ppm library.ppm library2.ppm error.ppm || truectl 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'