Xbox Cloud Gaming app for PS5 Homebrew
C
Buy page: price, description and a large QR code; no browser button
Rafael Abud Ferreira09fa0b7c15ad
diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 27cd245..db81827 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -360,6 +360,14 @@ int cmdUiPreview(auth::AuthManager& am, const std::string& dir) {}save("library_buy", 3000);press([](ui::NavInput& n) { n.accept = true; }, 1);+ if (std::string id = app.detailWanted(); !id.empty()) { // as the app's price thread does+ std::map<std::string, xcloud::Product> full;+ std::string e;+ if (xcloud::fetchProducts({id}, gssv.session().market.empty() ? "US" : gssv.session().market,+ ui::catalogLanguage(), full, e, true) &&+ full.count(id))+ app.setDetailInfo(id, full[id].description, full[id].publisher, full[id].categories);+ }save("details_buy", 2000);press([](ui::NavInput& n) { n.back = true; }, 1);press([](ui::NavInput& n) { n.triangle = true; }, 1); // "Your games" searchdiff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex 631bfd5..3a9b99e 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -75,8 +75,7 @@ app::StreamPlayer* g_player = nullptr;// in, plays that title for that long (pressing A at 15 s and 20 s), saves// decoded frames and logs "AUTOPLAY END". Options, comma-separated: nosimd,// dump, repeat, idle (no A presses), threads=N (H.264 decoder threads),-// rumbletest (rumbles the pad for 1.5 s at start), browsertest (opens a-// store page in the browser).+// rumbletest (rumbles the pad for 1.5 s at start).// The title "BENCH" decodes <dataDir>/sample.h264 instead.std::string g_autoplayTitle;@@ -105,7 +104,6 @@ void loadAutoplay() {if (opt == "repeat") g_autoplayRuns = 2;if (opt == "idle") g_autoplayIdle = true;if (opt == "rumbletest") input::setRumble(200, 200, 1500);- if (opt == "browsertest") platform::openUrl(ui::storeUrl("BX3M8L83BBRW"));if (opt.rfind("threads=", 0) == 0) g_decodeThreads = std::atoi(opt.c_str() + 8);}g_autoplayTitle = title;@@ -333,7 +331,8 @@ std::string g_xblAuth;// --- Store prices ---------------------------------------------------------------// Asked for the games to buy as they come on screen; kept a day in-// <dataDir>/prices.json.+// <dataDir>/prices.json. The same thread fetches the description of an+// opened game that has none yet.std::mutex g_priceMutex;std::string g_priceMarket, g_priceLanguage; // set by loadLibrary()platform::Thread g_priceThread;@@ -374,6 +373,16 @@ void priceLoop() {market = g_priceMarket;language = g_priceLanguage;}+ // The open page's description, for games that only have the light+ // catalog data (games to buy, search results).+ if (std::string id = market.empty() ? std::string() : g_ui->detailWanted(); !id.empty()) {+ std::map<std::string, xcloud::Product> full;+ std::string err;+ if (xcloud::fetchProducts({id}, market, language, full, err, true) && full.count(id)) {+ const auto& p = full[id];+ g_ui->setDetailInfo(id, p.description, p.publisher, p.categories);+ }+ }std::vector<std::string> ids = market.empty() ? std::vector<std::string>() : g_ui->pricesWanted(20);if (ids.empty()) {platform::sleepMs(300);@@ -692,12 +701,6 @@ int main(int argc, char** argv) {break;case ui::Action::Retry: g_command = kSignIn; break;case ui::Action::CancelLaunch: g_cancel = true; break;- case ui::Action::OpenUrl:- // The browser is a heavy process next to this app: give it- // the decoded images (up to 160 MB; they come back from disk).- g_images->clear();- platform::openUrl(ev.url); // the result is logged- break;case ui::Action::SettingsChanged: {bool languageChanged;{diff --git a/src/platform/host/platform_host.cpp b/src/platform/host/platform_host.cppindex 21c7a76..fe93276 100644--- a/src/platform/host/platform_host.cpp+++ b/src/platform/host/platform_host.cpp@@ -86,9 +86,5 @@ bool resolveIPv4(const std::string& host, uint32_t& addr, std::string& err) {void probeNetworking() {}void notify(const std::string& text) { std::printf("\n>>> %s\n\n", text.c_str()); }-bool openUrl(const std::string& url) {- std::printf("\n>>> open %s\n\n", url.c_str());- return true;-}} // namespace xc::platformdiff --git a/src/platform/platform.h b/src/platform/platform.hindex 0c0d68f..65949a2 100644--- a/src/platform/platform.h+++ b/src/platform/platform.h@@ -47,9 +47,6 @@ bool startThread(Thread& t, std::function<void()> fn, size_t stackBytes = 8u <<// Short on-screen message (PS5 system notification / host stdout).void notify(const std::string& text);-// Opens `url` in the console's web browser (the app keeps running behind-// it). False if the system refused.-bool openUrl(const std::string& url);bool readFile(const std::string& path, std::string& out);bool writeFileAtomic(const std::string& path, const std::string& data);diff --git a/src/platform/ps5/platform_ps5.cpp b/src/platform/ps5/platform_ps5.cppindex 84067a1..ae313d7 100644--- a/src/platform/ps5/platform_ps5.cpp+++ b/src/platform/ps5/platform_ps5.cpp@@ -23,7 +23,6 @@ int sceNetPoolCreate(const char* name, int size, int flags);int sceNetResolverCreate(const char* name, int memid, int flags);int sceNetResolverStartNtoa(int rid, const char* hostname, uint32_t* addr, int timeout, int retry, int flags);int sceNetResolverDestroy(int rid);-int sceSystemServiceLaunchWebBrowser(const char* uri, void* param);}namespace xc::platform {@@ -121,11 +120,4 @@ void notify(const std::string& text) {sceKernelSendNotificationRequest(0, &req, sizeof req, 0);}-bool openUrl(const std::string& url) {- // As PS5_PayloadSDK's samples/browser.- int rc = sceSystemServiceLaunchWebBrowser(url.c_str(), nullptr);- XC_LOGI("browser %s: 0x%08x", url.c_str(), rc);- return rc == 0;-}-} // namespace xc::platformdiff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex de1c2fb..7b37573 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -99,8 +99,6 @@ constexpr uint64_t kSignOutHoldMs = 5000;} // namespace-std::string storeUrl(const std::string& productId) { return "https://www.xbox.com/games/store/p/" + productId; }-std::string prettyRegion(const std::string& name) {static const char* kWords[] = {"SOUTHEAST", "NORTHEAST", "CENTRAL", "AUSTRALIA", "GERMANY", "EUROPE", "BRAZIL","CANADA", "FRANCE", "MEXICO", "SWEDEN", "JAPAN", "KOREA", "INDIA", "NORTH",@@ -269,6 +267,22 @@ std::vector<std::string> AppUi::pricesWanted(size_t max) {return out;}+std::string AppUi::detailWanted() {+ std::lock_guard<std::mutex> lock(mutex_);+ if (screen_ != Screen::Details || detail_.productId.empty() || !detail_.description.empty()) return {};+ return detailsAsked_.insert(detail_.productId).second ? detail_.productId : std::string();+}++void AppUi::setDetailInfo(const std::string& productId, const std::string& description, const std::string& publisher,+ const std::vector<std::string>& categories) {+ std::lock_guard<std::mutex> lock(mutex_);+ if (detail_.productId != productId) return;+ if (!description.empty()) detail_.description = description;+ if (!publisher.empty()) detail_.publisher = publisher;+ if (!categories.empty()) detail_.categories = categories;+ dirty_ = true;+}+const GameTile* AppUi::libraryTile(int index) const {if (index < 0) return nullptr;size_t i = static_cast<size_t>(index);@@ -648,9 +662,6 @@ UiEvent AppUi::handle(const NavInput& in) {if (in.accept && detail_.playable && !detail_.titleId.empty()) {ev.action = Action::Play;ev.game = detail_;- } else if (in.accept && detail_.purchasable) { // to the store, in the browser- ev.action = Action::OpenUrl;- ev.url = storeUrl(detail_.productId);}if (in.back) {screen_ = Screen::Home;@@ -1151,8 +1162,10 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {if (!drawHero(c, nowMs, g->heroUrl, true)) {// No hero art (yet): the cover, until the art arrives and fades in.drawBackground(c);- if (auto img = images_.get(g->tileUrl, kCover, kCover)) c.drawImage(*img, cover.x, cover.y, 255, 16);- else c.fillRect(cover, kPlaceholder, 16);+ if (!g->purchasable) { // a game to buy has its QR code there instead+ if (auto img = images_.get(g->tileUrl, kCover, kCover)) c.drawImage(*img, cover.x, cover.y, 255, 16);+ else c.fillRect(cover, kPlaceholder, 16);+ }}drawTopBar(c);int y = 260;@@ -1178,51 +1191,47 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {y += 34;}if (g->purchasable) {- // Streams once bought: say where to buy it, with a QR code of the- // store page for the phone.+ // Streams once bought: the price and how to buy it on the left, a+ // large QR code of the store page (for the phone) on the right. The+ // console's browser can't run the xbox.com store, so no button.+ int ty = y + 30;auto price = prices_.find(g->productId);- int ny = std::max(y + (price != prices_.end() ? 120 : 40), 600);if (price != prices_.end()) {// The price, and the regular one crossed out while on sale.int px = kMargin;- fonts_.bold.draw(c, price->second.first, px, ny - 70, 44, kWhite);- px += fonts_.bold.measure(price->second.first, 44) + 20;+ fonts_.bold.draw(c, price->second.first, px, ty, 52, kWhite);+ px += fonts_.bold.measure(price->second.first, 52) + 24;if (!price->second.second.empty()) {- int w = fonts_.semibold.measure(price->second.second, 28);- fonts_.semibold.draw(c, price->second.second, px, ny - 58, 28, kDim);- c.line(static_cast<float>(px), static_cast<float>(ny - 42), static_cast<float>(px + w),- static_cast<float>(ny - 42), 2, kDim);+ int w = fonts_.semibold.measure(price->second.second, 30);+ fonts_.semibold.draw(c, price->second.second, px, ty + 14, 30, kDim);+ c.line(static_cast<float>(px), static_cast<float>(ty + 32), static_cast<float>(px + w),+ static_cast<float>(ty + 32), 2, kDim);}+ ty += 84;}- // A button (focused, like Play): opens the store page in the browser.- Rect note{kMargin, ny, 620, 76};- c.strokeRect({note.x - 7, note.y - 7, note.w + 14, note.h + 14}, kWhite, 4, 45);- c.fillRect(note, rgba(16, 124, 16, 255), 38);- drawBag(c, note.x + 50, note.y + note.h / 2, kWhite);- fonts_.semibold.draw(c, tr(Str::BuyToPlay), note.x + 86, note.y + 22, 26, kWhite);- auto hint = fonts_.regular.wrap(tr(Str::BuyHint), 22, 760, 2);- for (size_t i = 0; i < hint.size(); ++i)- fonts_.regular.draw(c, hint[i], kMargin, ny + 100 + static_cast<int>(i) * 32, 22, kGray);- std::string url = storeUrl(g->productId);+ 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];if (qrcodegen_encodeText(url.c_str(), tmp, qr, qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN,qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true)) {- // Under the cover, centred, on a dark panel with its caption.int n = qrcodegen_getSize(qr);- int module = 220 / (n + 2), size = module * (n + 2);- int w = fonts_.regular.measure(tr(Str::ScanToBuy), 20);- Rect panel{cover.x + (cover.w - std::max(size + 40, w + 40)) / 2, cover.y + cover.h + 24,- std::max(size + 40, w + 40), size + 76};- c.fillRect(panel, rgba(20, 20, 20, 235), 18);- Rect box{panel.x + (panel.w - size - 20) / 2, panel.y + 14, size + 20, size + 20};- c.fillRect(box, kWhite, 12);- int ox = box.x + 10 + module, oy = box.y + 10 + module;+ int module = 440 / (n + 2), size = module * (n + 2);+ Rect box{kW - kMargin - size - 40, 190, size + 40, size + 40};+ c.fillRect(box, kWhite, 20);+ int ox = box.x + 20 + module, oy = box.y + 20 + module;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);- fonts_.regular.draw(c, tr(Str::ScanToBuy), panel.x + (panel.w - w) / 2, box.y + box.h + 12, 20, kGray);+ 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);}- drawHints(c, {{kIconCross, tr(Str::OpenStore)}, {kIconCircle, tr(Str::Back)}});+ drawHints(c, {{kIconCircle, tr(Str::Back)}});return;}if (!g->playable) {diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 7578967..5406e2a 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -66,18 +66,14 @@ struct SettingsChoice {std::string region; // gssv region name; empty = automatic};-enum class Action { None, Play, SignOut, Retry, CancelLaunch, SettingsChanged, OpenUrl };+enum class Action { None, Play, SignOut, Retry, CancelLaunch, SettingsChanged };struct UiEvent {Action action = Action::None;GameTile game;SettingsChoice settings; // SettingsChanged- std::string url; // OpenUrl};-// The store page of a product, for the browser or a phone.-std::string storeUrl(const std::string& productId);-// "SOUTHCENTRALUS" -> "South Central US".std::string prettyRegion(const std::string& name);@@ -103,6 +99,12 @@ public:// Games to buy on screen (or about to be) whose price hasn't been asked// for yet; marks them asked.std::vector<std::string> pricesWanted(size_t max);+ // The game whose page is open, if its description hasn't arrived: asked+ // once per game (empty otherwise).+ std::string detailWanted();+ // Fills in the open page when it shows `productId`.+ void setDetailInfo(const std::string& productId, const std::string& description, const std::string& publisher,+ const std::vector<std::string>& categories);void showHome(const std::string& toast = {});void showLaunching(const GameTile& game, const std::string& status);void setLaunchStatus(const std::string& status);@@ -205,7 +207,7 @@ private:std::string defaultRegion_;std::map<std::string, int> regionMs_;std::map<std::string, std::pair<std::string, std::string>> prices_;- std::set<std::string> pricesAsked_;+ std::set<std::string> pricesAsked_, detailsAsked_;int settingsRow_ = 0;uint64_t signOutHoldStart_ = 0; // TOUCHPAD hold in progressbool signOutLatched_ = false; // fired; wait for releasediff --git a/src/ui/image_cache.cpp b/src/ui/image_cache.cppindex 5adf9cb..85e4260 100644--- a/src/ui/image_cache.cpp+++ b/src/ui/image_cache.cpp@@ -103,15 +103,6 @@ std::shared_ptr<const Image> ImageCache::get(const std::string& url, int w, intreturn e.image;}-void ImageCache::clear() {- std::lock_guard<std::mutex> lock(mutex_);- size_t freed = bytes_;- for (auto it = entries_.begin(); it != entries_.end();)- it = it->second.loading ? std::next(it) : entries_.erase(it);- bytes_ = 0;- XC_LOGI("image cache: %zu MB freed", freed >> 20);-}-void ImageCache::evict() {// Caller holds mutex_.while (bytes_ > budget_) {diff --git a/src/ui/image_cache.h b/src/ui/image_cache.hindex f82900d..6cd9e89 100644--- a/src/ui/image_cache.h+++ b/src/ui/image_cache.h@@ -37,9 +37,6 @@ public:// The image scaled to w x h, or nullptr while it loads (or if it failed).std::shared_ptr<const Image> get(const std::string& url, int w, int h);- // Drops every decoded image (they reload from disk on demand): memory for- // another process, such as the web browser.- void clear();private:struct Entry {diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 8801b3e..8f4380d 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -96,7 +96,6 @@ constexpr Column kEnglish = {"Scan to open the store page", // ScanToBuy"Search in %s", // SearchIn"FREE", // Free- "Open in the store", // OpenStore};constexpr Column kPortugueseBR = {@@ -163,7 +162,6 @@ constexpr Column kPortugueseBR = {"Escaneie para abrir a página da loja","Pesquisar em %s","GRÁTIS",- "Abrir na loja",};constexpr Column kSpanish = {@@ -230,7 +228,6 @@ constexpr Column kSpanish = {"Escanea para abrir la página de la tienda","Buscar en %s","GRATIS",- "Abrir en la tienda",};constexpr Column kFrench = {@@ -297,7 +294,6 @@ constexpr Column kFrench = {"Scannez pour ouvrir la page du magasin","Rechercher dans %s","GRATUIT",- "Ouvrir dans le magasin",};constexpr Column kGerman = {@@ -364,7 +360,6 @@ constexpr Column kGerman = {"Scannen, um die Store-Seite zu öffnen","Suchen in %s","KOSTENLOS",- "Im Store öffnen",};constexpr Column kItalian = {@@ -431,7 +426,6 @@ constexpr Column kItalian = {"Scansiona per aprire la pagina dello store","Cerca in %s","GRATIS",- "Apri nello store",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex f0458f9..1123020 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -73,7 +73,6 @@ enum class Str {ScanToBuy,SearchIn, // "%s" = tab nameFree, // price 0 (free-to-play games still "bought" in the store)- OpenStore, // hint: open the store page in the browserCount};