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 75b51b341..d8afdde5f 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 @@ -12,12 +12,14 @@ import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater import app.revanced.patches.youtube.misc.playservice.versionCheckPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch +import app.revanced.util.findInstructionIndicesReversed import app.revanced.util.getReference 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_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;" +internal const val EXTENSION_METHOD_DESCRIPTOR = + "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;->isSlideToSeekDisabled(Z)Z" @Suppress("unused") val enableSlideToSeekPatch = bytecodePatch( @@ -59,51 +61,35 @@ val enableSlideToSeekPatch = bytecodePatch( var modifiedMethods = false // Restore the behaviour to slide to seek. - val checkIndex = - slideToSeekMatch.patternMatch!!.startIndex - val checkReference = - slideToSeekMatch.mutableMethod.getInstruction(checkIndex).getReference()!! + val checkIndex = slideToSeekMatch.patternMatch!!.startIndex + val checkReference = slideToSeekMatch.mutableMethod.getInstruction(checkIndex) + .getReference()!! // A/B check method was only called on this class. slideToSeekMatch.mutableClass.methods.forEach { method -> - method.implementation!!.instructions.forEachIndexed { index, instruction -> - if (instruction.opcode == Opcode.INVOKE_VIRTUAL && - instruction.getReference() == checkReference - ) { - method.apply { - val targetRegister = getInstruction(index + 1).registerA + method.findInstructionIndicesReversed { + opcode == Opcode.INVOKE_VIRTUAL && getReference() == checkReference + }.forEach { index -> + method.apply { + val register = getInstruction(index + 1).registerA - addInstructions( - index + 2, - """ - invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR - move-result v$targetRegister - """, - ) - } - - modifiedMethods = true + addInstructions( + index + 2, + """ + invoke-static { v$register }, $EXTENSION_METHOD_DESCRIPTOR + move-result v$register + """ + ) } + + modifiedMethods = true } } if (!modifiedMethods) throw PatchException("Could not find methods to modify") // Disable the double speed seek gesture. - if (!is_19_17_or_greater) { - disableFastForwardLegacyMatch.mutableMethod.apply { - val insertIndex = disableFastForwardLegacyMatch.patternMatch!!.endIndex + 1 - val targetRegister = getInstruction(insertIndex).registerA - - addInstructions( - insertIndex, - """ - invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR - move-result v$targetRegister - """, - ) - } - } else { + if (is_19_17_or_greater) { arrayOf( disableFastForwardGestureMatch, disableFastForwardNoticeMatch, @@ -115,12 +101,27 @@ val enableSlideToSeekPatch = bytecodePatch( addInstructions( targetIndex + 1, """ - invoke-static { v$targetRegister }, $EXTENSION_CLASS_DESCRIPTOR + invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR move-result v$targetRegister """, ) } } + } else { + disableFastForwardLegacyMatch.let { + it.mutableMethod.apply { + val insertIndex = it.patternMatch!!.endIndex + 1 + val targetRegister = getInstruction(insertIndex).registerA + + addInstructions( + insertIndex, + """ + invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR + move-result v$targetRegister + """ + ) + } + } } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt index c3fe10c2d..132c6f6f4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt @@ -63,7 +63,10 @@ internal val disableFastForwardNoticeFingerprint = fingerprint { Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT, ) - strings("Failed to easy seek haptics vibrate") + strings("search_landing_cache_key", "batterymanager") + custom { method, _ -> + method.name == "run" + } } internal val onTouchEventHandlerFingerprint = fingerprint(fuzzyPatternScanThreshold = 3) { @@ -107,7 +110,7 @@ internal val seekbarTappingFingerprint = fingerprint { internal val slideToSeekFingerprint = fingerprint { accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL) - returns("Z") + returns("V") parameters("Landroid/view/View;", "F") opcodes( Opcode.INVOKE_VIRTUAL,