Xbox Cloud Gaming app for PS5 Homebrew
C
Open the store page in the PS5 browser from a game to buy
Rafael Abud Ferreirae6f79483179e
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex e5d4c2c..709e978 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -75,7 +75,8 @@ 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).+// rumbletest (rumbles the pad for 1.5 s at start), browsertest (opens a+// store page in the browser).// The title "BENCH" decodes <dataDir>/sample.h264 instead.std::string g_autoplayTitle;@@ -104,6 +105,7 @@ 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;@@ -690,6 +692,9 @@ 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:+ 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 fe93276..21c7a76 100644--- a/src/platform/host/platform_host.cpp+++ b/src/platform/host/platform_host.cpp@@ -86,5 +86,9 @@ 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 65949a2..0c0d68f 100644--- a/src/platform/platform.h+++ b/src/platform/platform.h@@ -47,6 +47,9 @@ 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 ae313d7..84067a1 100644--- a/src/platform/ps5/platform_ps5.cpp+++ b/src/platform/ps5/platform_ps5.cpp@@ -23,6 +23,7 @@ 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 {@@ -120,4 +121,11 @@ 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 9907df9..de1c2fb 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -99,6 +99,8 @@ 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",@@ -646,6 +648,9 @@ 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;@@ -1189,14 +1194,16 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {static_cast<float>(ny - 42), 2, kDim);}}+ // A button (focused, like Play): opens the store page in the browser.Rect note{kMargin, ny, 620, 76};- c.fillRect(note, rgba(16, 124, 16, 235), 38);+ 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 = "https://www.xbox.com/games/store/p/" + g->productId;+ std::string url = storeUrl(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)) {@@ -1215,7 +1222,7 @@ void AppUi::drawDetails(Canvas& c, uint64_t nowMs) {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);}- drawHints(c, {{kIconCircle, tr(Str::Back)}});+ drawHints(c, {{kIconCross, tr(Str::OpenStore)}, {kIconCircle, tr(Str::Back)}});return;}if (!g->playable) {diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 0930298..7578967 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -66,14 +66,18 @@ struct SettingsChoice {std::string region; // gssv region name; empty = automatic};-enum class Action { None, Play, SignOut, Retry, CancelLaunch, SettingsChanged };+enum class Action { None, Play, SignOut, Retry, CancelLaunch, SettingsChanged, OpenUrl };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);diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 8f4380d..8801b3e 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -96,6 +96,7 @@ constexpr Column kEnglish = {"Scan to open the store page", // ScanToBuy"Search in %s", // SearchIn"FREE", // Free+ "Open in the store", // OpenStore};constexpr Column kPortugueseBR = {@@ -162,6 +163,7 @@ constexpr Column kPortugueseBR = {"Escaneie para abrir a página da loja","Pesquisar em %s","GRÁTIS",+ "Abrir na loja",};constexpr Column kSpanish = {@@ -228,6 +230,7 @@ constexpr Column kSpanish = {"Escanea para abrir la página de la tienda","Buscar en %s","GRATIS",+ "Abrir en la tienda",};constexpr Column kFrench = {@@ -294,6 +297,7 @@ constexpr Column kFrench = {"Scannez pour ouvrir la page du magasin","Rechercher dans %s","GRATUIT",+ "Ouvrir dans le magasin",};constexpr Column kGerman = {@@ -360,6 +364,7 @@ constexpr Column kGerman = {"Scannen, um die Store-Seite zu öffnen","Suchen in %s","KOSTENLOS",+ "Im Store öffnen",};constexpr Column kItalian = {@@ -426,6 +431,7 @@ 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 1123020..f0458f9 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -73,6 +73,7 @@ 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};