Compare commits

...

11 Commits

Author SHA1 Message Date
redphx
5ca8eb754c Bump version to 3.1.6 2024-02-11 17:50:54 +07:00
redphx
506f89ea51 Fix game's gallery failed to load (#250) 2024-02-11 16:21:40 +07:00
redphx
9332f375b8 Cache base custom touch layouts 2024-02-10 15:05:13 +07:00
redphx
dbe0435669 Use async/await in TouchController.getCustomLayouts() 2024-02-10 14:57:11 +07:00
redphx
c1684abf27 Switch to another Remote Play server if one is down 2024-02-10 14:46:51 +07:00
redphx
07e4f9dffd Add REMOTE_PLAY_SERVER for switching Remote Play server 2024-02-09 21:52:58 +07:00
redphx
bb980d2cad Bump version to 3.1.5 2024-02-09 18:07:40 +07:00
redphx
102c796c69 Set USE_DEV_TOUCH_LAYOUT to "false" 2024-02-09 18:07:04 +07:00
redphx
2f7218d165 Update translations 2024-02-09 18:04:06 +07:00
redphx
b07318e07f Add BX_EXPOSED.test_touch_control() for layout testing 2024-02-09 17:57:25 +07:00
redphx
70a8fc9866 Test new structure of custom touch layout 2024-02-09 17:46:05 +07:00
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;
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() {
@@ -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())
.then(json => {
// Normalize data
const schema_version = json.schema_version || 1;
let layout;
try {
if (schema_version === 1) {
json.layouts = {
default: {
name: 'Default',
content: json.layout,
},
};
json.default_layout = 'default';
delete json.layout;
}
} catch (e) {}
const baseUrl = `https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/touch-layouts${USE_DEV_TOUCH_LAYOUT ? '/dev' : ''}`;
const url = `${baseUrl}/${xboxTitleId}.json`;
// Get layout info
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 {
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;
TouchController.#customLayouts[xboxTitleId] = json; TouchController.#customLayouts[xboxTitleId] = json;
// Wait for BX_EXPOSED.touch_layout_manager // Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => dispatchLayouts(json), 1000); setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
}) } catch (e) {
.catch(() => { // Retry
TouchController.#customLayouts[xboxTitleId] = null; TouchController.getCustomLayouts(xboxTitleId, retries + 1);
// Wait for BX_EXPOSED.touch_layout_manager }
setTimeout(() => dispatchLayouts(null), 1000);
});
} }
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);