Compare commits

...

11 Commits

2 changed files with 110 additions and 51 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.4 // @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.4 // @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.4'; 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
@ -1335,6 +1337,7 @@ const Translations = {
"tr-TR": "Bu özellik çevrimiçi oyunlarda sizi hile yapıyormuşsunuz gibi gösterebilir", "tr-TR": "Bu özellik çevrimiçi oyunlarda sizi hile yapıyormuşsunuz gibi gösterebilir",
"uk-UA": "Використання цієї функції під час гри онлайн може розглядатися як шахрайство", "uk-UA": "Використання цієї функції під час гри онлайн може розглядатися як шахрайство",
"vi-VN": "Sử dụng chức năng này khi chơi trực tuyến có thể bị xem là gian lận", "vi-VN": "Sử dụng chức năng này khi chơi trực tuyến có thể bị xem là gian lận",
"zh-CN": "游玩在线游戏时,使用此功能可能被视为作弊。",
}, },
"mouse-and-keyboard": { "mouse-and-keyboard": {
"de-DE": "Maus & Tastatur", "de-DE": "Maus & Tastatur",
@ -2479,8 +2482,10 @@ const Translations = {
"ja-JP": "タッチコントロールレイアウト", "ja-JP": "タッチコントロールレイアウト",
"pt-BR": "Layout do controle por toque", "pt-BR": "Layout do controle por toque",
"ru-RU": "Расположение сенсорных кнопок", "ru-RU": "Расположение сенсорных кнопок",
"tr-TR": "Dokunmatik kontrol şeması",
"uk-UA": "Розташування сенсорного керування", "uk-UA": "Розташування сенсорного керування",
"vi-VN": "Bố cục điều khiển cảm ứng", "vi-VN": "Bố cục điều khiển cảm ứng",
"zh-CN": "触摸控制布局",
}, },
"touch-controller": { "touch-controller": {
"de-DE": "Touch-Controller", "de-DE": "Touch-Controller",
@ -3158,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;
method: 'GET', if (!REMOTE_PLAY_SERVER) {
headers: { servers = ['wus2', 'eus', 'uks']; // Possible values: wus2 (WestUS2), eus (EastUS), uks (UkSouth)
'Authorization': `Bearer ${RemotePlay.XHOME_TOKEN}`, } else {
}, servers = REMOTE_PLAY_SERVER;
}).then(resp => resp.json()) }
.then(json => {
const options = {
method: 'GET',
headers: {
'Authorization': `Bearer ${RemotePlay.XHOME_TOKEN}`,
},
};
// 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() {
@ -3442,6 +3472,7 @@ class TouchController {
static #dataChannel; static #dataChannel;
static #customLayouts = {}; static #customLayouts = {};
static #baseCustomLayouts = {};
static #currentLayoutId; static #currentLayoutId;
static enable() { static enable() {
@ -3498,54 +3529,64 @@ class TouchController {
}, 10); }, 10);
} }
static getCustomLayouts(xboxTitleId) { static #dispatchLayouts(data) {
const dispatchLayouts = data => { BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, { data: data,
data: data, });
}); };
};
static async getCustomLayouts(xboxTitleId, retries) {
xboxTitleId = '' + xboxTitleId; xboxTitleId = '' + xboxTitleId;
if (xboxTitleId in TouchController.#customLayouts) { if (xboxTitleId in TouchController.#customLayouts) {
dispatchLayouts(TouchController.#customLayouts[xboxTitleId]); TouchController.#dispatchLayouts(TouchController.#customLayouts[xboxTitleId]);
return; return;
} }
let url = 'https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/touch-layouts/'; retries = retries || 1;
if (USE_DEV_TOUCH_LAYOUT) { if (retries > 2) {
url += `dev/${xboxTitleId}.json`; TouchController.#customLayouts[xboxTitleId] = null;
} else { // Wait for BX_EXPOSED.touch_layout_manager
url += `${xboxTitleId}.json`; setTimeout(() => TouchController.#dispatchLayouts(null), 1000);
return;
} }
NATIVE_FETCH(url)
.then(resp => resp.json()) const baseUrl = `https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/touch-layouts${USE_DEV_TOUCH_LAYOUT ? '/dev' : ''}`;
.then(json => { const url = `${baseUrl}/${xboxTitleId}.json`;
// Normalize data
const schema_version = json.schema_version || 1; // Get layout info
let layout; try {
const resp = await NATIVE_FETCH(url);
const json = await resp.json();
const layouts = {};
json.layouts.forEach(async layoutName => {
let baseLayouts = {};
if (layoutName in TouchController.#baseCustomLayouts) {
baseLayouts = TouchController.#baseCustomLayouts[layoutName];
} else {
try { try {
if (schema_version === 1) { const layoutUrl = `${baseUrl}/layouts/${layoutName}.json`;
json.layouts = { const resp = await NATIVE_FETCH(layoutUrl);
default: { const json = await resp.json();
name: 'Default',
content: json.layout, baseLayouts = json.layouts;
}, TouchController.#baseCustomLayouts[layoutName] = baseLayouts;
};
json.default_layout = 'default';
delete json.layout;
}
} catch (e) {} } catch (e) {}
}
TouchController.#customLayouts[xboxTitleId] = json; Object.assign(layouts, baseLayouts);
});
// Wait for BX_EXPOSED.touch_layout_manager json.layouts = layouts;
setTimeout(() => dispatchLayouts(json), 1000); TouchController.#customLayouts[xboxTitleId] = json;
})
.catch(() => { // Wait for BX_EXPOSED.touch_layout_manager
TouchController.#customLayouts[xboxTitleId] = null; setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
// Wait for BX_EXPOSED.touch_layout_manager } catch (e) {
setTimeout(() => dispatchLayouts(null), 1000); // Retry
}); TouchController.getCustomLayouts(xboxTitleId, retries + 1);
}
} }
static loadCustomLayout(xboxTitleId, layoutId, delay) { static loadCustomLayout(xboxTitleId, layoutId, delay) {
@ -3588,6 +3629,24 @@ class TouchController {
} }
static setup() { static setup() {
// Function for testing touch control
window.BX_EXPOSED.test_touch_control = content => {
const { touch_layout_manager } = window.BX_EXPOSED;
touch_layout_manager && touch_layout_manager.changeLayoutForScope({
type: 'showLayout',
scope: '' + GAME_XBOX_TITLE_ID,
subscope: 'base',
layout: {
id: 'System.Standard',
displayName: 'Custom',
layoutFile: {
content: content,
},
},
});
};
const $fragment = document.createDocumentFragment(); const $fragment = document.createDocumentFragment();
const $style = document.createElement('style'); const $style = document.createElement('style');
$fragment.appendChild($style); $fragment.appendChild($style);
@ -8935,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',
]); ]);
} }
@ -9049,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);