Compare commits

...

6 Commits

2 changed files with 73 additions and 33 deletions

View File

@ -1,5 +1,5 @@
// ==UserScript== // ==UserScript==
// @name Better xCloud // @name Better xCloud
// @namespace https://github.com/redphx // @namespace https://github.com/redphx
// @version 3.1.5 // @version 3.1.6
// ==/UserScript== // ==/UserScript==

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Better xCloud // @name Better xCloud
// @namespace https://github.com/redphx // @namespace https://github.com/redphx
// @version 3.1.5 // @version 3.1.6
// @description Improve Xbox Cloud Gaming (xCloud) experience // @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx // @author redphx
// @license MIT // @license MIT
@ -14,13 +14,15 @@
// ==/UserScript== // ==/UserScript==
'use strict'; 'use strict';
const SCRIPT_VERSION = '3.1.5'; const SCRIPT_VERSION = '3.1.6';
const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud'; const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
const ENABLE_XCLOUD_LOGGER = false; const ENABLE_XCLOUD_LOGGER = false;
const ENABLE_PRELOAD_BX_UI = false; const ENABLE_PRELOAD_BX_UI = false;
const USE_DEV_TOUCH_LAYOUT = false; const USE_DEV_TOUCH_LAYOUT = false;
let REMOTE_PLAY_SERVER;
const ENABLE_NATIVE_MKB_BETA = false; const ENABLE_NATIVE_MKB_BETA = false;
window.NATIVE_MKB_TITLES = [ window.NATIVE_MKB_TITLES = [
// Not working anymore // Not working anymore
@ -3161,22 +3163,47 @@ class RemotePlay {
}); });
} }
static #getConsolesList(callback) { static async #getConsolesList(callback) {
if (RemotePlay.#CONSOLES) { if (RemotePlay.#CONSOLES) {
callback(); callback();
return; return;
} }
fetch('https://wus2.gssv-play-prodxhome.xboxlive.com/v6/servers/home?mr=50', { let servers;
if (!REMOTE_PLAY_SERVER) {
servers = ['wus2', 'eus', 'uks']; // Possible values: wus2 (WestUS2), eus (EastUS), uks (UkSouth)
} else {
servers = REMOTE_PLAY_SERVER;
}
const options = {
method: 'GET', method: 'GET',
headers: { headers: {
'Authorization': `Bearer ${RemotePlay.XHOME_TOKEN}`, 'Authorization': `Bearer ${RemotePlay.XHOME_TOKEN}`,
}, },
}).then(resp => resp.json()) };
.then(json => {
// Test servers one by one
for (const server of servers) {
try {
const url = `https://${server}.gssv-play-prodxhome.xboxlive.com/v6/servers/home?mr=50`;
const resp = await fetch(url, options);
const json = await resp.json();
RemotePlay.#CONSOLES = json.results; RemotePlay.#CONSOLES = json.results;
// Store working server
REMOTE_PLAY_SERVER = server;
callback(); callback();
}); break;
} catch (e) {}
}
// None of the servers worked
if (!REMOTE_PLAY_SERVER) {
RemotePlay.#CONSOLES = [];
}
} }
static showDialog() { static showDialog() {
@ -3445,6 +3472,7 @@ class TouchController {
static #dataChannel; static #dataChannel;
static #customLayouts = {}; static #customLayouts = {};
static #baseCustomLayouts = {};
static #currentLayoutId; static #currentLayoutId;
static enable() { static enable() {
@ -3507,7 +3535,7 @@ class TouchController {
}); });
}; };
static getCustomLayouts(xboxTitleId, retries) { static async getCustomLayouts(xboxTitleId, retries) {
xboxTitleId = '' + xboxTitleId; xboxTitleId = '' + xboxTitleId;
if (xboxTitleId in TouchController.#customLayouts) { if (xboxTitleId in TouchController.#customLayouts) {
TouchController.#dispatchLayouts(TouchController.#customLayouts[xboxTitleId]); TouchController.#dispatchLayouts(TouchController.#customLayouts[xboxTitleId]);
@ -3526,15 +3554,28 @@ class TouchController {
const url = `${baseUrl}/${xboxTitleId}.json`; const url = `${baseUrl}/${xboxTitleId}.json`;
// Get layout info // Get layout info
NATIVE_FETCH(url) try {
.then(resp => resp.json()) const resp = await NATIVE_FETCH(url);
.then(json => { const json = await resp.json();
const layouts = {}; const layouts = {};
json.layouts.forEach(async file => { json.layouts.forEach(async layoutName => {
const layoutUrl = `${baseUrl}/layouts/${file}.json`; let baseLayouts = {};
const json = await (await NATIVE_FETCH(layoutUrl)).json(); if (layoutName in TouchController.#baseCustomLayouts) {
Object.assign(layouts, json.layouts); baseLayouts = TouchController.#baseCustomLayouts[layoutName];
} else {
try {
const layoutUrl = `${baseUrl}/layouts/${layoutName}.json`;
const resp = await NATIVE_FETCH(layoutUrl);
const json = await resp.json();
baseLayouts = json.layouts;
TouchController.#baseCustomLayouts[layoutName] = baseLayouts;
} catch (e) {}
}
Object.assign(layouts, baseLayouts);
}); });
json.layouts = layouts; json.layouts = layouts;
@ -3542,11 +3583,10 @@ class TouchController {
// Wait for BX_EXPOSED.touch_layout_manager // Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => TouchController.#dispatchLayouts(json), 1000); setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
}) } catch (e) {
.catch(() => {
// Retry // Retry
TouchController.getCustomLayouts(xboxTitleId, retries + 1); TouchController.getCustomLayouts(xboxTitleId, retries + 1);
}); }
} }
static loadCustomLayout(xboxTitleId, layoutId, delay) { static loadCustomLayout(xboxTitleId, layoutId, delay) {
@ -8954,7 +8994,7 @@ function interceptHttpRequests() {
if (getPref(Preferences.BLOCK_SOCIAL_FEATURES)) { if (getPref(Preferences.BLOCK_SOCIAL_FEATURES)) {
BLOCKED_URLS = BLOCKED_URLS.concat([ BLOCKED_URLS = BLOCKED_URLS.concat([
'https://peoplehub.xboxlive.com/users/me', 'https://peoplehub.xboxlive.com/users/me',
'https://accounts.xboxlive.com/family/memberXuid', // 'https://accounts.xboxlive.com/family/memberXuid',
'https://notificationinbox.xboxlive.com', 'https://notificationinbox.xboxlive.com',
]); ]);
} }
@ -9068,7 +9108,7 @@ function interceptHttpRequests() {
} }
const index = request.url.indexOf('.xboxlive.com'); const index = request.url.indexOf('.xboxlive.com');
let newUrl = 'https://wus2.gssv-play-prodxhome' + request.url.substring(index); let newUrl = `https://${REMOTE_PLAY_SERVER}.gssv-play-prodxhome` + request.url.substring(index);
request = new Request(newUrl, opts); request = new Request(newUrl, opts);