Skip to content

Commit

Permalink
feat(YouTube): Add Disable fine scrubbing gesture patch
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 7, 2023
1 parent c1a943d commit 6c9baf2
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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<FiveRegisterInstruction>(addMovementIndex)
val trackerRegister = addMovementInstruction.registerC
val eventRegister = addMovementInstruction.registerD

replaceInstruction(
addMovementIndex,
"invoke-static {v$trackerRegister, v$eventRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR"
)
}
} ?: throw IsSwipingUpFingerprint.exception
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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!!
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
)

0 comments on commit 6c9baf2

Please sign in to comment.