Xbox Cloud Gaming app for PS5 Homebrew
C
Profile: a drawn gamerscore badge and the Game Pass membership
Rafael Abud Ferreira46d8f1d94289
diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 3710eba..d6cb0a4 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -637,6 +637,33 @@ int main(int argc, char** argv) {app.showError(ui::tr(ui::Str::ConnectionIntercepted));save("tls_intercepted");return 0;+ } else if (cmd == "ui-profile" && argi < argc) {+ // Offline: the account at the top right: name, gamerscore badge,+ // Game Pass plan (and without a plan, and a long name).+ ui::Fonts fonts;+ if (!fonts.load("assets/fonts")) return 1;+ ui::ImageCache images([] {});+ ui::AppUi app(fonts, images);+ ui::Canvas canvas(1920, 1080);+ if (argi + 1 < argc) ui::setLanguage(ui::languageFromCode(argv[argi + 1]));+ auto save = [&](const std::string& name) {+ app.render(canvas, 1000);+ std::string path = std::string(argv[argi]) + "/" + name + ".png";+ stbi_write_png(path.c_str(), canvas.width(), canvas.height(), 4, canvas.data(), canvas.width() * 4);+ std::printf("wrote %s\n", path.c_str());+ };+ app.showHome();+ app.setProfile("PlayerOne", "", "173591");+ app.setSubscription("Ultimate");+ save("profile_ultimate");+ app.setSubscription("GamePass");+ save("profile_member");+ app.setSubscription("");+ save("profile_noplan");+ app.setProfile("AVeryLongGamertag", "", "1250");+ app.setSubscription("Essential");+ save("profile_long");+ return 0;} else if (cmd == "ui-report" && argi < argc) {// Offline: #38's error screen (Triangle: report), its report's QR// code (a real link, from a made-up log), and Settings' hints.diff --git a/src/app/library.cpp b/src/app/library.cppindex 2d76c63..4d782c4 100644--- a/src/app/library.cpp+++ b/src/app/library.cpp@@ -282,6 +282,7 @@ bool Library::loadCache() {for (const auto& [pid, xbox] : (*j)["xboxTitles"].members()) xboxTitleOf_[pid] = xbox.str();for (const auto& id : (*j)["freeInStore"].items()) freeInStore_.insert(id.str());for (const auto& t : (*j)["ownedTitles"].items()) ownedTitles_.insert(t.str());+ gamePassMember_ = (*j)["gamePassMember"].asBool();for (const auto& p : (*j)["ownedProducts"].items()) ownedProducts_.insert(p.str());for (const auto& p : (*j)["gamePass"].items()) knownGamePass_.insert(p.str());owned_.clear();@@ -312,6 +313,7 @@ void Library::saveCache() const {for (const auto& t : ownedTitles_) titles.push(t);for (const auto& p : ownedProducts_) prods.push(p);root.set("ownedTitles", titles);+ root.set("gamePassMember", gamePassMember_);root.set("ownedProducts", prods);root.set("owned", itemsToJson(owned_));json::Value gamePass = json::Value::array();@@ -480,7 +482,9 @@ void Library::loadOwned(xcloud::GssvClient gssv, const Changed& changed, const sstd::set<std::string> ownedTitles, ownedProducts;std::vector<Item> mine;std::map<std::string, std::string> toBuy; // productId -> titleId+ bool member = false;for (const auto& t : titles) {+ member |= t.hasEntitlement && t.viaSubscription;if (xcloud::isNonGameAddon(t.titleId)) continue;if (!t.productId.empty() && !t.xboxTitleId.empty()) xboxTitleOf_[t.productId] = t.xboxTitleId;if (t.isFreeInStore && !t.productId.empty()) freeInStore_.insert(t.productId);@@ -519,6 +523,7 @@ void Library::loadOwned(xcloud::GssvClient gssv, const Changed& changed, const spurchasableSet_.clear();for (const auto& p : purchasable_) purchasableSet_.insert(p.first);ownershipKnown_ = true;+ gamePassMember_ = member;sortOwned();saveCache();XC_LOGI("library: account can stream %zu titles; %zu outside Game Pass; %zu more to buy", ownedTitles_.size(),diff --git a/src/app/library.h b/src/app/library.hindex cfd36de..63ac2e9 100644--- a/src/app/library.h+++ b/src/app/library.h@@ -71,6 +71,9 @@ public:std::vector<ui::GameTile> librarySearchPool() const;// True once the account's games are known (from the cache or the service).bool ownedKnown() const { return ownershipKnown_; }+ // The account streams games through a Game Pass plan (titles it has by+ // a subscription's program, not bought nor free): its badge in the UI.+ bool gamePassMember() const { return gamePassMember_; }// The background refresh of the lists: whether it runs, and (while// names come in) how far it is; total 0 = no measure yet.struct Progress {@@ -109,6 +112,7 @@ private:std::vector<std::string> recent_; // recently played product ids, newest first// The account (loadOwned() or the cache).bool ownershipKnown_ = false;+ bool gamePassMember_ = false;bool ownershipFresh_ = false; // the account's list of this start (not the cache's) is instd::set<std::string> knownGamePass_; // the Game Pass catalog at the last start (cache)std::set<std::string> ownedTitles_, ownedProducts_;diff --git a/src/app/worker.cpp b/src/app/worker.cppindex cd43f8b..019fdcf 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -549,6 +549,7 @@ void loadLibrary(xcloud::GssvClient& gssv) {auto publish = [](const app::Library& lib) {g_ui->setRows(lib.rows());g_ui->setOwned(lib.owned(), lib.purchasable(), lib.ownedKnown());+ g_ui->setSubscription(lib.gamePassMember() ? "GamePass" : "");g_ui->setSearchPools(lib.gamePassSearchPool(), lib.librarySearchPool());auto p = lib.progress();g_ui->setLoading(p.active, p.done, p.total);@@ -656,6 +657,7 @@ void worker() {g_ui->setRows({});g_ui->setOwned({}, {}, false);g_ui->setSearchPools({}, {});+ g_ui->setSubscription("");XC_LOGI("signed out: library and its cache cleared");signInAndLoad(am, gssv);loadConsoles(am, home);diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 699f7e6..d87cd61 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -298,6 +298,12 @@ void AppUi::setProfile(const std::string& gamertag, const std::string& gamerpicUdirty_ = true;}+void AppUi::setSubscription(const std::string& plan) {+ std::lock_guard<std::mutex> lock(mutex_);+ subscription_ = plan;+ dirty_ = true;+}+void AppUi::setRows(std::vector<GameRow> rows) {std::lock_guard<std::mutex> lock(mutex_);allRows_ = std::move(rows);@@ -2138,6 +2144,17 @@ void AppUi::drawBackground(Canvas& c) {void AppUi::drawLogo(Canvas& c, float cx, float cy, float r) { drawBrandMark(c, cx, cy, r); }+void AppUi::drawGamerscoreBadge(Canvas& c, float cx, float cy, float r) {+ // A filled disc with a "G" cut out of it, drawn from shapes (a letter of+ // the font never sits in the middle of a circle): a ring open at the+ // upper right, and its bar from the centre to the ring.+ c.fillCircle(cx, cy, r, kGray);+ const float ring = r * 0.56f, t = r * 0.24f;+ const float kGap = 0.95f; // radians left open, above 3 o'clock+ c.strokeArc(cx, cy, ring, t, 0.0f, 6.2832f - kGap, kBg);+ c.line(cx + r * 0.05f, cy, cx + ring + t * 0.5f, cy, t, kBg);+}+void AppUi::drawTopBar(Canvas& c) {drawLogo(c, kMargin + 22, 72, 22);fonts_.semibold.draw(c, tr(Str::CloudGaming), kMargin + 64, 60, 22, kWhite);@@ -2150,27 +2167,44 @@ 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();+ // The name; under it the gamerscore (its badge and the number, the+ // thousands grouped as the language writes them) and the Game Pass+ // plan, right-aligned to the picture as the Xbox app shows them.+ bool second = !gamerscore_.empty() || !subscription_.empty();int w = fonts_.semibold.measure(gamertag_, 22);- fonts_.semibold.draw(c, gamertag_, x - 16 - w, score ? 46 : 59, 22, kWhite);- if (score) {+ fonts_.semibold.draw(c, gamertag_, x - 16 - w, second ? 44 : 59, 22, kWhite);+ int right = x - 16;+ constexpr int kLineY = 76, kLineH = 22, kLinePx = 17;+ const float midY = kLineY + kLineH / 2.0f;+ if (!subscription_.empty()) {+ // "GAME PASS", and the plan in an outlined box when it is known+ // ("GamePass": a member, the plan not known).+ int left = right;+ if (subscription_ != "GamePass") {+ std::string plan = subscription_;+ for (auto& ch : plan) ch = static_cast<char>(std::toupper(static_cast<unsigned char>(ch)));+ int pw = fonts_.bold.measure(plan, 11);+ Rect box{right - pw - 10, static_cast<int>(midY) - 8, pw + 10, 16};+ c.strokeRect(box, kGray, 1, 2);+ fonts_.bold.draw(c, plan, box.x + 5, fonts_.bold.centeredY(box.y, box.h, 11), 11, kGray);+ left = box.x - 6;+ }+ const char* gp = "GAME PASS";+ int gw = fonts_.semibold.measure(gp, 14);+ fonts_.semibold.draw(c, gp, left - gw, fonts_.semibold.centeredY(kLineY, kLineH, 14), 14, kGray);+ right = left - gw - 16;+ }+ if (!gamerscore_.empty()) {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.0f;- c.strokeCircle(gx, gy, 8.5f, 1.6f, kGray);- int gw = fonts_.bold.measure("G", 11);- int gxInt = static_cast<int>(std::round(gx)) - gw / 2;- int gyInt = fonts_.bold.centeredY(static_cast<int>(std::round(gy - 8.5f)), 17, 11);- fonts_.bold.draw(c, "G", gxInt, gyInt, 11, kGray);+ int nw = fonts_.semibold.measure(n, kLinePx);+ int nx = right - nw;+ fonts_.semibold.draw(c, n, nx, fonts_.semibold.centeredY(kLineY, kLineH, kLinePx), kLinePx, kGray);+ drawGamerscoreBadge(c, nx - 13.0f, midY, 8.5f);}}}diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 146e0ce..64cdfbf 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -170,6 +170,10 @@ public:void showSignIn(const std::string& code, const std::string& url);// 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 = {});+ // The account's Game Pass plan under the name ("Ultimate", "Premium",+ // "Essential"...; "GamePass" for a member whose plan isn't known); empty+ // for none (nothing shown).+ void setSubscription(const std::string& plan);std::string gamertag() const; // for keeping it out of reportsstd::vector<std::string> consoleNames() const; // the same: the user's names for their consoles// "Report a problem": a QR code of `url` (the GitHub bug form, filled@@ -301,6 +305,7 @@ private:bool drawHero(Canvas& c, uint64_t nowMs, const std::string& url, bool details);void drawTopBar(Canvas& c);void drawLogo(Canvas& c, float cx, float cy, float r);+ void drawGamerscoreBadge(Canvas& c, float cx, float cy, float r);void drawHints(Canvas& c, const std::vector<std::pair<int, const char*>>& hints);void drawSpinner(Canvas& c, float cx, float cy, float r, uint64_t nowMs);void drawToast(Canvas& c, uint64_t nowMs);@@ -394,7 +399,7 @@ private:bool dirty_ = true;std::string status_;std::string code_, codeUrl_;- std::string gamertag_, gamerpicUrl_, gamerscore_;+ std::string gamertag_, gamerpicUrl_, gamerscore_, subscription_;std::vector<GameRow> rows_;int focusRow_ = 0;std::vector<int> focusCol_;