Compare commits

..

36 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
2d9ee16531 Bump version to 3.1.4 2024-02-07 21:43:49 +07:00
21168803e0 Set default value of STREAM_CODEC_PROFILE to the best codec profile 2024-02-07 21:37:35 +07:00
3068aa8a06 Minor fix for touch control 2024-02-07 18:40:36 +07:00
b6b9ec49f6 Update touch support detection in Remote Play 2024-02-07 17:35:13 +07:00
4dc60f965f Minor fix 2024-02-07 15:22:27 +07:00
2142c4a83c Only request custom touch control when the game is focused 2024-02-07 15:15:53 +07:00
6b090194c9 Only show toast when the layout has been changed 2024-02-07 14:56:36 +07:00
a878150ec3 Show a toast with layout's name when switching touch control layout 2024-02-07 11:09:10 +07:00
5fb1dded42 Change default value of "STREAM_TARGET_RESOLUTION" to "1080p" 2024-02-07 10:53:12 +07:00
ac6879c189 Change default value of "STREAM_TOUCH_CONTROLLER" to "all" 2024-02-07 10:52:04 +07:00
b8efaf9648 Fix not loading Better xCloud after logging in 2024-02-06 22:53:53 +07:00
033ac31333 Bump version to 3.1.3 2024-02-03 07:16:46 +07:00
1f754d4a1d Add STREAM_STOPPED and STREAM_ERROR_PAGE events 2024-02-02 10:31:40 +07:00
0d39ccf8bf Typo 2024-02-02 10:04:59 +07:00
966d7f2f6c Hide touchscreen using bx-offscreen instead of bx-gone 2024-02-02 10:02:57 +07:00
fdbf618253 Add STREAM_MENU_SHOWN and STREAM_MENU_HIDDEN events 2024-02-02 09:59:42 +07:00
aaa7612293 Fix default touch control not showing sometimes 2024-02-01 20:22:18 +07:00
2 changed files with 340 additions and 131 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.2 // @version 3.1.8
// ==/UserScript== // ==/UserScript==

View File

