Xbox Cloud Gaming app for PS5 Homebrew
C
Remote Play probe: the account's consoles, and streaming one (autotest)
Rafael Abud Ferreira96776c74863b
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex 0cfa6a4..31d5837 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -158,6 +158,7 @@ int g_autoplaySeconds = 0;bool g_autoplayDump = false;int g_autoplayRuns = 1;bool g_autoplayIdle = false;+bool g_autoplayConsoles = false; // autoplay "consoles": log the account's own consoles (xhome)bool g_autoplayPad = false; // autoplay "pad": the physical pad stays in use, its buttons loggedbool g_autoplayDetailTest = false; // open a game to buy far down the list, save its pagebool g_autoplayLibraryTest = false; // open "Your games", save it at 4 s and 25 s@@ -204,6 +205,7 @@ void loadAutoplay() {if (opt == "nopace") display::gpu::setPresentWait(false);if (opt == "detailtest") g_autoplayDetailTest = true;if (opt == "pad") g_autoplayPad = true;+ if (opt == "consoles") g_autoplayConsoles = true;if (opt == "librarytest") g_autoplayLibraryTest = true;if (opt == "imetest") g_autoplayImeTest = true;if (opt == "menutest") g_autoplayMenuTest = true;@@ -384,7 +386,9 @@ std::string stream(xcloud::GssvClient& gssv) {std::string play(auth::AuthManager& am, xcloud::GssvClient& gssv, const ui::GameTile& game, bool& failed,const std::string& regionName = {}) {failed = true;- XC_LOGI("starting %s (%s)", game.name.c_str(), game.titleId.c_str());+ // A home session's id is the console's: only its start in the log.+ XC_LOGI("starting %s (%s)", game.name.c_str(),+ gssv.isHome() ? (game.titleId.substr(0, 4) + "...").c_str() : game.titleId.c_str());g_ui->showLaunching(game, regionName.empty() ? ui::tr(ui::Str::Connecting): ui::trf(ui::Str::TryingRegion, ui::prettyRegion(regionName)));std::string err;@@ -556,6 +560,33 @@ void signInAndLoad(auth::AuthManager& am, xcloud::GssvClient& gssv) {if (!g_autoplayTitle.empty()) XC_LOGI("AUTOPLAY END: sign-in failed");return;}+ if (g_autoplayConsoles || g_autoplayTitle == "XHOME") {+ // Remote Play probe: the user's own consoles. Not their names nor+ // full ids in the log.+ xcloud::GssvClient home("xhome");+ std::vector<xcloud::Console> consoles;+ if (!am.loginOffering(home, err) || !home.listConsoles(consoles, err)) {+ XC_LOGI("AUTOPLAY END: consoles: %s", err.c_str());+ return;+ }+ XC_LOGI("xhome: %zu console(s), region %s", consoles.size(), home.region().name.c_str());+ for (const auto& c : consoles)+ XC_LOGI("xhome console %.4s...: %s, power %s, path %s%s%s", c.serverId.c_str(), c.consoleType.c_str(),+ c.powerState.c_str(), c.playPath.c_str(), c.outOfHomeWarning ? ", out-of-home warning" : "",+ c.wirelessWarning ? ", wireless warning" : "");+ if (g_autoplayTitle == "XHOME" && !consoles.empty()) {+ // Remote Play probe: stream the first console.+ ui::GameTile tile;+ tile.titleId = consoles.front().serverId;+ tile.name = "Xbox";+ bool failed = false;+ std::string result = play(am, home, tile, failed);+ XC_LOGI("AUTOPLAY END: xhome: %s", result.c_str());+ return;+ }+ XC_LOGI("AUTOPLAY END: consoles listed");+ return;+ }g_ui->setProfile(am.profile().gamertag, am.profile().gamerpicUrl);{std::lock_guard<std::mutex> lock(g_argMutex);diff --git a/src/auth/auth_manager.cpp b/src/auth/auth_manager.cppindex 193cbb1..a9ee3bb 100644--- a/src/auth/auth_manager.cpp+++ b/src/auth/auth_manager.cpp@@ -117,9 +117,16 @@ bool AuthManager::xboxChain(xcloud::GssvClient& gssv, std::string& err) {XC_LOGW("profile XSTS: %s", perr.c_str());}- XblToken gssvXsts;- if (!xstsToken(user, rp::kGssv, gssvXsts, err)) return false;- return gssv.login(gssvXsts, err);+ if (!xstsToken(user, rp::kGssv, gssvXsts_, err)) return false;+ return gssv.login(gssvXsts_, err);+}++bool AuthManager::loginOffering(xcloud::GssvClient& other, std::string& err) const {+ if (gssvXsts_.token.empty()) {+ err = "not signed in";+ return false;+ }+ return other.login(gssvXsts_, err);}void AuthManager::fetchGamerpic(const XblToken& xsts) {diff --git a/src/auth/auth_manager.h b/src/auth/auth_manager.hindex 652f841..a82f9fa 100644--- a/src/auth/auth_manager.h+++ b/src/auth/auth_manager.h@@ -43,6 +43,10 @@ public:// /connect step of cloud sessions.bool consoleTransferToken(std::string& out, std::string& err);+ // After signIn(): logs `other` (another offering, such as "xhome" for+ // the user's own consoles) in with the same Xbox token.+ bool loginOffering(xcloud::GssvClient& other, std::string& err) const;+void signOut();const Profile& profile() const { return profile_; }@@ -57,6 +61,7 @@ private:MsaClient msa_;MsaTokens tokens_;Profile profile_;+ XblToken gssvXsts_; // in memory only, for loginOffering()};} // namespace xc::authdiff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cppindex 0820a1f..3f5a643 100644--- a/src/stream/stream_session.cpp+++ b/src/stream/stream_session.cpp@@ -487,9 +487,9 @@ struct StreamSession::Impl {while (!c.empty() && (c.back() == ' ' || c.back() == '\r' || c.back() == '\n')) c.pop_back();try {pc->addRemoteCandidate(rtc::Candidate(c, mid));- XC_LOGD("remote candidate %s", c.c_str());+ XC_LOGD("remote candidate added"); // not its address} catch (const std::exception& e) {- XC_LOGW("ignoring remote candidate '%s': %s", c.c_str(), e.what());+ XC_LOGW("ignoring a remote candidate: %s", e.what());}}@@ -571,7 +571,8 @@ struct StreamSession::Impl {std::string ipv4;int port = 0;if (parts.size() > 4 && decodeTeredo(parts[4], ipv4, port)) {- XC_LOGI("teredo candidate -> %s:%d (and :9002)", ipv4.c_str(), port);+ // The console's public address: not in the log.+ XC_LOGI("teredo candidate -> port %d (and 9002)", port);addRemoteCandidate("a=candidate:10 1 UDP 1 " + ipv4 + " 9002 typ host", mid);addRemoteCandidate("a=candidate:11 1 UDP 1 " + ipv4 + " " + std::to_string(port) + " typ host", mid);}diff --git a/src/xcloud/gssv.cpp b/src/xcloud/gssv.cppindex 5f317ae..67effdd 100644--- a/src/xcloud/gssv.cpp+++ b/src/xcloud/gssv.cpp@@ -347,6 +347,28 @@ bool GssvClient::hydrateTitles(std::vector<Title>& titles, const std::string& mareturn true;}+bool GssvClient::listConsoles(std::vector<Console>& out, std::string& err) {+ out.clear();+ auto r = net::perform(authed(resolution_, login_, "GET", url("/v6/servers/home")));+ auto j = json::parse(r.body);+ if (!r.ok() || !j) {+ err = "console list failed: " + describe(r);+ return false;+ }+ for (const auto& c : (*j)["results"].items()) {+ Console con;+ con.serverId = c["serverId"].str();+ con.deviceName = c["deviceName"].str();+ con.consoleType = c["consoleType"].str();+ con.powerState = c["powerState"].str();+ con.playPath = c["playPath"].str();+ con.outOfHomeWarning = c["outOfHomeWarning"].asBool();+ con.wirelessWarning = c["wirelessWarning"].asBool();+ if (!con.serverId.empty()) out.push_back(std::move(con));+ }+ return true;+}+bool GssvClient::startSession(const std::string& titleId, const std::string& locale, std::string& err) {json::Value settings = json::Value::object();settings.set("nanoVersion", "V3;WebrtcTransport.dll");@@ -361,11 +383,12 @@ bool GssvClient::startSession(const std::string& titleId, const std::string& loc: "windows");json::Value body = json::Value::object();+ bool home = offering_ == "xhome";body.set("clientSessionId", "");- body.set("titleId", titleId);+ body.set("titleId", home ? "" : titleId);body.set("systemUpdateGroup", "");body.set("settings", settings);- body.set("serverId", "");+ body.set("serverId", home ? titleId : "");body.set("fallbackRegionNames", json::Value::array());std::string kind = offering_ == "xhome" ? "home" : "cloud";diff --git a/src/xcloud/gssv.h b/src/xcloud/gssv.hindex 057582a..d21c5e9 100644--- a/src/xcloud/gssv.h+++ b/src/xcloud/gssv.h@@ -44,6 +44,16 @@ struct Title {bool viaSubscription = false;};+// One of the user's own consoles (xhome offering), from /v6/servers/home.+struct Console {+ std::string serverId; // what a home session is started with+ std::string deviceName; // the name the user gave it+ std::string consoleType; // e.g. "XboxSeriesX"+ std::string powerState; // "On", "ConnectedStandby", "Off"...+ std::string playPath; // "Direct" (same network) or "Relay"...+ bool outOfHomeWarning = false, wirelessWarning = false;+};+enum class SessionState { Unknown, Provisioning, WaitingForResources, ReadyToConnect, Provisioned, Failed };struct SessionStatus {@@ -76,6 +86,7 @@ public:void setResolution(Resolution r) { resolution_ = r; }Resolution resolution() const { return resolution_; }const Region& region() const { return region_; }+ bool isHome() const { return offering_ == "xhome"; }// Titles available to stream (entitled + Game Pass) and recently played.bool listTitles(std::vector<Title>& out, std::string& err, bool recentOnly = false);@@ -83,7 +94,11 @@ public:bool hydrateTitles(std::vector<Title>& titles, const std::string& market, const std::string& lang,std::string& err);+ // The account's consoles that can stream (xhome offering).+ bool listConsoles(std::vector<Console>& out, std::string& err);+// --- Session lifecycle -------------------------------------------------+ // `titleId` for a cloud game; for the xhome offering, the console's serverId.bool startSession(const std::string& titleId, const std::string& locale, std::string& err);bool hasSession() const { return !sessionPath_.empty(); }bool sessionState(SessionStatus& out, std::string& err);