Compare commits

...

5 Commits

Author SHA1 Message Date
redphx
1d018cc0a3 Test native MKB feature with Remote Play 2024-01-21 18:05:19 +07:00
redphx
886a23e5ac Bump version to 3.0.5 2024-01-21 12:27:57 +07:00
redphx
309feca3f9 Only set "pointerEvents" property on touch-supported devices 2024-01-21 11:55:17 +07:00
redphx
82a9a91534 Fix Clarity Boost warning not working 2024-01-21 11:32:52 +07:00
redphx
7248dac3f6 Fix patches 2024-01-21 11:15:09 +07:00
2 changed files with 73 additions and 31 deletions

View File

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

View File

@@ -1,7 +1,7 @@
// ==UserScript==
// @name Better xCloud
// @namespace https://github.com/redphx
// @version 3.0.4
// @version 3.0.5
// @description Improve Xbox Cloud Gaming (xCloud) experience
// @author redphx
// @license MIT
@@ -13,14 +13,14 @@
// ==/UserScript==
'use strict';
const SCRIPT_VERSION = '3.0.4';
const SCRIPT_VERSION = '3.0.5';
const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud';
const ENABLE_XCLOUD_LOGGER = false;
const ENABLE_PRELOAD_BX_UI = false;
const ENABLE_NATIVE_MKB_BETA = false;
window.NATIVE_MKB_TITLES = [
'BT5P2X999VH2',
// Not working anymore
// '9PMQDM08SNK9', // MS Flight Simulator
// '9NP1P1WFS0LB', // Halo Infinite
@@ -37,6 +37,16 @@ window.NATIVE_MKB_TITLES = [
// '9P731Z4BBCT3', // Atomic Heart
];
window.REMOTE_PLAY_NATIVE_MKB_TITLES = [
// DOOM 64
'DOOM64',
'BT5P2X999VH2',
// Cyperpunk 2077
'222473492',
'BX3M8L83BBRW',
];
console.log(`[Better xCloud] readyState: ${document.readyState}`);
const BxEvent = {
@@ -6720,12 +6730,32 @@ class Patcher {
// Enable Remote Play feature
remotePlayConnectMode: function(funcStr) {
const text = 'connectMode:"cloud-connect"';
const text = 'connectMode:"cloud-connect",';
if (!funcStr.includes(text)) {
return false;
}
return funcStr.replace(text, `connectMode:window.BX_REMOTE_PLAY_CONFIG?"xhome-connect":"cloud-connect",remotePlayServerId:(window.BX_REMOTE_PLAY_CONFIG&&window.BX_REMOTE_PLAY_CONFIG.serverId)||''`);
const newCode = `
connectMode: window.BX_REMOTE_PLAY_CONFIG ? "xhome-connect" : "cloud-connect",
remotePlayServerId: (window.BX_REMOTE_PLAY_CONFIG && window.BX_REMOTE_PLAY_CONFIG.serverId) || '',
`;
return funcStr.replace(text, newCode);
},
// Remote Play MKB support
remotePlayMkb: function(funcStr) {
const text = 'handleRemotePlayTitleInputConfig(e){';
if (!funcStr.includes(text)) {
return false;
}
const newCode = `
const supportMkb = window.REMOTE_PLAY_NATIVE_MKB_TITLES.includes(e.titleId);
this.gameStream.session.updateInputConfigurationAsync({ enableMouseAndKeyboard: supportMkb });
`;
return funcStr.replace(text, text + newCode);
},
// Disable trackEvent() function
@@ -6808,13 +6838,11 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
];
// Enable native Mouse and Keyboard support
if (getPref(Preferences.MKB_ENABLED)) {
newSettings.push('EnableMouseAndKeyboard: true');
newSettings.push('ShowMouseKeyboardSetting: true');
newSettings.push('EnableMouseAndKeyboard: true');
newSettings.push('ShowMouseKeyboardSetting: true');
if (getPref(Preferences.MKB_ABSOLUTE_MOUSE)) {
newSettings.push('EnableAbsoluteMouse: true');
}
if (getPref(Preferences.MKB_ABSOLUTE_MOUSE)) {
newSettings.push('EnableAbsoluteMouse: true');
}
const newCode = newSettings.join(',');
@@ -6824,12 +6852,12 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
},
mkbIsMouseAndKeyboardTitle: function(funcStr) {
const text = 'isMouseAndKeyboardTitle:()=>yn';
const text = 'isMouseAndKeyboardTitle:()=>';
if (!funcStr.includes(text)) {
return false;
}
return funcStr.replace(text, `isMouseAndKeyboardTitle:()=>(function(e) { return e && e.details ? window.NATIVE_MKB_TITLES.includes(e.details.productId) : true; })`);
return funcStr.replace(text, text + `(function(e) { return e && e.details ? (window.BX_REMOTE_PLAY_CONFIG ? window.REMOTE_PLAY_NATIVE_MKB_TITLES : window.NATIVE_MKB_TITLES).includes(e.details.productId) : true; }),uwuwu:()=>`);
},
mkbMouseAndKeyboardEnabled: function(funcStr) {
@@ -6900,17 +6928,25 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
getPref(Preferences.UI_LAYOUT) === 'tv' && ['tvLayout'],
ENABLE_XCLOUD_LOGGER && ['enableXcloudLogger'],
ENABLE_XCLOUD_LOGGER && [
'enableXcloudLogger',
'enableConsoleLogging',
],
getPref(Preferences.BLOCK_TRACKING) && [
'disableTrackEvent',
'blockWebRtcStatsCollector',
],
getPref(Preferences.REMOTE_PLAY_ENABLED) && [
'remotePlayDirectConnectUrl',
'remotePlayKeepAlive',
],
[
'overrideSettings',
getPref(Preferences.REMOTE_PLAY_ENABLED) && 'remotePlayDirectConnectUrl',
getPref(Preferences.BLOCK_TRACKING) && 'disableTrackEvent',
'mkbIsMouseAndKeyboardTitle',
HAS_TOUCH_SUPPORT && 'patchUpdateInputConfigurationAsync',
ENABLE_NATIVE_MKB_BETA && getPref(Preferences.MKB_ENABLED) && 'mkbIsMouseAndKeyboardTitle',
ENABLE_XCLOUD_LOGGER && 'enableConsoleLogging',
getPref(Preferences.REMOTE_PLAY_ENABLED) && 'remotePlayKeepAlive',
getPref(Preferences.BLOCK_TRACKING) && 'blockWebRtcStatsCollector',
],
];
@@ -6922,9 +6958,11 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
ENABLE_XCLOUD_LOGGER && ['enableConsoleLogging'],
getPref(Preferences.REMOTE_PLAY_ENABLED) && ['remotePlayMkb'],
[
'disableGamepadDisconnectedScreen',
ENABLE_NATIVE_MKB_BETA && getPref(Preferences.MKB_ENABLED) && 'mkbMouseAndKeyboardEnabled',
'mkbMouseAndKeyboardEnabled',
],
];
@@ -7027,6 +7065,10 @@ if (window.BX_VIBRATION_INTENSITY && window.BX_VIBRATION_INTENSITY < 1) {
static #cleanupPatches() {
for (let groupIndex = Patcher.#PATCH_ORDERS.length - 1; groupIndex >= 0; groupIndex--) {
const group = Patcher.#PATCH_ORDERS[groupIndex];
if (group === false) {
Patcher.#PATCH_ORDERS.splice(groupIndex, 1);
continue;
}
for (let patchIndex = group.length - 1; patchIndex >= 0; patchIndex--) {
const patchName = group[patchIndex];
@@ -7830,11 +7872,11 @@ div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module] {
overflow: hidden;
}
.bx-quick-settings-tab-contents div:not([data-clarity-boost="true"]) .bx-clarity-boost-warning {
.bx-quick-settings-bar:not([data-clarity-boost="true"]) .bx-clarity-boost-warning {
display: none;
}
.bx-quick-settings-tab-contents div[data-clarity-boost="true"] .bx-clarity-boost-warning {
.bx-quick-settings-bar[data-clarity-boost="true"] .bx-clarity-boost-warning {
display: block;
margin: 0px 8px;
padding: 12px;
@@ -7844,7 +7886,7 @@ div[class*=StreamMenu-module__menuContainer] > div[class*=Menu-module] {
border-radius: 4px;
}
.bx-quick-settings-tab-contents div[data-clarity-boost="true"] > div[data-type="video"] {
.bx-quick-settings-bar[data-clarity-boost="true"] div[data-type="video"] {
display: none;
}
@@ -8877,9 +8919,7 @@ function interceptHttpRequests() {
overrides.inputConfiguration = overrides.inputConfiguration || {};
overrides.inputConfiguration.enableVibration = true;
if (ENABLE_NATIVE_MKB_BETA) {
overrides.inputConfiguration.enableMouseAndKeyboard = getPref(Preferences.MKB_ENABLED);
}
overrides.inputConfiguration.enableMouseAndKeyboard = true;
// Enable touch controller
if (TouchController.isEnabled()) {
@@ -9384,8 +9424,10 @@ function cloneStreamHudButton($orgButton, label, svg_icon) {
}
};
$container.addEventListener('transitionstart', onTransitionStart);
$container.addEventListener('transitionend', onTransitionEnd);
if (HAS_TOUCH_SUPPORT) {
$container.addEventListener('transitionstart', onTransitionStart);
$container.addEventListener('transitionend', onTransitionEnd);
}
const $button = $container.querySelector('button');
$button.setAttribute('title', label);
@@ -10091,7 +10133,7 @@ function onStreamStarted($video) {
}
// Enable MKB
if (getPref(Preferences.MKB_ENABLED) && (!ENABLE_NATIVE_MKB_BETA || !window.NATIVE_MKB_TITLES.includes(GAME_PRODUCT_ID))) {
if (getPref(Preferences.MKB_ENABLED) && (!window.NATIVE_MKB_TITLES.includes(GAME_PRODUCT_ID))) {
console.log('Emulate MKB');
MkbHandler.INSTANCE.init();
}