Compare commits

...

11 Commits

2 changed files with 98 additions and 34 deletions

View File

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

View File

@ -1,11 +1,12 @@
// ==UserScript==
// @name Better xCloud
// @namespace https://github.com/redphx
// @version 3.1.3
// @version 3.1.4
// @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx
// @license MIT
// @match https://www.xbox.com/*/play*
// @match https://www.xbox.com/*/auth/msa?*loggedIn*
// @run-at document-start
// @grant none
// @updateURL https://raw.githubusercontent.com/redphx/better-xcloud/main/better-xcloud.meta.js
@ -13,7 +14,7 @@
// ==/UserScript==
'use strict';
const SCRIPT_VERSION = '3.1.3';
const SCRIPT_VERSION = '3.1.4';
const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
const ENABLE_XCLOUD_LOGGER = false;
@ -38,6 +39,17 @@ window.NATIVE_MKB_TITLES = [
// '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}`);
const BxEvent = {
@ -1320,6 +1332,7 @@ const Translations = {
"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",
"ru-RU": "Использование этой функции при игре онлайн может рассматриваться как читерство",
"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",
},
@ -2460,6 +2473,15 @@ const Translations = {
"vi-VN": "Phía trên bên phải",
"zh-CN": "右上角",
},
"touch-control-layout": {
"de-DE": "Touch-Steuerungslayout",
"en-US": "Touch control layout",
"ja-JP": "タッチコントロールレイアウト",
"pt-BR": "Layout do controle por toque",
"ru-RU": "Расположение сенсорных кнопок",
"uk-UA": "Розташування сенсорного керування",
"vi-VN": "Bố cục điều khiển cảm ứng",
},
"touch-controller": {
"de-DE": "Touch-Controller",
"en-US": "Touch controller",
@ -3531,9 +3553,12 @@ class TouchController {
return;
}
const layoutChanged = TouchController.#currentLayoutId !== layoutId;
TouchController.#currentLayoutId = layoutId;
xboxTitleId = '' + xboxTitleId;
// Get layout data
const layoutData = TouchController.#customLayouts[xboxTitleId];
if (!xboxTitleId || !layoutId || !layoutData) {
TouchController.#enable && TouchController.#showDefault();
@ -3541,20 +3566,25 @@ class TouchController {
}
const layout = (layoutData.layouts[layoutId] || layoutData.layouts[layoutData.default_layout]);
layout && setTimeout(() => {
window.BX_EXPOSED.touch_layout_manager.changeLayoutForScope({
type: 'showLayout',
scope: xboxTitleId,
subscope: 'base',
layout: {
id: 'System.Standard',
displayName: 'System',
layoutFile: {
content: layout.content,
},
}
});
}, delay);
if (layout) {
// Show a toast with layout's name
layoutChanged && Toast.show(__('touch-control-layout'), layout.name);
setTimeout(() => {
window.BX_EXPOSED.touch_layout_manager.changeLayoutForScope({
type: 'showLayout',
scope: xboxTitleId,
subscope: 'base',
layout: {
id: 'System.Standard',
displayName: 'System',
layoutFile: {
content: layout.content,
},
}
});
}, delay);
}
}
static setup() {
@ -3620,6 +3650,7 @@ class TouchController {
setTimeout(TouchController.#show, 1000);
});
let focused = false;
dataChannel.addEventListener('message', msg => {
if (msg.origin === 'better-xcloud' || typeof msg.data !== 'string') {
return;
@ -3627,7 +3658,13 @@ class TouchController {
// Dispatch a message to display generic touch controller
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;
}
@ -3637,6 +3674,7 @@ class TouchController {
const json = JSON.parse(JSON.parse(msg.data).content);
TouchController.#toggleBar(json.focused);
focused = json.focused;
if (!json.focused) {
TouchController.#show();
}
@ -6440,7 +6478,7 @@ class Preferences {
},
},
[Preferences.STREAM_TARGET_RESOLUTION]: {
'default': 'auto',
'default': '1080p',
'options': {
'auto': __('default'),
'1080p': '1080p',
@ -6503,10 +6541,16 @@ class Preferences {
return options;
})(),
'ready': () => {
const options = Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE].options;
if (Object.keys(options).length <= 1) {
Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE].unsupported = true;
Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE].note = '⚠️ ' + __('browser-unsupported-feature');
const setting = Preferences.SETTINGS[Preferences.STREAM_CODEC_PROFILE]
const options = setting.options;
const keys = Object.keys(options);
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];
}
},
},
@ -6528,13 +6572,19 @@ class Preferences {
'default': false,
},
[Preferences.STREAM_TOUCH_CONTROLLER]: {
'default': 'default',
'default': 'all',
'options': {
'default': __('default'),
'all': __('tc-all-games'),
'off': __('off'),
},
'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]: {
'default': 'default',
@ -6794,6 +6844,7 @@ class Preferences {
},
// Deprecated
/*
[Preferences.DEPRECATED_USE_DESKTOP_CODEC]: {
'default': false,
'migrate': function(savedPrefs, value) {
@ -6802,6 +6853,7 @@ class Preferences {
savedPrefs[Preferences.STREAM_CODEC_PROFILE] = quality;
},
},
*/
}
#storage = localStorage;
@ -6816,12 +6868,14 @@ class Preferences {
savedPrefs = JSON.parse(savedPrefs);
for (let settingId in Preferences.SETTINGS) {
if (!(settingId in savedPrefs)) {
continue;
}
const setting = Preferences.SETTINGS[settingId];
setting && setting.migrate && setting.migrate.call(this, savedPrefs, savedPrefs[settingId]);
setting && setting.ready && setting.ready.call(this);
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) {
@ -8261,16 +8315,18 @@ div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module] {
font-size: 14px;
display: inline-block;
padding: 12px 16px;
white-space: pre;
}
.bx-toast-status {
font-weight: bold;
font-size: 16px;
font-size: 14px;
text-transform: uppercase;
display: inline-block;
background: #515863;
padding: 12px 16px;
color: #fff;
white-space: pre;
}
.bx-number-stepper span {
@ -9028,7 +9084,18 @@ function interceptHttpRequests() {
return promise.then(response => {
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();
BxEvent.dispatch(window, BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, {
@ -9036,9 +9103,6 @@ function interceptHttpRequests() {
});
} else {
TouchController.enable();
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
GAME_XBOX_TITLE_ID = xboxTitleId;
TouchController.getCustomLayouts(xboxTitleId);
}