From 6c9baf22614b1be4870be684915445f7a138cf31 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 7 Oct 2023 03:50:42 +0200 Subject: [PATCH] feat(YouTube): Add `Disable fine scrubbing gesture` patch --- .../DisableFineScrubbingGesturePatch.kt | 64 +++++++++++++++++++ .../seekbar/EnableSeekbarTappingPatch.kt | 16 ++++- .../EnableSeekbarTappingResourcePatch.kt | 24 ------- .../fingerprints/IsSwipingUpFingerprint.kt | 9 +++ 4 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisableFineScrubbingGesturePatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingResourcePatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/IsSwipingUpFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisableFineScrubbingGesturePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisableFineScrubbingGesturePatch.kt new file mode 100644 index 00000000..8d5d0441 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisableFineScrubbingGesturePatch.kt @@ -0,0 +1,64 @@ +package app.revanced.patches.youtube.interaction.seekbar + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.settings.preference.impl.StringResource +import app.revanced.patches.shared.settings.preference.impl.SwitchPreference +import app.revanced.patches.youtube.interaction.seekbar.fingerprints.IsSwipingUpFingerprint +import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.SettingsPatch +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction + +@Patch( + name = "Disable fine scrubbing gesture", + description = "Disables gesture that shows the fine scrubbing overlay when swiping up on the seekbar.", + dependencies = [IntegrationsPatch::class, SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.32.39", + "18.37.36" + ] + ) + ] +) +@Suppress("unused") +object DisableFineScrubbingGesturePatch : BytecodePatch( + setOf(IsSwipingUpFingerprint) +) { + private const val INTEGRATIONS_METHOD_DESCRIPTOR = + "Lapp/revanced/integrations/patches/DisableFineScrubbingGesturePatch;->" + + "disableGesture(Landroid/view/VelocityTracker;Landroid/view/MotionEvent;)V" + + override fun execute(context: BytecodeContext) { + SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences( + SwitchPreference( + "revanced_disable_fine_scrubbing_gesture", + StringResource("revanced_disable_fine_scrubbing_gesture_title", "Disable fine scrubbing gesture"), + StringResource("revanced_disable_fine_scrubbing_gesture_summary_on", "Gesture is disabled"), + StringResource("revanced_disable_fine_scrubbing_gesture_summary_off", "Gesture is enabled"), + ) + ) + + IsSwipingUpFingerprint.result?.let { + val addMovementIndex = it.scanResult.patternScanResult!!.startIndex - 1 + + it.mutableMethod.apply { + val addMovementInstruction = getInstruction(addMovementIndex) + val trackerRegister = addMovementInstruction.registerC + val eventRegister = addMovementInstruction.registerD + + replaceInstruction( + addMovementIndex, + "invoke-static {v$trackerRegister, v$eventRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR" + ) + } + } ?: throw IsSwipingUpFingerprint.exception + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt index 18529223..ff9c2b07 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt @@ -8,9 +8,12 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.shared.settings.preference.impl.StringResource +import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.interaction.seekbar.fingerprints.OnTouchEventHandlerFingerprint import app.revanced.patches.youtube.interaction.seekbar.fingerprints.SeekbarTappingFingerprint import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.SettingsPatch import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -19,9 +22,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference name = "Seekbar tapping", description = "Enables tap-to-seek on the seekbar of the video player.", dependencies = [ - IntegrationsPatch::class, - EnableSeekbarTappingResourcePatch::class - ], + IntegrationsPatch::class, SettingsPatch::class], compatiblePackages = [ CompatiblePackage( "com.google.android.youtube", @@ -45,6 +46,15 @@ object EnableSeekbarTappingPatch : BytecodePatch( ) ) { override fun execute(context: BytecodeContext) { + SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences( + SwitchPreference( + "revanced_seekbar_tapping", + StringResource("revanced_seekbar_tapping_title", "Enable seekbar tapping"), + StringResource("revanced_seekbar_tapping_summary_on", "Seekbar tapping is enabled"), + StringResource("revanced_seekbar_tapping_summary_off", "Seekbar tapping is disabled") + ) + ) + // Find the required methods to tap the seekbar. val seekbarTappingMethods = OnTouchEventHandlerFingerprint.result?.let { val patternScanResult = it.scanResult.patternScanResult!! diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingResourcePatch.kt deleted file mode 100644 index a39bc0e8..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingResourcePatch.kt +++ /dev/null @@ -1,24 +0,0 @@ -package app.revanced.patches.youtube.interaction.seekbar - -import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.patch.ResourcePatch -import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.shared.settings.preference.impl.StringResource -import app.revanced.patches.shared.settings.preference.impl.SwitchPreference -import app.revanced.patches.youtube.misc.settings.SettingsPatch - -@Patch( - dependencies = [SettingsPatch::class] -) -object EnableSeekbarTappingResourcePatch : ResourcePatch() { - override fun execute(context: ResourceContext) { - SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences( - SwitchPreference( - "revanced_seekbar_tapping", - StringResource("revanced_seekbar_tapping_title", "Enable seekbar tapping"), - StringResource("revanced_seekbar_tapping_summary_on", "Seekbar tapping is enabled"), - StringResource("revanced_seekbar_tapping_summary_off", "Seekbar tapping is disabled") - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/IsSwipingUpFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/IsSwipingUpFingerprint.kt new file mode 100644 index 00000000..3a35684a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/IsSwipingUpFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.youtube.interaction.seekbar.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.Opcode + +object IsSwipingUpFingerprint : MethodFingerprint( + parameters = listOf("Landroid/view/MotionEvent;", "J"), + opcodes = listOf(Opcode.SGET_OBJECT) +) \ No newline at end of file