@ -1,11 +1,12 @@
// ==UserScript== // ==UserScript==
// @name Better xCloud // @name Better xCloud
// @namespace https://github.com/redphx // @namespace https://github.com/redphx
// @version 3.1.2 // @version 3.1.8
// @description Improve Xbox Cloud Gaming (xCloud) experience // @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx // @author redphx
// @license MIT // @license MIT
// @match https://www.xbox.com/*/play* // @match https://www.xbox.com/*/play*
// @match https://www.xbox.com/*/auth/msa?*loggedIn*
// @run-at document-start // @run-at document-start
// @grant none // @grant none
// @updateURL https://raw.githubusercontent.com/redphx/better-xcloud/main/better-xcloud.meta.js // @updateURL https://raw.githubusercontent.com/redphx/better-xcloud/main/better-xcloud.meta.js
@ -13,13 +14,15 @@
// ==/UserScript== // ==/UserScript==
'use strict'; 'use strict';
const SCRIPT_VERSION = '3.1.2'; const SCRIPT_VERSION = '3.1.8';
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
@ -38,6 +41,17 @@ window.NATIVE_MKB_TITLES = [
// '9P731Z4BBCT3', // Atomic Heart // '9P731Z4BBCT3', // Atomic Heart
]; ];
if (window.location.pathname.includes('/auth/msa')) {
window.addEventListener('load', e => {
window.location.search.includes('loggedIn') && setTimeout(() => {
const location = window.location;
location.pathname.includes('/play') && location.reload(true);
}, 2000);
});
// Stop processing the script
throw new Error('[Better xCloud] Refreshing the page after logging in');
}
console.log(`[Better xCloud] readyState: ${document.readyState}`); console.log(`[Better xCloud] readyState: ${document.readyState}`);
const BxEvent = { const BxEvent = {
@ -49,6 +63,10 @@ const BxEvent = {
STREAM_STARTED: 'bx-stream-started', STREAM_STARTED: 'bx-stream-started',
STREAM_PLAYING: 'bx-stream-playing', STREAM_PLAYING: 'bx-stream-playing',
STREAM_STOPPED: 'bx-stream-stopped', STREAM_STOPPED: 'bx-stream-stopped',
STREAM_ERROR_PAGE: 'bx-stream-error-page',
STREAM_MENU_SHOWN: 'bx-stream-menu-shown',
STREAM_MENU_HIDDEN: 'bx-stream-menu-hidden',
STREAM_WEBRTC_CONNECTED: 'bx-stream-webrtc-connected', STREAM_WEBRTC_CONNECTED: 'bx-stream-webrtc-connected',
STREAM_WEBRTC_DISCONNECTED: 'bx-stream-webrtc-disconnected', STREAM_WEBRTC_DISCONNECTED: 'bx-stream-webrtc-disconnected',
@ -58,6 +76,11 @@ const BxEvent = {
DATA_CHANNEL_CREATED: 'bx-data-channel-created', DATA_CHANNEL_CREATED: 'bx-data-channel-created',
dispatch: (target, eventName, data) => { dispatch: (target, eventName, data) => {
if (!eventName) {
alert('BxEvent.dispatch(): eventName is null');
return;
}
const event = new Event(eventName); const event = new Event(eventName);
if (data) { if (data) {
@ -1038,6 +1061,28 @@ const Translations = {
"vi-VN": "Nhanh", "vi-VN": "Nhanh",
"zh-CN": "快速", "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": { "getting-consoles-list": {
"de-DE": "Rufe Liste der Konsolen ab...", "de-DE": "Rufe Liste der Konsolen ab...",
"en-US": "Getting the list of consoles...", "en-US": "Getting the list of consoles...",
@ -1311,8 +1356,10 @@ const Translations = {
"pl-PL": "Używanie tej funkcji podczas grania online może być postrzegane jako oszukiwanie", "pl-PL": "Używanie tej funkcji podczas grania online może być postrzegane jako oszukiwanie",
"pt-BR": "Usar esta função em jogos online pode ser considerado como uma forma de trapaça", "pt-BR": "Usar esta função em jogos online pode ser considerado como uma forma de trapaça",
"ru-RU": "Использование этой функции при игре онлайн может рассматриваться как читерство", "ru-RU": "Использование этой функции при игре онлайн может рассматриваться как читерство",
"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",
@ -2451,6 +2498,19 @@ const Translations = {
"vi-VN": "Phía trên bên phải", "vi-VN": "Phía trên bên phải",
"zh-CN": "右上角", "zh-CN": "右上角",
}, },
"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": { "touch-controller": {
"de-DE": "Touch-Controller", "de-DE": "Touch-Controller",
"en-US": "Touch controller", "en-US": "Touch controller",
@ -3127,22 +3187,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() {
@ -3411,6 +3496,7 @@ class TouchController {
static #dataChannel; static #dataChannel;
static #customLayouts = {}; static #customLayouts = {};
static #baseCustomLayouts = {};
static #currentLayoutId; static #currentLayoutId;
static enable() { static enable() {
@ -3431,14 +3517,12 @@ class TouchController {
} }
static #show() { static #show() {
document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.remove('bx-gone'); document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.remove('bx-offscreen');
// TouchController.loadCustomLayout(GAME_XBOX_TITLE_ID, TouchController.#currentLayoutId, 0);
TouchController.#showing = true; TouchController.#showing = true;
} }
static #hide() { static #hide() {
document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.add('bx-gone'); document.querySelector('#BabylonCanvasContainer-main').parentElement.classList.add('bx-offscreen');
// TouchController.#dispatchMessage(TouchController.#EVENT_HIDE_CONTROLLER);
TouchController.#showing = false; TouchController.#showing = false;
} }
@ -3469,53 +3553,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' : ''}`;
TouchController.#customLayouts[xboxTitleId] = null; const url = `${baseUrl}/${xboxTitleId}.json`;
// Wait for BX_EXPOSED.touch_layout_manager
setTimeout(() => dispatchLayouts(null), 1000); // Get layout info
}) try {
.then(json => { const resp = await NATIVE_FETCH(url);
// Normalize data const json = await resp.json();
const schema_version = json.schema_version || 1;
let layout; 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;
});
// 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) { static loadCustomLayout(xboxTitleId, layoutId, delay) {
@ -3523,9 +3618,12 @@ class TouchController {
return; return;
} }
const layoutChanged = TouchController.#currentLayoutId !== layoutId;
TouchController.#currentLayoutId = layoutId; TouchController.#currentLayoutId = layoutId;
xboxTitleId = '' + xboxTitleId; xboxTitleId = '' + xboxTitleId;
// Get layout data
const layoutData = TouchController.#customLayouts[xboxTitleId]; const layoutData = TouchController.#customLayouts[xboxTitleId];
if (!xboxTitleId || !layoutId || !layoutData) { if (!xboxTitleId || !layoutId || !layoutData) {
TouchController.#enable && TouchController.#showDefault(); TouchController.#enable && TouchController.#showDefault();
@ -3533,23 +3631,46 @@ class TouchController {
} }
const layout = (layoutData.layouts[layoutId] || layoutData.layouts[layoutData.default_layout]); const layout = (layoutData.layouts[layoutId] || layoutData.layouts[layoutData.default_layout]);
layout && setTimeout(() => { if (layout) {
window.BX_EXPOSED.touch_layout_manager.changeLayoutForScope({ // Show a toast with layout's name
type: 'showLayout', layoutChanged && Toast.show(__('touch-control-layout'), layout.name);
scope: xboxTitleId,
subscope: 'base', setTimeout(() => {
layout: { window.BX_EXPOSED.touch_layout_manager.changeLayoutForScope({
id: 'System.Standard', type: 'showLayout',
displayName: 'System', scope: xboxTitleId,
layoutFile: { subscope: 'base',
content: layout.content, layout: {
}, id: 'System.Standard',
} displayName: 'System',
}); layoutFile: {
}, delay); content: layout.content,
},
}
});
}, delay);
}
} }
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);
@ -3612,6 +3733,7 @@ class TouchController {
setTimeout(TouchController.#show, 1000); setTimeout(TouchController.#show, 1000);
}); });
let focused = false;
dataChannel.addEventListener('message', msg => { dataChannel.addEventListener('message', msg => {
if (msg.origin === 'better-xcloud' || typeof msg.data !== 'string') { if (msg.origin === 'better-xcloud' || typeof msg.data !== 'string') {
return; return;
@ -3619,7 +3741,13 @@ class TouchController {
// Dispatch a message to display generic touch controller // Dispatch a message to display generic touch controller
if (msg.data.includes('touchcontrols/showtitledefault')) { if (msg.data.includes('touchcontrols/showtitledefault')) {
TouchController.#enable && TouchController.getCustomLayouts(GAME_XBOX_TITLE_ID); if (TouchController.#enable) {
if (focused) {
TouchController.getCustomLayouts(GAME_XBOX_TITLE_ID);
} else {
TouchController.#showDefault();
}
}
return; return;
} }
@ -3629,6 +3757,7 @@ class TouchController {
const json = JSON.parse(JSON.parse(msg.data).content); const json = JSON.parse(JSON.parse(msg.data).content);
TouchController.#toggleBar(json.focused); TouchController.#toggleBar(json.focused);
focused = json.focused;
if (!json.focused) { if (!json.focused) {
TouchController.#show(); TouchController.#show();
} }
@ -4781,8 +4910,8 @@ class MkbHandler {
this.#$message.addEventListener('click', this.#onActivatePointerLock); this.#$message.addEventListener('click', this.#onActivatePointerLock);
document.documentElement.appendChild(this.#$message); document.documentElement.appendChild(this.#$message);
window.addEventListener('bx-stream-menu-shown', this.#onStreamMenuShown); window.addEventListener(BxEvent.STREAM_MENU_SHOWN, this.#onStreamMenuShown);
window.addEventListener('bx-stream-menu-hidden', this.#onStreamMenuHidden); window.addEventListener(BxEvent.STREAM_MENU_HIDDEN, this.#onStreamMenuHidden);
this.#waitForPointerLock(true); this.#waitForPointerLock(true);
} }
@ -4799,8 +4928,8 @@ class MkbHandler {
document.removeEventListener('pointerlockchange', this.#onPointerLockChange); document.removeEventListener('pointerlockchange', this.#onPointerLockChange);
document.removeEventListener('pointerlockerror', this.#onPointerLockError); document.removeEventListener('pointerlockerror', this.#onPointerLockError);
window.removeEventListener('bx-stream-menu-shown', this.#onStreamMenuShown); window.removeEventListener(BxEvent.STREAM_MENU_SHOWN, this.#onStreamMenuShown);
window.removeEventListener('bx-stream-menu-hidden', this.#onStreamMenuHidden); window.removeEventListener(BxEvent.STREAM_MENU_HIDDEN, this.#onStreamMenuHidden);
} }
start = () => { start = () => {
@ -6363,6 +6492,8 @@ class Preferences {
static get REMOTE_PLAY_ENABLED() { return 'xhome_enabled'; } static get REMOTE_PLAY_ENABLED() { return 'xhome_enabled'; }
static get REMOTE_PLAY_RESOLUTION() { return 'xhome_resolution'; } static get REMOTE_PLAY_RESOLUTION() { return 'xhome_resolution'; }
static get GAME_FORTNITE_FORCE_CONSOLE() { return 'game_fortnite_force_console'; }
// Deprecated // Deprecated
static get DEPRECATED_USE_DESKTOP_CODEC() { return 'use_desktop_codec'; } static get DEPRECATED_USE_DESKTOP_CODEC() { return 'use_desktop_codec'; }
@ -6432,7 +6563,7 @@ class Preferences {
}, },
}, },
[Preferences.STREAM_TARGET_RESOLUTION]: { [Preferences.STREAM_TARGET_RESOLUTION]: {
'default': 'auto', 'default': '1080p',
'options': { 'options': {
'auto': __('default'), 'auto': __('default'),
'1080p': '1080p', '1080p': '1080p',
@ -6495,10 +6626,16 @@ class Preferences {
return options; return options;
})(), })(),
'ready': () => { 'ready': () => {
const options = Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE].options; const setting = Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE]
if (Object.keys(options).length <= 1) { const options = setting.options;
Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE].unsupported = true; const keys = Object.keys(options);
Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE].note = '⚠️ ' + __('browser-unsupported-feature');
if (keys.length <= 1) { // Unsupported
setting.unsupported = true;
setting.note = '⚠️ ' + __('browser-unsupported-feature');
} else {
// Set default value to the best codec profile
setting.default = keys[keys.length - 1];
} }
}, },
}, },
@ -6520,13 +6657,19 @@ class Preferences {
'default': false, 'default': false,
}, },
[Preferences.STREAM_TOUCH_CONTROLLER]: { [Preferences.STREAM_TOUCH_CONTROLLER]: {
'default': 'default', 'default': 'all',
'options': { 'options': {
'default': __('default'), 'default': __('default'),
'all': __('tc-all-games'), 'all': __('tc-all-games'),
'off': __('off'), 'off': __('off'),
}, },
'unsupported': !HAS_TOUCH_SUPPORT, 'unsupported': !HAS_TOUCH_SUPPORT,
'ready': () => {
const setting = Preferences.SETTINGS[Preferences.STREAM_TOUCH_CONTROLLER];
if (setting.unsupported) {
setting.default = 'off';
}
},
}, },
[Preferences.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: { [Preferences.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
'default': 'default', 'default': 'default',
@ -6592,8 +6735,21 @@ class Preferences {
})(), })(),
'ready': () => { 'ready': () => {
const pref = Preferences.SETTINGS[Preferences.MKB_ENABLED]; 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);
}, },
}, },
@ -6785,7 +6941,13 @@ class Preferences {
}, },
}, },
[Preferences.GAME_FORTNITE_FORCE_CONSOLE]: {
'default': false,
'note': __('fortnite-allow-stw-mode'),
},
// Deprecated // Deprecated
/*
[Preferences.DEPRECATED_USE_DESKTOP_CODEC]: { [Preferences.DEPRECATED_USE_DESKTOP_CODEC]: {
'default': false, 'default': false,
'migrate': function(savedPrefs, value) { 'migrate': function(savedPrefs, value) {
@ -6794,6 +6956,7 @@ class Preferences {
savedPrefs[Preferences.STREAM_CODEC_PROFILE] = quality; savedPrefs[Preferences.STREAM_CODEC_PROFILE] = quality;
}, },
}, },
*/
} }
#storage = localStorage; #storage = localStorage;
@ -6808,12 +6971,14 @@ class Preferences {
savedPrefs = JSON.parse(savedPrefs); savedPrefs = JSON.parse(savedPrefs);
for (let settingId in Preferences.SETTINGS) { for (let settingId in Preferences.SETTINGS) {
if (!(settingId in savedPrefs)) {
continue;
}
const setting = Preferences.SETTINGS[settingId]; const setting = Preferences.SETTINGS[settingId];
setting && setting.migrate && setting.migrate.call(this, savedPrefs, savedPrefs[settingId]); setting.ready && setting.ready.call(this);
setting && setting.ready && setting.ready.call(this);
/*
if (setting.migrate && !(settingId in savedPrefs)) {
setting.migrate.call(this, savedPrefs, savedPrefs[settingId]);
}
*/
} }
for (let settingId in Preferences.SETTINGS) { for (let settingId in Preferences.SETTINGS) {
@ -7192,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); funcStr = funcStr.replace(text, 'window.BX_EXPOSED["touch_layout_manager"] = this,' + text);
return funcStr; 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 = [ static #PATCH_ORDERS = [
@ -7224,6 +7401,8 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
ENABLE_NATIVE_MKB_BETA && 'mkbIsMouseAndKeyboardTitle', ENABLE_NATIVE_MKB_BETA && 'mkbIsMouseAndKeyboardTitle',
HAS_TOUCH_SUPPORT && 'patchUpdateInputConfigurationAsync', HAS_TOUCH_SUPPORT && 'patchUpdateInputConfigurationAsync',
], ],
getPref(Preferences.GAME_FORTNITE_FORCE_CONSOLE) && ['forceFortniteConsole'],
]; ];
// Only when playing // Only when playing
@ -8253,16 +8432,18 @@ div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module] {
font-size: 14px; font-size: 14px;
display: inline-block; display: inline-block;
padding: 12px 16px; padding: 12px 16px;
white-space: pre;
} }
.bx-toast-status { .bx-toast-status {
font-weight: bold; font-weight: bold;
font-size: 16px; font-size: 14px;
text-transform: uppercase; text-transform: uppercase;
display: inline-block; display: inline-block;
background: #515863; background: #515863;
padding: 12px 16px; padding: 12px 16px;
color: #fff; color: #fff;
white-space: pre;
} }
.bx-number-stepper span { .bx-number-stepper span {
@ -8870,9 +9051,10 @@ 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/people/social',
'https://accounts.xboxlive.com/family/memberXuid', 'https://peoplehub.xboxlive.com/users/me/people/recommendations',
'https://notificationinbox.xboxlive.com', 'https://notificationinbox.xboxlive.com',
// 'https://accounts.xboxlive.com/family/memberXuid',
]); ]);
} }
@ -8949,6 +9131,17 @@ function interceptHttpRequests() {
let request = arg[0]; let request = arg[0];
let url = (typeof request === 'string') ? request : request.url; 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')) { if (url.endsWith('/play')) {
BxEvent.dispatch(window, BxEvent.STREAM_LOADING); BxEvent.dispatch(window, BxEvent.STREAM_LOADING);
} }
@ -8985,7 +9178,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);
@ -9020,7 +9213,18 @@ function interceptHttpRequests() {
return promise.then(response => { return promise.then(response => {
return response.clone().json().then(obj => { return response.clone().json().then(obj => {
if (obj[0].supportedTabs.length > 0) { const xboxTitleId = JSON.parse(opts.body).titleIds[0];
GAME_XBOX_TITLE_ID = xboxTitleId;
const inputConfigs = obj[0];
let hasTouchSupport = inputConfigs.supportedTabs.length > 0;
if (!hasTouchSupport) {
const supportedInputTypes = inputConfigs.supportedInputTypes;
hasTouchSupport = supportedInputTypes.includes('NativeTouch');
}
if (hasTouchSupport) {
TouchController.disable(); TouchController.disable();
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, { BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
@ -9028,9 +9232,6 @@ function interceptHttpRequests() {
}); });
} else { } else {
TouchController.enable(); TouchController.enable();
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
GAME_XBOX_TITLE_ID = xboxTitleId;
TouchController.getCustomLayouts(xboxTitleId); TouchController.getCustomLayouts(xboxTitleId);
} }
@ -9268,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); return NATIVE_FETCH(...arg);
} }
} }
@ -9380,6 +9570,7 @@ function injectSettingsButton($parent) {
[Preferences.AUDIO_ENABLE_VOLUME_CONTROL]: __('enable-volume-control'), [Preferences.AUDIO_ENABLE_VOLUME_CONTROL]: __('enable-volume-control'),
[Preferences.AUDIO_MIC_ON_PLAYING]: __('enable-mic-on-startup'), [Preferences.AUDIO_MIC_ON_PLAYING]: __('enable-mic-on-startup'),
[Preferences.STREAM_DISABLE_FEEDBACK_DIALOG]: __('disable-post-stream-feedback-dialog'), [Preferences.STREAM_DISABLE_FEEDBACK_DIALOG]: __('disable-post-stream-feedback-dialog'),
[Preferences.GAME_FORTNITE_FORCE_CONSOLE]: '🎮 ' + __('fortnite-force-console-version'),
}, },
[__('mouse-and-keyboard')]: { [__('mouse-and-keyboard')]: {
@ -9790,13 +9981,13 @@ function injectStreamMenuButtons() {
} }
item.removedNodes.forEach($node => { item.removedNodes.forEach($node => {
if (!$node.className || !$node.className.startsWith) { if (!$node || !$node.className || !$node.className.startsWith) {
return; return;
} }
if ($node.className.startsWith('StreamMenu')) { if ($node.className.startsWith('StreamMenu')) {
if (!document.querySelector('div[class^=PureInStreamConfirmationModal]')) { if (!document.querySelector('div[class^=PureInStreamConfirmationModal]')) {
window.dispatchEvent(new Event('bx-stream-menu-hidden')); BxEvent.dispatch(window, BxEvent.STREAM_MENU_HIDDEN);
} }
} }
}); });
@ -9806,6 +9997,12 @@ function injectStreamMenuButtons() {
return; return;
} }
// Error Page: .PureErrorPage.ErrorScreen
if ($node.className.includes('PureErrorPage')) {
BxEvent.dispatch(window, BxEvent.STREAM_ERROR_PAGE);
return;
}
if (PREF_DISABLE_FEEDBACK_DIALOG && $node.className.startsWith('PostStreamFeedbackScreen')) { if (PREF_DISABLE_FEEDBACK_DIALOG && $node.className.startsWith('PostStreamFeedbackScreen')) {
const $btnClose = $node.querySelector('button'); const $btnClose = $node.querySelector('button');
$btnClose && $btnClose.click(); $btnClose && $btnClose.click();
@ -9814,7 +10011,7 @@ function injectStreamMenuButtons() {
// Render badges // Render badges
if ($node.className.startsWith('StreamMenu')) { if ($node.className.startsWith('StreamMenu')) {
window.dispatchEvent(new Event('bx-stream-menu-shown')); BxEvent.dispatch(window, BxEvent.STREAM_MENU_SHOWN);
// Hide Quick bar when closing HUD // Hide Quick bar when closing HUD
const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]'); const $btnCloseHud = document.querySelector('button[class*=StreamMenu-module__backButton]');
@ -10456,14 +10653,10 @@ function patchHistoryMethod(type) {
function onHistoryChanged(e) { function onHistoryChanged(e) {
if (e.arguments && e.arguments[0] && e.arguments[0].origin === 'better-xcloud') { if (e && e.arguments && e.arguments[0] && e.arguments[0].origin === 'better-xcloud') {
return; return;
} }
// Stop MKB listeners
MkbHandler.INSTANCE.destroy();
IS_PLAYING = false;
setTimeout(RemotePlay.detect, 10); setTimeout(RemotePlay.detect, 10);
const $settings = document.querySelector('.better_xcloud_settings'); const $settings = document.querySelector('.better_xcloud_settings');
@ -10471,28 +10664,10 @@ function onHistoryChanged(e) {
$settings.classList.add('bx-gone'); $settings.classList.add('bx-gone');
} }
const $quickBar = document.querySelector('.bx-quick-settings-bar');
if ($quickBar) {
$quickBar.classList.add('bx-gone');
}
STREAM_AUDIO_GAIN_NODE = null;
$STREAM_VIDEO = null;
StreamStats.onStoppedPlaying();
const $screenshotBtn = document.querySelector('.bx-screenshot-button');
if ($screenshotBtn) {
$screenshotBtn.style = '';
}
MouseCursorHider.stop();
TouchController.reset();
LoadingScreen.reset(); LoadingScreen.reset();
GamepadHandler.stopPolling();
setTimeout(checkHeader, 2000); setTimeout(checkHeader, 2000);
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
} }
@ -10587,6 +10762,40 @@ window.addEventListener(BxEvent.STREAM_PLAYING, e => {
} }
}); });
window.addEventListener(BxEvent.STREAM_ERROR_PAGE, e => {
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
});
window.addEventListener(BxEvent.STREAM_STOPPED, e => {
if (!IS_PLAYING) {
return;
}
IS_PLAYING = false;
// Stop MKB listeners
MkbHandler.INSTANCE.destroy();
const $quickBar = document.querySelector('.bx-quick-settings-bar');
if ($quickBar) {
$quickBar.classList.add('bx-gone');
}
STREAM_AUDIO_GAIN_NODE = null;
$STREAM_VIDEO = null;
StreamStats.onStoppedPlaying();
const $screenshotBtn = document.querySelector('.bx-screenshot-button');
if ($screenshotBtn) {
$screenshotBtn.style = '';
}
MouseCursorHider.stop();
TouchController.reset();
GamepadHandler.stopPolling();
});
PreloadedState.override(); PreloadedState.override();