From 503b7eb8d413ef7f248394f128f3b2a6f3192ba6 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 1 Apr 2025 20:57:03 +0200 Subject: [PATCH] fix(YouTube): Combine multiple seekbar patches into a single patch (#4705) --- patches/api/patches.api | 8 +++ .../DisablePreciseSeekingGesturePatch.kt | 21 ++----- .../seekbar/EnableSeekbarTappingPatch.kt | 12 ---- .../seekbar/EnableSlideToSeekPatch.kt | 23 ++------ .../interaction/seekbar/HideSeekbarPatch.kt | 46 ++++++++++++++++ .../interaction/seekbar/SeekbarPatch.kt | 31 +++++++++++ .../seekbar/SeekbarThumbnailsPatch.kt | 19 +++---- .../layout/hide/seekbar/HideSeekbarPatch.kt | 55 ++----------------- 8 files changed, 107 insertions(+), 108 deletions(-) create mode 100644 patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/HideSeekbarPatch.kt create mode 100644 patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarPatch.kt diff --git a/patches/api/patches.api b/patches/api/patches.api index e672bf3ad..fc2d0de32 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -1096,6 +1096,14 @@ public final class app/revanced/patches/youtube/interaction/seekbar/EnableSlideT public static final fun getEnableSlideToSeekPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } +public final class app/revanced/patches/youtube/interaction/seekbar/HideSeekbarPatchKt { + public static final fun getHideSeekbarPatch ()Lapp/revanced/patcher/patch/BytecodePatch; +} + +public final class app/revanced/patches/youtube/interaction/seekbar/SeekbarPatchKt { + public static final fun getSeekbarPatch ()Lapp/revanced/patcher/patch/BytecodePatch; +} + public final class app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatchKt { public static final fun getSeekbarThumbnailsPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt index 4f0357954..8cecc1400 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt @@ -11,8 +11,10 @@ import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch +private const val EXTENSION_CLASS_DESCRIPTOR = + "Lapp/revanced/extension/youtube/patches/DisablePreciseSeekingGesturePatch;" + val disablePreciseSeekingGesturePatch = bytecodePatch( - name = "Disable precise seeking gesture", description = "Adds an option to disable precise seeking when swiping up on the seekbar.", ) { dependsOn( @@ -21,25 +23,12 @@ val disablePreciseSeekingGesturePatch = bytecodePatch( addResourcesPatch, ) - compatibleWith( - "com.google.android.youtube"( - "19.16.39", - "19.25.37", - "19.34.42", - "19.43.41", - "19.47.53", - "20.07.39", - ), - ) - execute { addResources("youtube", "interaction.seekbar.disablePreciseSeekingGesturePatch") PreferenceScreen.SEEKBAR.addPreferences( SwitchPreference("revanced_disable_precise_seeking_gesture"), ) - val extensionMethodDescriptor = - "Lapp/revanced/extension/youtube/patches/DisablePreciseSeekingGesturePatch;" allowSwipingUpGestureFingerprint.match( swipingUpGestureParentFingerprint.originalClassDef, @@ -47,7 +36,7 @@ val disablePreciseSeekingGesturePatch = bytecodePatch( addInstructionsWithLabels( 0, """ - invoke-static { }, $extensionMethodDescriptor->isGestureDisabled()Z + invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->isGestureDisabled()Z move-result v0 if-eqz v0, :disabled return-void @@ -62,7 +51,7 @@ val disablePreciseSeekingGesturePatch = bytecodePatch( addInstructionsWithLabels( 0, """ - invoke-static { }, $extensionMethodDescriptor->isGestureDisabled()Z + invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->isGestureDisabled()Z move-result v0 if-eqz v0, :disabled const/4 v0, 0x0 diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt index 60a424e28..fadf2357f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt @@ -15,7 +15,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c import com.android.tools.smali.dexlib2.iface.reference.MethodReference val enableSeekbarTappingPatch = bytecodePatch( - name = "Enable tap to seek", description = "Adds an option to enable tap to seek on the seekbar of the video player.", ) { dependsOn( @@ -24,17 +23,6 @@ val enableSeekbarTappingPatch = bytecodePatch( addResourcesPatch, ) - compatibleWith( - "com.google.android.youtube"( - "19.16.39", - "19.25.37", - "19.34.42", - "19.43.41", - "19.47.53", - "20.07.39", - ), - ) - execute { addResources("youtube", "interaction.seekbar.enableSeekbarTappingPatch") diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt index e7dc185a4..1a19d5b91 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt @@ -18,11 +18,9 @@ import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference -internal const val EXTENSION_METHOD_DESCRIPTOR = - "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;->isSlideToSeekDisabled(Z)Z" +private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;" val enableSlideToSeekPatch = bytecodePatch( - name = "Enable slide to seek", description = "Adds an option to enable slide to seek " + "instead of playing at 2x speed when pressing and holding in the video player." ) { @@ -33,17 +31,6 @@ val enableSlideToSeekPatch = bytecodePatch( versionCheckPatch, ) - compatibleWith( - "com.google.android.youtube"( - "19.16.39", - "19.25.37", - "19.34.42", - "19.43.41", - "19.47.53", - "20.07.39", - ), - ) - execute { addResources("youtube", "interaction.seekbar.enableSlideToSeekPatch") @@ -59,6 +46,8 @@ val enableSlideToSeekPatch = bytecodePatch( val checkReference = slideToSeekFingerprint.method.getInstruction(checkIndex) .getReference()!! + val extensionMethodDescriptor = "$EXTENSION_CLASS_DESCRIPTOR->isSlideToSeekDisabled(Z)Z" + // A/B check method was only called on this class. slideToSeekFingerprint.classDef.methods.forEach { method -> method.findInstructionIndicesReversed { @@ -70,7 +59,7 @@ val enableSlideToSeekPatch = bytecodePatch( addInstructions( index + 2, """ - invoke-static { v$register }, $EXTENSION_METHOD_DESCRIPTOR + invoke-static { v$register }, $extensionMethodDescriptor move-result v$register """, ) @@ -95,7 +84,7 @@ val enableSlideToSeekPatch = bytecodePatch( addInstructions( targetIndex + 1, """ - invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR + invoke-static { v$targetRegister }, $extensionMethodDescriptor move-result v$targetRegister """, ) @@ -109,7 +98,7 @@ val enableSlideToSeekPatch = bytecodePatch( addInstructions( insertIndex, """ - invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR + invoke-static { v$targetRegister }, $extensionMethodDescriptor move-result v$targetRegister """, ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/HideSeekbarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/HideSeekbarPatch.kt new file mode 100644 index 000000000..ddf21dd85 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/HideSeekbarPatch.kt @@ -0,0 +1,46 @@ +package app.revanced.patches.youtube.interaction.seekbar + +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patches.all.misc.resources.addResources +import app.revanced.patches.all.misc.resources.addResourcesPatch +import app.revanced.patches.shared.misc.settings.preference.SwitchPreference +import app.revanced.patches.youtube.layout.seekbar.seekbarColorPatch +import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch +import app.revanced.patches.youtube.misc.settings.PreferenceScreen +import app.revanced.patches.youtube.misc.settings.settingsPatch +import app.revanced.patches.youtube.shared.seekbarFingerprint +import app.revanced.patches.youtube.shared.seekbarOnDrawFingerprint + +val hideSeekbarPatch = bytecodePatch( + description = "Adds an option to hide the seekbar.", +) { + dependsOn( + sharedExtensionPatch, + settingsPatch, + seekbarColorPatch, + addResourcesPatch, + ) + + execute { + addResources("youtube", "layout.hide.seekbar.hideSeekbarPatch") + + PreferenceScreen.SEEKBAR.addPreferences( + SwitchPreference("revanced_hide_seekbar"), + SwitchPreference("revanced_hide_seekbar_thumbnail"), + ) + + seekbarOnDrawFingerprint.match(seekbarFingerprint.originalClassDef).method.addInstructionsWithLabels( + 0, + """ + const/4 v0, 0x0 + invoke-static { }, Lapp/revanced/extension/youtube/patches/HideSeekbarPatch;->hideSeekbar()Z + move-result v0 + if-eqz v0, :hide_seekbar + return-void + :hide_seekbar + nop + """, + ) + } +} diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarPatch.kt new file mode 100644 index 000000000..7c053f5e4 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarPatch.kt @@ -0,0 +1,31 @@ +package app.revanced.patches.youtube.interaction.seekbar + +import app.revanced.patcher.patch.bytecodePatch + +@Suppress("unused") +val seekbarPatch = bytecodePatch( + name = "Seekbar", + description = "Adds options to disable precise seeking when swiping up on the seekbar, " + + "slide to seek instead of playing at 2x speed when pressing and holding, " + + "tapping the player seekbar to seek, " + + "and hiding the video player seekbar." +) { + dependsOn( + disablePreciseSeekingGesturePatch, + enableSlideToSeekPatch, + enableSeekbarTappingPatch, + hideSeekbarPatch, + seekbarThumbnailsPatch + ) + + compatibleWith( + "com.google.android.youtube"( + "19.16.39", + "19.25.37", + "19.34.42", + "19.43.41", + "19.47.53", + "20.07.39", + ) + ) +} diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt index a890d6c11..114f25895 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt @@ -10,6 +10,7 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.layout.seekbar.fullscreenSeekbarThumbnailsFingerprint import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater +import app.revanced.patches.youtube.misc.playservice.is_20_09_or_greater import app.revanced.patches.youtube.misc.playservice.versionCheckPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen @@ -17,7 +18,6 @@ private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/SeekbarThumbnailsPatch;" val seekbarThumbnailsPatch = bytecodePatch( - name = "Seekbar thumbnails", description = "Adds an option to use high quality fullscreen seekbar thumbnails. " + "Patching 19.16.39 adds an option to restore old seekbar thumbnails.", ) { @@ -27,18 +27,13 @@ val seekbarThumbnailsPatch = bytecodePatch( versionCheckPatch, ) - compatibleWith( - "com.google.android.youtube"( - "19.16.39", - "19.25.37", - "19.34.42", - "19.43.41", - "19.47.53", - "20.07.39", - ) - ) - execute { + if (is_20_09_or_greater) { + // High quality seekbar thumbnails is partially broken in 20.09 + // and the code is completely removed in 20.10+ + return@execute + } + addResources("youtube", "layout.seekbar.seekbarThumbnailsPatch") if (is_19_17_or_greater) { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt index 68b516ebb..edf7390ce 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt @@ -1,58 +1,11 @@ package app.revanced.patches.youtube.layout.hide.seekbar -import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.patch.bytecodePatch -import app.revanced.patches.all.misc.resources.addResources -import app.revanced.patches.all.misc.resources.addResourcesPatch -import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.layout.seekbar.seekbarColorPatch -import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch -import app.revanced.patches.youtube.misc.settings.PreferenceScreen -import app.revanced.patches.youtube.misc.settings.settingsPatch -import app.revanced.patches.youtube.shared.seekbarFingerprint -import app.revanced.patches.youtube.shared.seekbarOnDrawFingerprint +import app.revanced.patches.youtube.interaction.seekbar.hideSeekbarPatch -val hideSeekbarPatch = bytecodePatch( - name = "Hide seekbar", - description = "Adds an option to hide the seekbar.", -) { +@Deprecated("Patch was moved to app.revanced.patches.youtube.interaction.seekbar") +val hideSeekbarPatch = bytecodePatch { dependsOn( - sharedExtensionPatch, - settingsPatch, - seekbarColorPatch, - addResourcesPatch, + hideSeekbarPatch ) - - compatibleWith( - "com.google.android.youtube"( - "19.16.39", - "19.25.37", - "19.34.42", - "19.43.41", - "19.47.53", - "20.07.39", - ), - ) - - execute { - addResources("youtube", "layout.hide.seekbar.hideSeekbarPatch") - - PreferenceScreen.SEEKBAR.addPreferences( - SwitchPreference("revanced_hide_seekbar"), - SwitchPreference("revanced_hide_seekbar_thumbnail"), - ) - - seekbarOnDrawFingerprint.match(seekbarFingerprint.originalClassDef).method.addInstructionsWithLabels( - 0, - """ - const/4 v0, 0x0 - invoke-static { }, Lapp/revanced/extension/youtube/patches/HideSeekbarPatch;->hideSeekbar()Z - move-result v0 - if-eqz v0, :hide_seekbar - return-void - :hide_seekbar - nop - """, - ) - } }