From bccd6dc5df7deebd6765283f3fc270437e3dbcf3 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 31 Mar 2025 21:09:11 +0900 Subject: [PATCH] fix(YouTube - Swipe controls): Patch fails on YouTube 19.43.41 when `Player components` patch is included --- .../youtube/swipe/controls/Fingerprints.kt | 21 ++++++++++++------- .../swipe/controls/SwipeControlsPatch.kt | 16 +++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) 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 838a52ecf..eecf2a6cf 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 @@ -10,6 +10,7 @@ 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.Method import com.android.tools.smali.dexlib2.iface.reference.MethodReference internal val fullScreenEngagementOverlayFingerprint = legacyFingerprint( @@ -113,11 +114,17 @@ internal val playerGestureConfigSyntheticFingerprint = legacyFingerprint( // 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 + indexOfPlayerConfigModelBooleanInstruction(method) >= 0 }, -) \ No newline at end of file +) + +internal fun indexOfPlayerConfigModelBooleanInstruction( + method: Method, + startIndex: Int = 0 +) = method.indexOfFirstInstruction(startIndex) { + val reference = getReference() + opcode == Opcode.INVOKE_VIRTUAL && + reference?.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" && + reference.parameterTypes.isEmpty() && + reference.returnType == "Z" +} \ 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 3b82fb404..ea22e133b 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 @@ -30,7 +30,6 @@ 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 @@ -212,14 +211,17 @@ val swipeControlsPatch = bytecodePatch( // 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 + playerGestureConfigSyntheticFingerprint.methodOrThrow().apply { + val disableSwipeToExitFullscreenModeIndex = + indexOfPlayerConfigModelBooleanInstruction(this) + val disableSwipeToEnterFullscreenModeInThePlayerIndex = + indexOfPlayerConfigModelBooleanInstruction(this, disableSwipeToExitFullscreenModeIndex + 1) mapOf( - 3 to "disableSwipeToEnterFullscreenModeInThePlayer", - 9 to "disableSwipeToExitFullscreenMode" - ).forEach { (offSet, methodName) -> - it.getWalkerMethod(endIndex - offSet).apply { + disableSwipeToExitFullscreenModeIndex to "disableSwipeToExitFullscreenMode", + disableSwipeToEnterFullscreenModeInThePlayerIndex to "disableSwipeToEnterFullscreenModeInThePlayer" + ).forEach { (walkerIndex, methodName) -> + getWalkerMethod(walkerIndex).apply { val index = implementation!!.instructions.lastIndex val register = getInstruction(index).registerA