Compare commits

...

19 Commits

Author SHA1 Message Date
e48b277535 Bump version to 3.1.8 2024-02-15 16:46:56 +07:00
e2dbf873a6 Update translations 2024-02-15 16:46:28 +07:00
6510eac0c3 Fix error while loading profile page 2024-02-15 16:23:06 +07:00
3dd83ace6c Fix mkb's note 2024-02-15 15:49:28 +07:00
45d8aed841 Bump version to 3.1.7 2024-02-15 11:08:02 +07:00
cf1d11185b Add a link for MKB's note 2024-02-14 17:54:03 +07:00
21f119e4eb Update translations 2024-02-14 17:45:05 +07:00
ebb7920d82 Fortnite: allow playing console version on mobile 2024-02-12 19:40:28 +07:00
5ca8eb754c Bump version to 3.1.6 2024-02-11 17:50:54 +07:00
506f89ea51 Fix game's gallery failed to load (#250) 2024-02-11 16:21:40 +07:00
9332f375b8 Cache base custom touch layouts 2024-02-10 15:05:13 +07:00
dbe0435669 Use async/await in TouchController.getCustomLayouts() 2024-02-10 14:57:11 +07:00
c1684abf27 Switch to another Remote Play server if one is down 2024-02-10 14:46:51 +07:00
07e4f9dffd Add REMOTE_PLAY_SERVER for switching Remote Play server 2024-02-09 21:52:58 +07:00
bb980d2cad Bump version to 3.1.5 2024-02-09 18:07:40 +07:00
102c796c69 Set USE_DEV_TOUCH_LAYOUT to "false" 2024-02-09 18:07:04 +07:00
2f7218d165 Update translations 2024-02-09 18:04:06 +07:00
b07318e07f Add BX_EXPOSED.test_touch_control() for layout testing 2024-02-09 17:57:25 +07:00
70a8fc9866 Test new structure of custom touch layout 2024-02-09 17:46:05 +07:00
2 changed files with 184 additions and 65 deletions

