Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

Retry in another region when a game quits on the server at start

Rafael Abud Ferreira993ee4c64eba
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cpp
index c3f853e..6680d1d 100644
--- a/src/app/ps5_main.cpp
+++ b/src/app/ps5_main.cpp
@@ -22,6 +22,7 @@
#include <atomic>
#include <map>
+#include <strings.h>
#include <cstdio>
#include <memory>
#include <mutex>
@@ -148,8 +149,15 @@ std::string formatWait(int seconds) {
return std::to_string((seconds + 59) / 60) + " min";
}
+// Set by stream(): the game quit on the server before its first frame.
+bool g_gameClosedOnServer = false;
+// Titles that would not start in the automatic region, and where they did
+// (for the rest of this run).
+std::map<std::string, std::string> g_regionFallback;
+
// Streams until the player ends or the user leaves; returns a status line.
std::string stream(xcloud::GssvClient& gssv) {
+ g_gameClosedOnServer = false;
app::StreamPlayer player(gssv);
if (g_autoplayDump) player.dumpVideo(platform::dataDir() + "/stream.aus", 20);
player.setDecodeThreads(g_decodeThreads);
@@ -213,16 +221,22 @@ std::string stream(xcloud::GssvClient& gssv) {
auto st = player.stats();
// Ended before a single frame: the game never started (e.g. it closed on
// the server); say so on the error screen instead of going back quietly.
- if (st.decodedFrames == 0 && !g_cancel && !autoplayDone) return "ERROR: " + ui::trf(ui::Str::StreamFailed, reason);
+ if (st.decodedFrames == 0 && !g_cancel && !autoplayDone) {
+ g_gameClosedOnServer = reason.rfind("the game closed on the server", 0) == 0;
+ return "ERROR: " + ui::trf(ui::Str::StreamFailed, reason);
+ }
return "Stream ended (" + reason + "), " + std::to_string(st.decodedFrames) + " frames shown";
}
// Queue -> /connect -> Provisioned -> stream. Returns a status line; sets
// `failed` when the user should see an error rather than the home screen.
-std::string play(auth::AuthManager& am, xcloud::GssvClient& gssv, const ui::GameTile& game, bool& failed) {
+// `regionName` overrides the settings' region (empty: as set).
+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());
- g_ui->showLaunching(game, ui::tr(ui::Str::Connecting));
+ g_ui->showLaunching(game, regionName.empty() ? ui::tr(ui::Str::Connecting)
+ : ui::trf(ui::Str::TryingRegion, ui::prettyRegion(regionName)));
std::string err;
{
std::lock_guard<std::mutex> lock(g_settingsMutex);
@@ -230,8 +244,9 @@ std::string play(auth::AuthManager& am, xcloud::GssvClient& gssv, const ui::Game
: g_settings.resolution == "1440p" ? xcloud::Resolution::P1440
: xcloud::Resolution::P1080);
const xcloud::Region* region = gssv.session().defaultRegion();
+ const std::string& wanted = regionName.empty() ? g_settings.region : regionName;
for (const auto& r : gssv.session().regions)
- if (r.name == g_settings.region) region = &r;
+ if (r.name == wanted) region = &r;
if (region) gssv.setRegion(*region);
XC_LOGI("stream settings: %s, region %s, locale %s", g_settings.resolution.c_str(),
region ? region->name.c_str() : "?", ui::gameLocale());
@@ -389,8 +404,29 @@ void worker() {
tile = g_playTile;
}
bool failed = false;
- std::string result = play(am, gssv, tile, failed);
+ bool automatic;
+ {
+ std::lock_guard<std::mutex> lock(g_settingsMutex);
+ automatic = g_settings.region.empty();
+ }
+ std::string region = automatic && g_regionFallback.count(tile.titleId) ? g_regionFallback[tile.titleId] : "";
+ std::string result = play(am, gssv, tile, failed, region);
XC_LOGI("%s", result.c_str());
+ // Some games fail to start in one region only (Dead Cells in
+ // Brazil South quits at once with 0x8027025B but runs in East
+ // US): with the region on automatic, try another one once.
+ if (failed && g_gameClosedOnServer && automatic && !g_cancel) {
+ std::string tried = gssv.region().name, next;
+ for (const auto& r : gssv.session().regions)
+ if (r.name != tried && (next.empty() || strcasecmp(r.name.c_str(), "EASTUS") == 0)) next = r.name;
+ if (!next.empty()) {
+ XC_LOGI("%s closed on the server in %s; trying %s", tile.titleId.c_str(), tried.c_str(),
+ next.c_str());
+ result = play(am, gssv, tile, failed, next);
+ XC_LOGI("%s", result.c_str());
+ if (!failed) g_regionFallback[tile.titleId] = next;
+ }
+ }
if (failed)
g_ui->showError(result.rfind("ERROR: ", 0) == 0 ? result.substr(7) : result);
else
diff --git a/src/stream/stream_session.cpp b/src/stream/stream_session.cpp
index 2c8a4bc..1b71615 100644
--- a/src/stream/stream_session.cpp
+++ b/src/stream/stream_session.cpp
@@ -260,7 +260,7 @@ struct StreamSession::Impl {
XC_LOGI("requested stream resolution %s", opt.resolutionAlias.c_str());
}
- sendBinary(input, clientMetadataReport(0, nowMs()));
+ sendBinary(input, clientMetadataReport(0, nowMs(), static_cast<uint8_t>(std::getenv("XC_TOUCH_POINTS") ? std::atoi(std::getenv("XC_TOUCH_POINTS")) : 1)));
sendClientConfig();
{
std::lock_guard<std::mutex> lock(mutex);
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index d093213..7a4fd73 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -88,6 +88,7 @@ constexpr Column kEnglish = {
"Clear", // KeyClear
"%s games", // GamesCount
"Type", // KeyType
+ "Trying another region: %s", // TryingRegion
};
constexpr Column kPortugueseBR = {
@@ -136,16 +137,17 @@ constexpr Column kPortugueseBR = {
"Sem atividade: você será desconectado em %s segundos",
"Seus jogos",
"Indisponível na sua conta",
- "Game Pass",
- "Pesquisar",
- "Digite o nome de um jogo",
- "Nenhum jogo encontrado",
- "%s resultados",
- "Espaço",
- "Apagar",
- "Limpar",
- "%s jogos",
- "Digitar",
+ "Game Pass",
+ "Pesquisar",
+ "Digite o nome de um jogo",
+ "Nenhum jogo encontrado",
+ "%s resultados",
+ "Espaço",
+ "Apagar",
+ "Limpar",
+ "%s jogos",
+ "Digitar",
+ "Tentando outra região: %s",
};
constexpr Column kSpanish = {
@@ -194,16 +196,17 @@ constexpr Column kSpanish = {
"Sin actividad: se te desconectará en %s segundos",
"Tus juegos",
"No disponible en tu cuenta",
- "Game Pass",
- "Buscar",
- "Escribe el nombre de un juego",
- "No se encontraron juegos",
- "%s resultados",
- "Espacio",
- "Borrar",
- "Limpiar",
- "%s juegos",
- "Escribir",
+ "Game Pass",
+ "Buscar",
+ "Escribe el nombre de un juego",
+ "No se encontraron juegos",
+ "%s resultados",
+ "Espacio",
+ "Borrar",
+ "Limpiar",
+ "%s juegos",
+ "Escribir",
+ "Probando otra región: %s",
};
constexpr Column kFrench = {
@@ -252,16 +255,17 @@ constexpr Column kFrench = {
"Aucune activité : vous serez déconnecté dans %s secondes",
"Vos jeux",
"Indisponible sur votre compte",
- "Game Pass",
- "Rechercher",
- "Tapez le nom d'un jeu",
- "Aucun jeu trouvé",
- "%s résultats",
- "Espace",
- "Effacer",
- "Tout effacer",
- "%s jeux",
- "Taper",
+ "Game Pass",
+ "Rechercher",
+ "Tapez le nom d'un jeu",
+ "Aucun jeu trouvé",
+ "%s résultats",
+ "Espace",
+ "Effacer",
+ "Tout effacer",
+ "%s jeux",
+ "Taper",
+ "Essai d'une autre région : %s",
};
constexpr Column kGerman = {
@@ -310,16 +314,17 @@ constexpr Column kGerman = {
"Keine Aktivität: Die Verbindung wird in %s Sekunden getrennt",
"Deine Spiele",
"Für dein Konto nicht verfügbar",
- "Game Pass",
- "Suchen",
- "Gib den Namen eines Spiels ein",
- "Keine Spiele gefunden",
- "%s Ergebnisse",
- "Leerzeichen",
- "Löschen",
- "Leeren",
- "%s Spiele",
- "Tippen",
+ "Game Pass",
+ "Suchen",
+ "Gib den Namen eines Spiels ein",
+ "Keine Spiele gefunden",
+ "%s Ergebnisse",
+ "Leerzeichen",
+ "Löschen",
+ "Leeren",
+ "%s Spiele",
+ "Tippen",
+ "Andere Region wird versucht: %s",
};
constexpr Column kItalian = {
@@ -368,16 +373,17 @@ constexpr Column kItalian = {
"Nessuna attività: verrai disconnesso tra %s secondi",
"I tuoi giochi",
"Non disponibile sul tuo account",
- "Game Pass",
- "Cerca",
- "Scrivi il nome di un gioco",
- "Nessun gioco trovato",
- "%s risultati",
- "Spazio",
- "Cancella",
- "Svuota",
- "%s giochi",
- "Scrivi",
+ "Game Pass",
+ "Cerca",
+ "Scrivi il nome di un gioco",
+ "Nessun gioco trovato",
+ "%s risultati",
+ "Spazio",
+ "Cancella",
+ "Svuota",
+ "%s giochi",
+ "Scrivi",
+ "Provo un'altra regione: %s",
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index 1815b08..3480548 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -65,6 +65,7 @@ enum class Str {
KeyClear,
GamesCount, // "%s" = number
KeyType, // hint: press to type the focused key
+ TryingRegion, // "%s" = region name
Count
};
diff --git a/src/xcloud/gssv.cpp b/src/xcloud/gssv.cpp
index 29ae51b..8e59817 100644
--- a/src/xcloud/gssv.cpp
+++ b/src/xcloud/gssv.cpp
@@ -8,6 +8,7 @@
#include "platform/platform.h"
#include "util/log.h"
+#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <map>
@@ -225,7 +226,11 @@ bool GssvClient::listTitles(std::vector<Title>& out, std::string& err, bool rece
err = "title list failed: " + describe(r);
return false;
}
+ // Debugging: XC_DUMP_TITLES="ID1,ID2" prints those entries as sent.
+ static const char* dump = std::getenv("XC_DUMP_TITLES");
for (const auto& t : (*j)["results"].items()) {
+ if (dump && ("," + std::string(dump) + ",").find("," + t["titleId"].str() + ",") != std::string::npos)
+ std::printf("%s\n", t.dump().c_str());
Title title;
title.titleId = t["titleId"].str();
title.productId = t["details"]["productId"].str();