Compare commits

...

16 Commits

Author SHA1 Message Date
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
redphx
2d9ee16531 Bump version to 3.1.4 2024-02-07 21:43:49 +07:00
redphx
21168803e0 Set default value of STREAM_CODEC_PROFILE to the best codec profile 2024-02-07 21:37:35 +07:00
redphx
3068aa8a06 Minor fix for touch control 2024-02-07 18:40:36 +07:00
redphx
b6b9ec49f6 Update touch support detection in Remote Play 2024-02-07 17:35:13 +07:00
redphx
4dc60f965f Minor fix 2024-02-07 15:22:27 +07:00
redphx
2142c4a83c Only request custom touch control when the game is focused 2024-02-07 15:15:53 +07:00
redphx
6b090194c9 Only show toast when the layout has been changed 2024-02-07 14:56:36 +07:00
redphx
a878150ec3 Show a toast with layout's name when switching touch control layout 2024-02-07 11:09:10 +07:00
redphx
5fb1dded42 Change default value of "STREAM_TARGET_RESOLUTION" to "1080p" 2024-02-07 10:53:12 +07:00
redphx
ac6879c189 Change default value of "STREAM_TOUCH_CONTROLLER" to "all" 2024-02-07 10:52:04 +07:00
redphx
b8efaf9648 Fix not loading Better xCloud after logging in 2024-02-06 22:53:53 +07:00
2 changed files with 148 additions and 65 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.3 // @version 3.1.5
// ==/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.3 // @version 3.1.5
// @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,7 +14,7 @@
// ==/UserScript== // ==/UserScript==
'use strict'; 'use strict';
const SCRIPT_VERSION = '3.1.3'; const SCRIPT_VERSION = '3.1.5';
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;
@@ -38,6 +39,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 = {
@@ -1320,8 +1332,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",
@@ -2460,6 +2474,17 @@ 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",
"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": { "touch-controller": {
"de-DE": "Touch-Controller", "de-DE": "Touch-Controller",
"en-US": "Touch controller", "en-US": "Touch controller",
@@ -3476,53 +3501,51 @@ 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 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;
} }
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
NATIVE_FETCH(url) NATIVE_FETCH(url)
.then(resp => resp.json()) .then(resp => resp.json())
.then(json => { .then(json => {
// Normalize data const layouts = {};
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) {}
json.layouts.forEach(async file => {
const layoutUrl = `${baseUrl}/layouts/${file}.json`;
const json = await (await NATIVE_FETCH(layoutUrl)).json();
Object.assign(layouts, json.layouts);
});
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(() => { .catch(() => {
TouchController.#customLayouts[xboxTitleId] = null; // Retry
// Wait for BX_EXPOSED.touch_layout_manager TouchController.getCustomLayouts(xboxTitleId, retries + 1);
setTimeout(() => dispatchLayouts(null), 1000);
}); });
} }
@@ -3531,9 +3554,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();
@@ -3541,23 +3567,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);
@@ -3620,6 +3669,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;
@@ -3627,7 +3677,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;
} }
@@ -3637,6 +3693,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();
} }
@@ -6440,7 +6497,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',
@@ -6503,10 +6560,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];
} }
}, },
}, },
@@ -6528,13 +6591,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',
@@ -6794,6 +6863,7 @@ class Preferences {
}, },
// Deprecated // Deprecated
/*
[Preferences.DEPRECATED_USE_DESKTOP_CODEC]: { [Preferences.DEPRECATED_USE_DESKTOP_CODEC]: {
'default': false, 'default': false,
'migrate': function(savedPrefs, value) { 'migrate': function(savedPrefs, value) {
@@ -6802,6 +6872,7 @@ class Preferences {
savedPrefs[Preferences.STREAM_CODEC_PROFILE] = quality; savedPrefs[Preferences.STREAM_CODEC_PROFILE] = quality;
}, },
}, },
*/
} }
#storage = localStorage; #storage = localStorage;
@@ -6816,12 +6887,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) {
@@ -8261,16 +8334,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 {
@@ -9028,7 +9103,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, {
@@ -9036,9 +9122,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);
} }