mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-28 18:31:44 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
5ca8eb754c | |||
506f89ea51 | |||
9332f375b8 | |||
dbe0435669 | |||
c1684abf27 | |||
07e4f9dffd | |||
bb980d2cad | |||
102c796c69 | |||
2f7218d165 | |||
b07318e07f | |||
70a8fc9866 |
@ -1,5 +1,5 @@
|
||||
// ==UserScript==
|
||||
// @name Better xCloud
|
||||
// @namespace https://github.com/redphx
|
||||
// @version 3.1.4
|
||||
// @version 3.1.6
|
||||
// ==/UserScript==
|
||||
|
@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name Better xCloud
|
||||
// @namespace https://github.com/redphx
|
||||
// @version 3.1.4
|
||||
// @version 3.1.6
|
||||
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||
// @author redphx
|
||||
// @license MIT
|
||||
@ -14,13 +14,15 @@
|
||||
// ==/UserScript==
|
||||
'use strict';
|
||||
|
||||
const SCRIPT_VERSION = '3.1.4';
|
||||
const SCRIPT_VERSION = '3.1.6';
|
||||
const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
|
||||
|
||||
const ENABLE_XCLOUD_LOGGER = false;
|
||||
const ENABLE_PRELOAD_BX_UI = false;
|
||||
const USE_DEV_TOUCH_LAYOUT = false;
|
||||
|
||||
let REMOTE_PLAY_SERVER;
|
||||
|
||||
const ENABLE_NATIVE_MKB_BETA = false;
|
||||
window.NATIVE_MKB_TITLES = [
|
||||
// Not working anymore
|
||||
@ -1335,6 +1337,7 @@ const Translations = {
|
||||
"tr-TR": "Bu özellik çevrimiçi oyunlarda sizi hile yapıyormuşsunuz gibi gösterebilir",
|
||||
"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",
|
||||
"zh-CN": "游玩在线游戏时,使用此功能可能被视为作弊。",
|
||||
},
|
||||
"mouse-and-keyboard": {
|
||||
"de-DE": "Maus & Tastatur",
|
||||
@ -2479,8 +2482,10 @@ const Translations = {
|
||||
"ja-JP": "タッチコントロールレイアウト",
|
||||
"pt-BR": "Layout do controle por toque",
|
||||
"ru-RU": "Расположение сенсорных кнопок",
|
||||
"tr-TR": "Dokunmatik kontrol şeması",
|
||||
"uk-UA": "Розташування сенсорного керування",
|
||||
"vi-VN": "Bố cục điều khiển cảm ứng",
|
||||
"zh-CN": "触摸控制布局",
|
||||
},
|
||||
"touch-controller": {
|
||||
"de-DE": "Touch-Controller",
|
||||
@ -3158,22 +3163,47 @@ class RemotePlay {
|
||||
});
|
||||
}
|
||||
|
||||
static #getConsolesList(callback) {
|
||||
static async #getConsolesList(callback) {
|
||||
if (RemotePlay.#CONSOLES) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('https://wus2.gssv-play-prodxhome.xboxlive.com/v6/servers/home?mr=50', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${RemotePlay.XHOME_TOKEN}`,
|
||||
},
|
||||
}).then(resp => resp.json())
|
||||
.then(json => {
|
||||
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',
|
||||
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;
|
||||
|
||||
// Store working server
|
||||
REMOTE_PLAY_SERVER = server;
|
||||
|
||||
callback();
|
||||
});
|
||||
break;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// None of the servers worked
|
||||
if (!REMOTE_PLAY_SERVER) {
|
||||
RemotePlay.#CONSOLES = [];
|
||||
}
|
||||
}
|
||||
|
||||
static showDialog() {
|
||||
@ -3442,6 +3472,7 @@ class TouchController {
|
||||
static #dataChannel;
|
||||
|
||||
static #customLayouts = {};
|
||||
static #baseCustomLayouts = {};
|
||||
static #currentLayoutId;
|
||||
|
||||
static enable() {
|
||||
@ -3498,54 +3529,64 @@ class TouchController {
|
||||
}, 10);
|
||||
}
|
||||
|
||||
static getCustomLayouts(xboxTitleId) {
|
||||
const dispatchLayouts = data => {
|
||||
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
|
||||
data: data,
|
||||
});
|
||||
};
|
||||
static #dispatchLayouts(data) {
|
||||
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
|
||||
data: data,
|
||||
});
|
||||
};
|
||||
|
||||
static async getCustomLayouts(xboxTitleId, retries) {
|
||||
xboxTitleId = '' + xboxTitleId;
|
||||
if (xboxTitleId in TouchController.#customLayouts) {
|
||||
dispatchLayouts(TouchController.#customLayouts[xboxTitleId]);
|
||||
TouchController.#dispatchLayouts(TouchController.#customLayouts[xboxTitleId]);
|
||||
return;
|
||||
}
|
||||
|
||||
let url = 'https://raw.githubusercontent.com/redphx/better-xcloud/gh-pages/touch-layouts/';
|
||||
if (USE_DEV_TOUCH_LAYOUT) {
|
||||
url += `dev/${xboxTitleId}.json`;
|
||||
} else {
|
||||
url += `${xboxTitleId}.json`;
|
||||
retries = retries || 1;
|
||||
if (retries > 2) {
|
||||
TouchController.#customLayouts[xboxTitleId] = null;
|
||||
// Wait for BX_EXPOSED.touch_layout_manager
|
||||
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;
|
||||
|
||||
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 {
|
||||
if (schema_version === 1) {
|
||||
json.layouts = {
|
||||
default: {
|
||||
name: 'Default',
|
||||
content: json.layout,
|
||||
},
|
||||
};
|
||||
json.default_layout = 'default';
|
||||
delete json.layout;
|
||||
}
|
||||
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) {}
|
||||
}
|
||||
|
||||
TouchController.#customLayouts[xboxTitleId] = json;
|
||||
Object.assign(layouts, baseLayouts);
|
||||
});
|
||||
|
||||
// Wait for BX_EXPOSED.touch_layout_manager
|
||||
setTimeout(() => dispatchLayouts(json), 1000);
|
||||
})
|
||||
.catch(() => {
|
||||
TouchController.#customLayouts[xboxTitleId] = null;
|
||||
// Wait for BX_EXPOSED.touch_layout_manager
|
||||
setTimeout(() => dispatchLayouts(null), 1000);
|
||||
});
|
||||
json.layouts = layouts;
|
||||
TouchController.#customLayouts[xboxTitleId] = json;
|
||||
|
||||
// Wait for BX_EXPOSED.touch_layout_manager
|
||||
setTimeout(() => TouchController.#dispatchLayouts(json), 1000);
|
||||
} catch (e) {
|
||||
// Retry
|
||||
TouchController.getCustomLayouts(xboxTitleId, retries + 1);
|
||||
}
|
||||
}
|
||||
|
||||
static loadCustomLayout(xboxTitleId, layoutId, delay) {
|
||||
@ -3588,6 +3629,24 @@ class TouchController {
|
||||
}
|
||||
|
||||
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 $style = document.createElement('style');
|
||||
$fragment.appendChild($style);
|
||||
@ -8935,7 +8994,7 @@ function interceptHttpRequests() {
|
||||
if (getPref(Preferences.BLOCK_SOCIAL_FEATURES)) {
|
||||
BLOCKED_URLS = BLOCKED_URLS.concat([
|
||||
'https://peoplehub.xboxlive.com/users/me',
|
||||
'https://accounts.xboxlive.com/family/memberXuid',
|
||||
// 'https://accounts.xboxlive.com/family/memberXuid',
|
||||
'https://notificationinbox.xboxlive.com',
|
||||
]);
|
||||
}
|
||||
@ -9049,7 +9108,7 @@ function interceptHttpRequests() {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
Reference in New Issue
Block a user