From 3562d0318e3ff8b44bc3d1a39750a21ba5359caa Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:54:35 +0700 Subject: [PATCH] Don't disable touch on native touch-supported games --- src/modules/patcher.ts | 22 +++------------- src/utils/bx-exposed.ts | 58 +++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/modules/patcher.ts b/src/modules/patcher.ts index fb2ee2c..23ff5d2 100644 --- a/src/modules/patcher.ts +++ b/src/modules/patcher.ts @@ -323,26 +323,12 @@ if (match) { return false; } - let newCode = ''; - if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off') { - newCode = 'return;'; - } else { - newCode = ` -const gamepads = window.navigator.getGamepads(); -let gamepadFound = false; - -for (let gamepad of gamepads) { - if (gamepad && gamepad.connected) { - gamepadFound = true; - break; - } -} - -if (gamepadFound) { + const newCode = ` +const titleInfo = window.BX_EXPOSED.getTitleInfo(); +if (!titleInfo.details.hasTouchSupport) { return; } `; - } str = str.replace(text, newCode + text); return str; @@ -492,7 +478,7 @@ const PLAYING_PATCH_ORDERS = [ ['playVibration'], STATES.hasTouchSupport && getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && ['exposeTouchLayoutManager'], - STATES.hasTouchSupport && (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off' || getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) && ['disableTakRenderer'], + STATES.hasTouchSupport && getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off' && ['disableTakRenderer'], BX_FLAGS.EnableXcloudLogging && ['enableConsoleLogging'], diff --git a/src/utils/bx-exposed.ts b/src/utils/bx-exposed.ts index 4aacde0..1b0e02d 100644 --- a/src/utils/bx-exposed.ts +++ b/src/utils/bx-exposed.ts @@ -36,31 +36,55 @@ export const BxExposed = { } }, + getTitleInfo: () => STATES.currentStream.titleInfo, + modifyTitleInfo: (titleInfo: XcloudTitleInfo): XcloudTitleInfo => { // Clone the object since the original is read-only titleInfo = structuredClone(titleInfo); - const touchControllerAvailability = getPref(PrefKey.STREAM_TOUCH_CONTROLLER); + if (STATES.hasTouchSupport) { + let touchControllerAvailability = getPref(PrefKey.STREAM_TOUCH_CONTROLLER); + let supportedInputTypes = titleInfo.details.supportedInputTypes; - let supportedInputTypes = titleInfo.details.supportedInputTypes; + // Disable touch control when gamepad found + if (touchControllerAvailability !== 'off' && getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) { + const gamepads = window.navigator.getGamepads(); + let gamepadFound = false; - // Remove MKB support on mobile browsers - if (UserAgent.isMobile()) { - supportedInputTypes = supportedInputTypes.filter(i => i !== 'MKB'); + for (let gamepad of gamepads) { + if (gamepad && gamepad.connected) { + gamepadFound = true; + break; + } + } + + gamepadFound && (touchControllerAvailability = 'off'); + } + + // Remove MKB support on mobile browsers + if (UserAgent.isMobile()) { + supportedInputTypes = supportedInputTypes.filter(i => i !== InputType.MKB); + } + + if (touchControllerAvailability === 'off') { + // Disable touch on all games (not native touch) + supportedInputTypes = supportedInputTypes.filter(i => i !== InputType.CUSTOM_TOUCH_OVERLAY && i !== InputType.GENERIC_TOUCH); + } + + // Pre-check supported input types + titleInfo.details.hasMkbSupport = supportedInputTypes.includes(InputType.MKB); + titleInfo.details.hasTouchSupport = supportedInputTypes.includes(InputType.NATIVE_TOUCH) && + !supportedInputTypes.includes(InputType.CUSTOM_TOUCH_OVERLAY) && + !supportedInputTypes.includes(InputType.GENERIC_TOUCH); + + if (!titleInfo.details.hasTouchSupport && touchControllerAvailability === 'all') { + // Add generic touch support for non touch-supported games + supportedInputTypes.push(InputType.GENERIC_TOUCH); + } + + titleInfo.details.supportedInputTypes = supportedInputTypes; } - // Pre-check supported input types - titleInfo.details.hasMkbSupport = supportedInputTypes.includes(InputType.MKB); - titleInfo.details.hasTouchSupport = supportedInputTypes.includes(InputType.NATIVE_TOUCH) && - !supportedInputTypes.includes(InputType.CUSTOM_TOUCH_OVERLAY) && - !supportedInputTypes.includes(InputType.GENERIC_TOUCH); - - // Add generic touch support for non touch-supported games - if (!titleInfo.details.hasTouchSupport && touchControllerAvailability === 'all') { - supportedInputTypes.push(InputType.GENERIC_TOUCH); - } - titleInfo.details.supportedInputTypes = supportedInputTypes; - // Save this info in STATES STATES.currentStream.titleInfo = titleInfo; BxEvent.dispatch(window, BxEvent.TITLE_INFO_READY);