View File

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

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Better xCloud
// @namespace https://github.com/redphx
// @version 3.1.4
// @version 3.1.8
// @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.8';
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
@ -1059,6 +1061,28 @@ const Translations = {
"vi-VN": "Nhanh",
"zh-CN": "快速",
},
"fortnite-allow-stw-mode": {
"de-DE": "Erlaubt das Spielen im \"STW\"-Modus auf Mobilgeräten",
"en-US": "Allows playing STW mode on mobile",
"es-ES": "Permitir jugar al modo STW en el móvil",
"ja-JP": "モバイル版で「世界を救え」をプレイできるようになります",
"pl-PL": "Zezwól na granie w tryb STW na urządzeniu mobilnym",
"pt-BR": "Permitir a reprodução do modo STW no celular",
"tr-TR": "Mobil cihazda Fortnite: Dünyayı Kurtar modunu etkinleştir",
"uk-UA": "Дозволити відтворення режиму STW на мобільному пристрої",
"vi-VN": "Cho phép chơi chế độ STW trên điện thoại",
},
"fortnite-force-console-version": {
"de-DE": "Fortnite: Erzwinge Konsolenversion",
"en-US": "Fortnite: force console version",
"es-ES": "Fortnite: forzar versión de consola",
"ja-JP": "Fortnite: 強制的にコンソール版を起動する",
"pl-PL": "Fortnite: wymuś wersję konsolową",
"pt-BR": "Fortnite: forçar versão para console",
"tr-TR": "Fortnite'ın konsol sürümünü aç",
"uk-UA": "Fortnite: примусова консольна версія",
"vi-VN": "Fortnite: bắt buộc phiên bản console",
},
"getting-consoles-list": {
"de-DE": "Rufe Liste der Konsolen ab...",
"en-US": "Getting the list of consoles...",
@ -1335,6 +1359,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",
@ -2476,11 +2501,15 @@ const Translations = {
"touch-control-layout": {
"de-DE": "Touch-Steuerungslayout",
"en-US": "Touch control layout",
"es-ES": "Diseño de control táctil",
"ja-JP": "タッチコントロールレイアウト",
"pl-PL": "Układ sterowania dotykowego",
"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 +3187,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 +3496,7 @@ class TouchController {
static #dataChannel;
static #customLayouts = {};
static #baseCustomLayouts = {};
static #currentLayoutId;
static enable() {
@ -3498,54 +3553,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 +3653,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);
@ -6409,6 +6492,8 @@ class Preferences {
static get REMOTE_PLAY_ENABLED() { return 'xhome_enabled'; }
static get REMOTE_PLAY_RESOLUTION() { return 'xhome_resolution'; }
static get GAME_FORTNITE_FORCE_CONSOLE() { return 'game_fortnite_force_console'; }
// Deprecated
static get DEPRECATED_USE_DESKTOP_CODEC() { return 'use_desktop_codec'; }
@ -6650,8 +6735,21 @@ class Preferences {
})(),
'ready': () => {
const pref = Preferences.SETTINGS[Preferences.MKB_ENABLED];
const note = __(pref.unsupported ? 'browser-unsupported-feature' : 'mkb-disclaimer');
Preferences.SETTINGS[Preferences.MKB_ENABLED].note = '⚠️ ' + note;
let note;
let url;
if (pref.unsupported) {
note = __('browser-unsupported-feature');
url = 'https://github.com/redphx/better-xcloud/issues/206#issuecomment-1920475657';
} else {
note = __('mkb-disclaimer');
url = 'https://better-xcloud.github.io/mouse-and-keyboard/#disclaimer';
}
Preferences.SETTINGS[Preferences.MKB_ENABLED].note = CE('a', {
href: url,
target: '_blank',
}, '⚠️ ' + note);
},
},
@ -6843,6 +6941,11 @@ class Preferences {
},
},
[Preferences.GAME_FORTNITE_FORCE_CONSOLE]: {
'default': false,
'note': __('fortnite-allow-stw-mode'),
},
// Deprecated
/*
[Preferences.DEPRECATED_USE_DESKTOP_CODEC]: {
@ -7254,6 +7357,18 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
funcStr = funcStr.replace(text, 'window.BX_EXPOSED["touch_layout_manager"] = this,' + text);
return funcStr;
},
forceFortniteConsole: function(funcStr) {
const text = 'sendTouchInputEnabledMessage(e){';
if (!funcStr.includes(text)) {
return false;
}
const newCode = `window.location.pathname.includes('/launch/fortnite/') && (e = false);`;
funcStr = funcStr.replace(text, text + newCode);
return funcStr;
},
};
static #PATCH_ORDERS = [
@ -7286,6 +7401,8 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
ENABLE_NATIVE_MKB_BETA && 'mkbIsMouseAndKeyboardTitle',
HAS_TOUCH_SUPPORT && 'patchUpdateInputConfigurationAsync',
],
getPref(Preferences.GAME_FORTNITE_FORCE_CONSOLE) && ['forceFortniteConsole'],
];
// Only when playing
@ -8934,9 +9051,10 @@ 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://peoplehub.xboxlive.com/users/me/people/social',
'https://peoplehub.xboxlive.com/users/me/people/recommendations',
'https://notificationinbox.xboxlive.com',
// 'https://accounts.xboxlive.com/family/memberXuid',
]);
}
@ -9013,6 +9131,17 @@ function interceptHttpRequests() {
let request = arg[0];
let url = (typeof request === 'string') ? request : request.url;
for (let blocked of BLOCKED_URLS) {
if (!url.startsWith(blocked)) {
continue;
}
return new Response('{"acc":1,"webResult":{}}', {
status: 200,
statusText: '200 OK',
});
}
if (url.endsWith('/play')) {
BxEvent.dispatch(window, BxEvent.STREAM_LOADING);
}
@ -9049,7 +9178,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);
@ -9340,17 +9469,6 @@ function interceptHttpRequests() {
});
}
for (let blocked of BLOCKED_URLS) {
if (!url.startsWith(blocked)) {
continue;
}
return new Response('{"acc":1,"webResult":{}}', {
status: 200,
statusText: '200 OK',
});
}
return NATIVE_FETCH(...arg);
}
}
@ -9452,6 +9570,7 @@ function injectSettingsButton($parent) {
[Preferences.AUDIO_ENABLE_VOLUME_CONTROL]: __('enable-volume-control'),
[Preferences.AUDIO_MIC_ON_PLAYING]: __('enable-mic-on-startup'),
[Preferences.STREAM_DISABLE_FEEDBACK_DIALOG]: __('disable-post-stream-feedback-dialog'),
[Preferences.GAME_FORTNITE_FORCE_CONSOLE]: '🎮 ' + __('fortnite-force-console-version'),
},
[__('mouse-and-keyboard')]: {