Xbox Cloud Gaming app for PS5 Homebrew
C
Quick wins: My games, MOBA, Xbox One/Series pairs, new games unlocked, gamerscore
Rafael Abud Ferreira29e79d2442e7
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex a426d2d..ba25393 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -83,6 +83,8 @@ void loadAutoplay() {if (opt == "confirmtest") g_autoplay.confirmTest = true;if (opt == "tunetest") g_autoplay.tuneTest = true;if (opt == "searchtest") g_autoplay.searchTest = true;+ if (opt == "quicktest") g_autoplay.quickTest = true;+ if (opt.rfind("locktitle=", 0) == 0) g_autoplay.lockTitle = opt.substr(10);if (opt == "norestart") g_autoplay.noRestart = true;if (opt.rfind("threads=", 0) == 0) g_autoplay.decodeThreads = std::atoi(opt.c_str() + 8);}@@ -436,6 +438,21 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {saveCanvas("home.ppm");XC_LOGI("AUTOPLAY END: confirm test, on the %s screen", g_ui->screen() == ui::Screen::Home ? "home" : "WRONG");}+ if (g_autoplay.quickTest && uiSaved) {+ g_autoplay.quickTest = false;+ ui::GameTile t;+ for (const char* id : {"HOGWARTSLEGACYXBOXSERIESXSVERSION", "HOGWARTSLEGACYXBOXONEVERSION"})+ XC_LOGI("quick: %s badge %s", id, g_ui->findTile(id, t) ? t.platform.c_str() : "(not found)");+ if (!g_autoplay.lockTitle.empty())+ XC_LOGI("quick: %s %s", g_autoplay.lockTitle.c_str(),+ !g_ui->findTile(g_autoplay.lockTitle, t) ? "not found" : t.playable ? "playable" : "LOCKED");+ g_ui->showFilteredSearch(ui::Tab::Library, false, 0, "MOBA", 0);+ size_t mine = g_ui->searchResults(500).size();+ g_ui->showFilteredSearch(ui::Tab::GamePass, false, 0, "MOBA", 0);+ XC_LOGI("quick: MOBA games: %zu in My games, %zu in Game Pass", mine, g_ui->searchResults(500).size());+ g_ui->showHome();+ XC_LOGI("AUTOPLAY END: quick test");+ }if (g_autoplay.searchTest && uiSaved) {// "Your games" by lowest price, then on sale, once the prices are in// (the background fetch): each saved, its first results logged.diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex a68268e..5931f3d 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -60,6 +60,8 @@ 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 quickTest = false; // quicktest: Hogwarts Legacy's badges, MOBA games, the lock on `lockTitle`+ std::string lockTitle; // locktitle=<xCloud title id>: logged playable or locked at oncebool searchTest = false; // searchtest: lowest price, Game Pass co-op + dubbed, the genres' list// (cheapest.ppm, filters.ppm, genres.ppm)bool tuneTest = false; // tunetest: the dead zone's stick tester and the trigger tester (sticks.ppm, triggers.ppm)diff --git a/src/app/library.cpp b/src/app/library.cppindex a076d14..bba71f0 100644--- a/src/app/library.cpp+++ b/src/app/library.cpp@@ -57,7 +57,7 @@ xcloud::Product productFromJson(const std::string& id, const json::Value& v) {p.tileUrl = v["tile"].str();p.posterUrl = v["poster"].str();p.heroUrl = v["hero"].str();- for (const auto& c : v["categories"].items()) p.categories.push_back(c.str());+ for (const auto& c : v["categories"].items()) p.categories.push_back(xcloud::categoryName(c.str()));p.detailed = v["d"].asBool(false);p.modes = static_cast<uint32_t>(v["modes"].asInt(0));for (const auto& [lang, bits] : v["langs"].members()) p.languages[lang] = static_cast<uint8_t>(bits.asInt(0));@@ -117,16 +117,24 @@ ui::GameTile Library::tile(const std::string& productId, const std::string& titlif (auto lang = p.languages.find(language_.substr(0, language_.find('-'))); lang != p.languages.end())t.languages = lang->second; // in the app's languageif (ownershipKnown_) t.playable = ownedTitles_.count(t.titleId) || ownedProducts_.count(t.productId);+ // Added to Game Pass since the last start: the account's list from then+ // doesn't have it yet. Not locked until this start's list arrives.+ if (!t.playable && !ownershipFresh_ && !knownGamePass_.empty() && gamePass_.count(productId) &&+ !knownGamePass_.count(productId))+ t.playable = true;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();+ sharedXbox_.clear();+ std::set<std::string> seen;for (const auto& [id, prod] : products_) {- if (!namesSeries(prod.title)) continue;auto xs = xboxTitleOf_.find(id);- seriesSiblings_.insert(xs != xboxTitleOf_.end() ? xs->second : prod.xboxTitleId);+ const std::string& xbox = xs != xboxTitleOf_.end() ? xs->second : prod.xboxTitleId;+ if (!xbox.empty() && !seen.insert(xbox).second) sharedXbox_.insert(xbox);+ if (namesSeries(prod.title)) seriesSiblings_.insert(xbox);}siblingsFor_ = products_.size();}@@ -136,7 +144,14 @@ ui::GameTile Library::tile(const std::string& productId, const std::string& titlif (pl != platform_.end()) t.platform = pl->second;// Cross-gen pairs ("Call of Duty: Vanguard" and "... - Xbox Series X|S")// are two cloud titles sharing one Xbox title id: the name tells them apart.- if (namesSeries(p.title)) t.platform = xcloud::kPlatformSeries;+ // The cloud title id names the version where the store's name doesn't+ // say it in English ("Hogwarts Legacy" / "... Versão Xbox One":+ // HOGWARTSLEGACYXBOXSERIESXSVERSION / ...XBOXONEVERSION).+ bool pair = sharedXbox_.count(xbox) > 0;+ if (pair && t.titleId.find("XBOXONE") != std::string::npos) t.platform = xcloud::kPlatformOne;+ else if (pair && (t.titleId.find("XBOXSERIES") != std::string::npos || t.titleId.find("SERIESXS") != std::string::npos))+ t.platform = xcloud::kPlatformSeries;+ else if (namesSeries(p.title)) t.platform = xcloud::kPlatformSeries;else if (t.platform == xcloud::kPlatformSeries && seriesSiblings_.count(xbox)) t.platform = xcloud::kPlatformOne;return t;}@@ -217,6 +232,7 @@ bool Library::loadCache() {for (const auto& id : (*j)["freeInStore"].items()) freeInStore_.insert(id.str());for (const auto& t : (*j)["ownedTitles"].items()) ownedTitles_.insert(t.str());for (const auto& p : (*j)["ownedProducts"].items()) ownedProducts_.insert(p.str());+ for (const auto& p : (*j)["gamePass"].items()) knownGamePass_.insert(p.str());owned_.clear();for (const auto& o : (*j)["owned"].items()) owned_.emplace_back(o["p"].str(), o["t"].str());purchasable_.clear();@@ -243,6 +259,9 @@ void Library::saveCache() const {root.set("ownedTitles", titles);root.set("ownedProducts", prods);root.set("owned", itemsToJson(owned_));+ json::Value gamePass = json::Value::array();+ for (const auto& id : allGames_) gamePass.push(id);+ root.set("gamePass", gamePass); // the next start tells the games added sinceroot.set("purchasable", itemsToJson(purchasable_));// Details of everything on the home screen, in "Your games" and in the// Game Pass search: the next launch shows them, hero art and all, before@@ -280,6 +299,8 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, constpopular_.clear();recent_.clear();ownershipKnown_ = false;+ ownershipFresh_ = false;+ knownGamePass_.clear();ownedTitles_.clear();ownedProducts_.clear();owned_.clear();@@ -436,6 +457,7 @@ void Library::loadOwned(xcloud::GssvClient gssv, const Changed& changed, const sXC_LOGW("%s", err.c_str());if (stop && *stop) return;ownedTitles_ = std::move(ownedTitles);+ ownershipFresh_ = true;ownedProducts_ = std::move(ownedProducts);owned_ = std::move(mine);purchasable_ = std::move(buy);diff --git a/src/app/library.h b/src/app/library.hindex 503cd21..8f45ae7 100644--- a/src/app/library.h+++ b/src/app/library.h@@ -106,6 +106,8 @@ private:std::vector<std::string> recent_; // recently played product ids, newest first// The account (loadOwned() or the cache).bool ownershipKnown_ = false;+ bool ownershipFresh_ = false; // the account's list of this start (not the cache's) is in+ std::set<std::string> knownGamePass_; // the Game Pass catalog at the last start (cache)std::set<std::string> ownedTitles_, ownedProducts_;std::vector<Item> owned_; // outside Game Passstd::vector<Item> purchasable_; // streamable once bought@@ -119,6 +121,7 @@ private:// Xbox title ids that have a "... - Xbox Series X|S" product, rebuilt// when products_ grows.mutable std::set<std::string> seriesSiblings_;+ mutable std::set<std::string> sharedXbox_; // Xbox title ids two products share (cross-gen pairs)mutable size_t siblingsFor_ = 0;};diff --git a/src/app/worker.cpp b/src/app/worker.cppindex 9b8013e..4f82bdf 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -468,7 +468,7 @@ void signInAndLoad(auth::AuthManager& am, xcloud::GssvClient& gssv) {XC_LOGI("AUTOPLAY END: consoles listed");return;}- g_ui->setProfile(am.profile().gamertag, am.profile().gamerpicUrl);+ g_ui->setProfile(am.profile().gamertag, am.profile().gamerpicUrl, am.profile().gamerscore);{std::lock_guard<std::mutex> lock(g_argMutex);g_xblAuth = am.profile().xblAuthorization;@@ -535,7 +535,7 @@ void loadLibrary(xcloud::GssvClient& gssv) {});if (!g_autoplay.title.empty() && g_autoplay.title != "BENCH" && g_autoplay.title != "UPDATE" && !g_autoplay.detailTest && !g_autoplay.libraryTest &&!g_autoplay.consolesTab && !g_autoplay.settingsTest &&- !g_autoplay.imeTest && !g_autoplay.vibeTest && !g_autoplay.searchTest) {+ !g_autoplay.imeTest && !g_autoplay.vibeTest && !g_autoplay.searchTest && !g_autoplay.quickTest) {platform::sleepMs(6000); // leave the home screen up for ui.ppmui::GameTile tile;tile.titleId = g_autoplay.title;diff --git a/src/auth/auth_manager.cpp b/src/auth/auth_manager.cppindex b4569e2..69e16d5 100644--- a/src/auth/auth_manager.cpp+++ b/src/auth/auth_manager.cpp@@ -132,7 +132,7 @@ bool AuthManager::loginOffering(xcloud::GssvClient& other, std::string& err) convoid AuthManager::fetchGamerpic(const XblToken& xsts) {net::Request req;- req.url = "https://profile.xboxlive.com/users/me/profile/settings?settings=GameDisplayPicRaw";+ req.url = "https://profile.xboxlive.com/users/me/profile/settings?settings=GameDisplayPicRaw,Gamerscore";req.headers = {{"Authorization", xsts.authorizationHeader()}, {"x-xbl-contract-version", "2"}};auto r = net::perform(req);auto j = json::parse(r.body);@@ -142,6 +142,7 @@ void AuthManager::fetchGamerpic(const XblToken& xsts) {}for (const auto& s : (*j)["profileUsers"][0]["settings"].items())if (s["id"].str() == "GameDisplayPicRaw") profile_.gamerpicUrl = s["value"].str();+ else if (s["id"].str() == "Gamerscore") profile_.gamerscore = s["value"].str();}bool AuthManager::signIn(xcloud::GssvClient& gssv, const DeviceCodeCallback& onCode, std::string& err,diff --git a/src/auth/auth_manager.h b/src/auth/auth_manager.hindex a82f9fa..4fe8a83 100644--- a/src/auth/auth_manager.h+++ b/src/auth/auth_manager.h@@ -19,6 +19,7 @@ struct Profile {std::string gamertag;std::string xuid;std::string gamerpicUrl; // empty until fetched+ std::string gamerscore; // digits; empty until fetched// "XBL3.0 x=...;token" for services on http://xboxlive.com (titlehub...).// Memory only: never logged or saved.std::string xblAuthorization;diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex ea90144..a88800f 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -175,10 +175,11 @@ void AppUi::showSignIn(const std::string& code, const std::string& url) {dirty_ = true;}-void AppUi::setProfile(const std::string& gamertag, const std::string& gamerpicUrl) {+void AppUi::setProfile(const std::string& gamertag, const std::string& gamerpicUrl, const std::string& gamerscore) {std::lock_guard<std::mutex> lock(mutex_);gamertag_ = gamertag;gamerpicUrl_ = gamerpicUrl;+ gamerscore_ = gamerscore;dirty_ = true;}@@ -1604,8 +1605,25 @@ void AppUi::drawTopBar(Canvas& c) {c.fillCircle(x + kAvatar / 2.0f, 72, kAvatar / 2.0f, kPanel);}if (!gamertag_.empty()) {+ // The name, and the gamerscore under it (a "G" badge and the number,+ // its thousands grouped as the language writes them).+ bool score = !gamerscore_.empty();int w = fonts_.semibold.measure(gamertag_, 22);- fonts_.semibold.draw(c, gamertag_, x - 16 - w, 59, 22, kWhite);+ fonts_.semibold.draw(c, gamertag_, x - 16 - w, score ? 46 : 59, 22, kWhite);+ if (score) {+ std::string n;+ const char* sep = language() == Language::English ? "," : ".";+ for (size_t i = 0; i < gamerscore_.size(); ++i) {+ if (i && (gamerscore_.size() - i) % 3 == 0) n += sep;+ n += gamerscore_[i];+ }+ int nw = fonts_.semibold.measure(n, 18);+ int nx = x - 16 - nw;+ fonts_.semibold.draw(c, n, nx, 76, 18, kGray);+ float gx = nx - 14.0f, gy = 86;+ c.strokeArc(gx, gy, 9, 2, 0, 6.2832f, kGray);+ fonts_.bold.draw(c, "G", static_cast<int>(gx) - fonts_.bold.measure("G", 12) / 2, static_cast<int>(gy) - 8, 12, kGray);+ }}}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex d79a88b..d453052 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -138,7 +138,8 @@ public:// --- Model -------------------------------------------------------------void showSplash(const std::string& status);void showSignIn(const std::string& code, const std::string& url);- void setProfile(const std::string& gamertag, const std::string& gamerpicUrl);+ // The signed-in account, top right; `gamerscore` (digits) under the name.+ void setProfile(const std::string& gamertag, const std::string& gamerpicUrl, const std::string& gamerscore = {});// Replaces the rows, keeping the focus on the same game when possible.void setRows(std::vector<GameRow> rows);// "Your games": the account's games, then those to buy; `known` false@@ -334,7 +335,7 @@ private:bool dirty_ = true;std::string status_;std::string code_, codeUrl_;- std::string gamertag_, gamerpicUrl_;+ std::string gamertag_, gamerpicUrl_, gamerscore_;std::vector<GameRow> rows_;int focusRow_ = 0;std::vector<int> focusCol_;diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex bb3c828..9fe7c5d 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -76,7 +76,7 @@ constexpr Column kEnglish = {"Could not load the game list: %s", // LibraryFailed"Could not start the stream: %s", // StreamFailed"No input for a while: you will be disconnected in %s seconds", // IdleWarning- "Your games", // YourGames+ "My games", // YourGames"Not available on your account", // NotPlayable"Game Pass", // TabGamePass"Search", // TabSearch@@ -92,7 +92,7 @@ constexpr Column kEnglish = {"Available to buy", // AvailableToBuy"BUY", // BuyBadge"Buy this game to play it in the cloud", // BuyToPlay- "Buy it on xbox.com or in the Xbox app; it then shows up in Your games.", // BuyHint+ "Buy it on xbox.com or in the Xbox app; it then shows up in My games.", // BuyHint"Scan to open the store page", // ScanToBuy"Search in %s", // SearchIn"FREE", // Free@@ -272,7 +272,7 @@ constexpr Column kPortugueseBR = {"Não foi possível carregar a lista de jogos: %s","Não foi possível iniciar o streaming: %s","Sem atividade: você será desconectado em %s segundos",- "Seus jogos",+ "Meus jogos","Indisponível na sua conta","Game Pass","Pesquisar",@@ -288,7 +288,7 @@ constexpr Column kPortugueseBR = {"Disponíveis para comprar","COMPRAR","Compre este jogo para jogá-lo na nuvem",- "Compre em xbox.com ou no app Xbox; depois ele aparece em Seus jogos.",+ "Compre em xbox.com ou no app Xbox; depois ele aparece em Meus jogos.","Escaneie para abrir a página da loja","Pesquisar em %s","GRÁTIS",@@ -468,7 +468,7 @@ constexpr Column kSpanish = {"No se pudo cargar la lista de juegos: %s","No se pudo iniciar el streaming: %s","Sin actividad: se te desconectará en %s segundos",- "Tus juegos",+ "Mis juegos","No disponible en tu cuenta","Game Pass","Buscar",@@ -484,7 +484,7 @@ constexpr Column kSpanish = {"Disponibles para comprar","COMPRAR","Compra este juego para jugarlo en la nube",- "Cómpralo en xbox.com o en la app de Xbox; luego aparecerá en Tus juegos.",+ "Cómpralo en xbox.com o en la app de Xbox; luego aparecerá en Mis juegos.","Escanea para abrir la página de la tienda","Buscar en %s","GRATIS",@@ -664,7 +664,7 @@ constexpr Column kFrench = {"Impossible de charger la liste des jeux : %s","Impossible de démarrer le streaming : %s","Aucune activité : vous serez déconnecté dans %s secondes",- "Vos jeux",+ "Mes jeux","Indisponible sur votre compte","Game Pass","Rechercher",@@ -680,7 +680,7 @@ constexpr Column kFrench = {"Disponibles à l'achat","ACHETER","Achetez ce jeu pour y jouer dans le cloud",- "Achetez-le sur xbox.com ou dans l'app Xbox ; il apparaîtra ensuite dans Vos jeux.",+ "Achetez-le sur xbox.com ou dans l'app Xbox ; il apparaîtra ensuite dans Mes jeux.","Scannez pour ouvrir la page du magasin","Rechercher dans %s","GRATUIT",@@ -860,7 +860,7 @@ constexpr Column kGerman = {"Die Spieleliste konnte nicht geladen werden: %s","Das Streaming konnte nicht gestartet werden: %s","Keine Aktivität: Die Verbindung wird in %s Sekunden getrennt",- "Deine Spiele",+ "Meine Spiele","Für dein Konto nicht verfügbar","Game Pass","Suchen",@@ -876,7 +876,7 @@ constexpr Column kGerman = {"Zum Kaufen verfügbar","KAUFEN","Kaufe dieses Spiel, um es in der Cloud zu spielen",- "Kaufe es auf xbox.com oder in der Xbox-App; danach erscheint es unter Deine Spiele.",+ "Kaufe es auf xbox.com oder in der Xbox-App; danach erscheint es unter Meine Spiele.","Scannen, um die Store-Seite zu öffnen","Suchen in %s","KOSTENLOS",@@ -1056,7 +1056,7 @@ constexpr Column kItalian = {"Impossibile caricare l'elenco dei giochi: %s","Impossibile avviare lo streaming: %s","Nessuna attività: verrai disconnesso tra %s secondi",- "I tuoi giochi",+ "I miei giochi","Non disponibile sul tuo account","Game Pass","Cerca",@@ -1072,7 +1072,7 @@ constexpr Column kItalian = {"Disponibili per l'acquisto","ACQUISTA","Acquista questo gioco per giocarci nel cloud",- "Acquistalo su xbox.com o nell'app Xbox; poi apparirà in I tuoi giochi.",+ "Acquistalo su xbox.com o nell'app Xbox; poi apparirà in I miei giochi.","Scansiona per aprire la pagina dello store","Cerca in %s","GRATIS",diff --git a/src/xcloud/catalog.cpp b/src/xcloud/catalog.cppindex be035ae..c53c31b 100644--- a/src/xcloud/catalog.cpp+++ b/src/xcloud/catalog.cpp@@ -82,7 +82,7 @@ bool fetchProducts(const std::vector<std::string>& ids, const std::string& markeprod.posterUrl = imageUrl(p["Image_Poster"]);prod.heroUrl = imageUrl(p["Image_Hero"]);if (prod.heroUrl.empty()) prod.heroUrl = imageUrl(p["Image_TitledHero"]);- for (const auto& c : p["LocalizedCategories"].items()) prod.categories.push_back(c.str());+ for (const auto& c : p["LocalizedCategories"].items()) prod.categories.push_back(categoryName(c.str()));if (full) {// How it can be played, from the store's attributes.prod.detailed = true;@@ -113,4 +113,15 @@ bool fetchProducts(const std::vector<std::string>& ids, const std::string& markereturn true;}+std::string categoryName(const std::string& storeName) {+ static const char* const kMoba[] = {"Multi-Player Online Battle Arena", "Multi-player Online Battle Arena",+ "Arena de batalha online para vários jogadores",+ "Campo de batalla en línea para varios jugadores",+ "Arène de combat multijoueur en ligne", "Multiplayer-Onlinekampfarena",+ "Arena per combattimenti online multiplayer"};+ for (const char* name : kMoba)+ if (storeName == name) return "MOBA";+ return storeName;+}+} // namespace xc::xclouddiff --git a/src/xcloud/catalog.h b/src/xcloud/catalog.hindex 50dfbf5..5507141 100644--- a/src/xcloud/catalog.h+++ b/src/xcloud/catalog.h@@ -53,6 +53,11 @@ struct ProductList {std::vector<std::string> productIds;};+// A genre as the app shows it: the store's long name for multiplayer online+// battle arenas, in any of the app's languages, becomes "MOBA" (the name+// players use); the others stay as the store has them.+std::string categoryName(const std::string& storeName);+bool fetchList(const std::string& siglId, const std::string& market, const std::string& language, ProductList& out,std::string& err);// Details for `ids` (batched); products the catalog does not know are absent.