From 01bd3141b3525beecf5dec5028293ec141b01207 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 3 Jan 2025 22:00:04 +0900 Subject: [PATCH] =?UTF-8?q?feat(YouTube=20-=20Swipe=20controls):=20Add=20s?= =?UTF-8?q?ettings=20-=20`Disable=20swipe=20to=20enter=20fullscreen=20mode?= =?UTF-8?q?`,=20`Disable=20swipe=20to=20exit=20fullscreen=20mode`=20&=20Ch?= =?UTF-8?q?ange=20default=20values=20=E2=80=8B=E2=80=8B-=20`Disable=20swip?= =?UTF-8?q?e=20to=20change=20video`,=20`Disable=20watch=20panel=20gestures?= =?UTF-8?q?`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extension/youtube/settings/Settings.java | 6 ++- .../youtube/swipe/controls/Fingerprints.kt | 48 +++++++++++++++++++ .../swipe/controls/SwipeControlsPatch.kt | 39 +++++++++++++-- .../util/fingerprint/LegacyFingerprint.kt | 5 +- .../youtube/settings/host/values/strings.xml | 16 +++++-- .../youtube/settings/xml/revanced_prefs.xml | 8 ++-- 6 files changed, 105 insertions(+), 17 deletions(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 6658ef05a..6a4c79418 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -515,8 +515,10 @@ public class Settings extends BaseSettings { */ @Deprecated // Patch is obsolete and no longer works with 19.09+ public static final BooleanSetting DISABLE_HDR_AUTO_BRIGHTNESS = new BooleanSetting("revanced_disable_hdr_auto_brightness", TRUE, true, parent(ENABLE_SWIPE_BRIGHTNESS)); - public static final BooleanSetting DISABLE_SWIPE_TO_SWITCH_VIDEO = new BooleanSetting("revanced_disable_swipe_to_switch_video", FALSE, true); - public static final BooleanSetting DISABLE_WATCH_PANEL_GESTURES = new BooleanSetting("revanced_disable_watch_panel_gestures", FALSE, true); + public static final BooleanSetting DISABLE_SWIPE_TO_SWITCH_VIDEO = new BooleanSetting("revanced_disable_swipe_to_switch_video", TRUE, true); + public static final BooleanSetting DISABLE_SWIPE_TO_ENTER_FULLSCREEN_MODE_BELOW_THE_PLAYER = new BooleanSetting("revanced_disable_swipe_to_enter_fullscreen_mode_below_the_player", TRUE, true); + public static final BooleanSetting DISABLE_SWIPE_TO_ENTER_FULLSCREEN_MODE_IN_THE_PLAYER = new BooleanSetting("revanced_disable_swipe_to_enter_fullscreen_mode_in_the_player", FALSE, true); + public static final BooleanSetting DISABLE_SWIPE_TO_EXIT_FULLSCREEN_MODE = new BooleanSetting("revanced_disable_swipe_to_exit_fullscreen_mode", FALSE, true); public static final BooleanSetting SWIPE_BRIGHTNESS_AUTO = new BooleanSetting("revanced_swipe_brightness_auto", TRUE, false, false); public static final FloatSetting SWIPE_BRIGHTNESS_VALUE = new FloatSetting("revanced_swipe_brightness_value", -1.0f, false, false); diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/Fingerprints.kt index e0a892c49..838a52ecf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/Fingerprints.kt @@ -5,8 +5,12 @@ import app.revanced.patches.youtube.utils.resourceid.autoNavScrollCancelPadding import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementOverlay import app.revanced.util.containsLiteralInstruction import app.revanced.util.fingerprint.legacyFingerprint +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstruction import app.revanced.util.or import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.reference.MethodReference internal val fullScreenEngagementOverlayFingerprint = legacyFingerprint( name = "fullScreenEngagementOverlayFingerprint", @@ -73,3 +77,47 @@ internal val watchPanelGesturesChannelBarFingerprint = legacyFingerprint( method.containsLiteralInstruction(WATCH_PANEL_GESTURES_SECONDARY_FEATURE_FLAG) } ) + +/** + * fuzzyPatternScanThreshold is required to maintain compatibility with YouTube v18.29.38 ~ v18.32.39. + * + * TODO: Remove fuzzyPatternScanThreshold if support for YouTube v18.29.38 to v18.32.39 is dropped. + */ +internal val playerGestureConfigSyntheticFingerprint = legacyFingerprint( + name = "playerGestureConfigSyntheticFingerprint", + fuzzyPatternScanThreshold = 5, + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Ljava/lang/Object;"), + opcodes = listOf( + Opcode.SGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, // playerGestureConfig.downAndOutLandscapeAllowed + Opcode.MOVE_RESULT, + Opcode.CHECK_CAST, + Opcode.IPUT_BOOLEAN, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, // playerGestureConfig.downAndOutPortraitAllowed + Opcode.MOVE_RESULT, + Opcode.IPUT_BOOLEAN, + Opcode.RETURN_VOID, + ), + customFingerprint = { method, classDef -> + // This method is always called "a" because this kind of class always has a single method. + method.name == "a" && + classDef.methods.count() == 2 && + method.indexOfFirstInstruction { + val reference = getReference() + reference?.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" && + reference.parameterTypes.isEmpty() && + reference.returnType == "Z" + } >= 0 + }, +) \ No newline at end of file diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt index 5e459e855..af0c104b5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt @@ -1,6 +1,7 @@ package app.revanced.patches.youtube.swipe.controls import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction @@ -29,9 +30,11 @@ import app.revanced.patches.youtube.utils.settings.settingsPatch import app.revanced.util.ResourceGroup import app.revanced.util.copyResources import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall +import app.revanced.util.fingerprint.matchOrThrow import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.fingerprint.mutableClassOrThrow import app.revanced.util.getReference +import app.revanced.util.getWalkerMethod import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstLiteralInstruction import app.revanced.util.indexOfFirstLiteralInstructionOrThrow @@ -107,7 +110,7 @@ val swipeControlsPatch = bytecodePatch( var settingArray = arrayOf( "PREFERENCE_SCREEN: SWIPE_CONTROLS", - "SETTINGS: DISABLE_WATCH_PANEL_GESTURES" + "SETTINGS: DISABLE_SWIPE_TO_ENTER_FULLSCREEN_MODE_BELOW_THE_PLAYER" ) // region patch for disable HDR auto brightness @@ -143,12 +146,12 @@ val swipeControlsPatch = bytecodePatch( // endregion - // region patch for disable watch panel gestures + // region patch for disable swipe to enter fullscreen mode (below the player) if (!is_19_36_or_greater) { watchPanelGesturesFingerprint.injectLiteralInstructionBooleanCall( WATCH_PANEL_GESTURES_PRIMARY_FEATURE_FLAG, - "$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z" + "$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableSwipeToEnterFullscreenModeBelowThePlayer()Z" ) } else { watchPanelGesturesAlternativeFingerprint.methodOrThrow().apply { @@ -188,7 +191,7 @@ val swipeControlsPatch = bytecodePatch( addInstructionsWithLabels( targetIndex, """ - invoke-static {}, $EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z + invoke-static {}, $EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableSwipeToEnterFullscreenModeBelowThePlayer()Z move-result v${fieldInstruction.registerA} if-eqz v${fieldInstruction.registerA}, :disable iget-object v${fieldInstruction.registerA}, v${fieldInstruction.registerB}, $fieldReference @@ -201,12 +204,38 @@ val swipeControlsPatch = bytecodePatch( if (is_19_15_or_greater) { watchPanelGesturesChannelBarFingerprint.injectLiteralInstructionBooleanCall( WATCH_PANEL_GESTURES_SECONDARY_FEATURE_FLAG, - "$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z" + "$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableSwipeToEnterFullscreenModeBelowThePlayer()Z" ) } // endregion + // region patch for disable swipe to enter fullscreen mode (in the player) and disable swipe to exit fullscreen mode + + playerGestureConfigSyntheticFingerprint.matchOrThrow().let { + val endIndex = it.patternMatch!!.endIndex + + mapOf( + 3 to "disableSwipeToEnterFullscreenModeInThePlayer", + 9 to "disableSwipeToExitFullscreenMode" + ).forEach { (offSet, methodName) -> + it.getWalkerMethod(endIndex - offSet).apply { + val index = implementation!!.instructions.lastIndex + val register = getInstruction(index).registerA + + addInstructions( + index, + """ + invoke-static {v$register}, $EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->$methodName(Z)Z + move-result v$register + """ + ) + } + } + } + + // endregion + // region copy resources getContext().copyResources( diff --git a/patches/src/main/kotlin/app/revanced/util/fingerprint/LegacyFingerprint.kt b/patches/src/main/kotlin/app/revanced/util/fingerprint/LegacyFingerprint.kt index ef7e9dbcb..36dc8bdb2 100644 --- a/patches/src/main/kotlin/app/revanced/util/fingerprint/LegacyFingerprint.kt +++ b/patches/src/main/kotlin/app/revanced/util/fingerprint/LegacyFingerprint.kt @@ -134,16 +134,17 @@ fun Pair.injectLiteralInstructionViewCall( internal fun legacyFingerprint( name: String, + fuzzyPatternScanThreshold: Int = 0, accessFlags: Int? = null, returnType: String? = null, parameters: List? = null, opcodes: List? = null, strings: List? = null, literals: List? = null, - customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null + customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null, ) = Pair( name, - fingerprint { + fingerprint(fuzzyPatternScanThreshold = fuzzyPatternScanThreshold) { if (accessFlags != null) { accessFlags(accessFlags) } diff --git a/patches/src/main/resources/youtube/settings/host/values/strings.xml b/patches/src/main/resources/youtube/settings/host/values/strings.xml index dc3c41d7e..b26b9bafb 100644 --- a/patches/src/main/resources/youtube/settings/host/values/strings.xml +++ b/patches/src/main/resources/youtube/settings/host/values/strings.xml @@ -1484,12 +1484,18 @@ No margins on top and bottom of player." Disable auto HDR brightness Auto HDR brightness is disabled. Auto HDR brightness is enabled. - Disable watch panel gestures - Entering fullscreen when swiping down below the video player is disabled. - Entering fullscreen when swiping down below the video player is enabled. Disable swipe to change video - Swiping up / down will not play the next / previous video. - Swiping up / down will play the next / previous video. + Swiping up / down in fullscreen mode will not change to the next / previous video. + Swiping up / down in fullscreen mode will change to the next / previous video. + Disable swipe to enter fullscreen mode (below the player) + Swiping down below the player will not enter fullscreen mode. + Swiping down below the player will enter fullscreen mode. + Disable swipe to enter fullscreen mode (in the player) + Swiping up in the player will not enter fullscreen mode. + Swiping up in the player will enter fullscreen mode. + Disable swipe to exit fullscreen mode + Swiping down in fullscreen will not exit fullscreen mode. + Swiping down in fullscreen will exit fullscreen mode. Auto diff --git a/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml index f87a6a472..22284a761 100644 --- a/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -672,10 +672,12 @@ - + -