From 3e8c748f48c306ab8cfd836b686e68dfe12148f7 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 28 Mar 2025 19:47:08 +0900 Subject: [PATCH] feat(YouTube): Add support version `20.03.45` https://github.com/inotia00/ReVanced_Extended/issues/2717#issuecomment-2760796211 --- .../general/toolbar/ToolBarComponentsPatch.kt | 65 +++++++++++++------ .../components/PlayerComponentsPatch.kt | 6 +- .../youtube/utils/compatibility/Constants.kt | 3 +- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarComponentsPatch.kt index e701162e8..49753224d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarComponentsPatch.kt @@ -38,6 +38,7 @@ import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.fingerprint.mutableClassOrThrow import app.revanced.util.getReference import app.revanced.util.getWalkerMethod +import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstLiteralInstructionOrThrow import app.revanced.util.replaceLiteralInstructionCall @@ -268,30 +269,54 @@ val toolBarComponentsPatch = bytecodePatch( createSearchSuggestionsFingerprint.methodOrThrow().apply { val iteratorIndex = indexOfIteratorInstruction(this) - val replaceIndex = indexOfFirstInstructionOrThrow(iteratorIndex) { + val replaceIndex = indexOfFirstInstruction(iteratorIndex) { opcode == Opcode.IGET_OBJECT && getReference()?.type == "Landroid/widget/ImageView;" } - val uriIndex = indexOfFirstInstructionOrThrow(replaceIndex) { - opcode == Opcode.INVOKE_STATIC && - getReference()?.toString() == "Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;" - } - val jumpIndex = indexOfFirstInstructionOrThrow(uriIndex, Opcode.CONST_4) - val replaceIndexInstruction = getInstruction(replaceIndex) - val freeRegister = replaceIndexInstruction.registerA - val classRegister = replaceIndexInstruction.registerB - val replaceIndexReference = - getInstruction(replaceIndex).reference + if (replaceIndex > -1) { + val uriIndex = indexOfFirstInstructionOrThrow(replaceIndex) { + opcode == Opcode.INVOKE_STATIC && + getReference()?.toString() == "Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;" + } + val jumpIndex = indexOfFirstInstructionOrThrow(uriIndex, Opcode.CONST_4) + val replaceIndexInstruction = getInstruction(replaceIndex) + val freeRegister = replaceIndexInstruction.registerA + val classRegister = replaceIndexInstruction.registerB + val replaceIndexReference = + getInstruction(replaceIndex).reference - addInstructionsWithLabels( - replaceIndex + 1, """ - invoke-static { }, $GENERAL_CLASS_DESCRIPTOR->hideSearchTermThumbnail()Z - move-result v$freeRegister - if-nez v$freeRegister, :hidden - iget-object v$freeRegister, v$classRegister, $replaceIndexReference - """, ExternalLabel("hidden", getInstruction(jumpIndex)) - ) - removeInstruction(replaceIndex) + addInstructionsWithLabels( + replaceIndex + 1, """ + invoke-static { }, $GENERAL_CLASS_DESCRIPTOR->hideSearchTermThumbnail()Z + move-result v$freeRegister + if-nez v$freeRegister, :hidden + iget-object v$freeRegister, v$classRegister, $replaceIndexReference + """, ExternalLabel("hidden", getInstruction(jumpIndex)) + ) + removeInstruction(replaceIndex) + } else { // only for YT 20.03 + val insertIndex = indexOfFirstInstructionOrThrow(iteratorIndex) { + opcode == Opcode.INVOKE_VIRTUAL && + getReference()?.toString() == "Landroid/widget/ImageView;->setVisibility(I)V" + } - 1 + if (getInstruction(insertIndex).opcode != Opcode.CONST_4) { + throw PatchException("Failed to find insert index") + } + val freeRegister = getInstruction(insertIndex).registerA + val uriIndex = indexOfFirstInstructionOrThrow(insertIndex) { + opcode == Opcode.INVOKE_STATIC && + getReference()?.toString() == "Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;" + } + val jumpIndex = indexOfFirstInstructionOrThrow(uriIndex, Opcode.CONST_4) + + addInstructionsWithLabels( + insertIndex, """ + invoke-static { }, $GENERAL_CLASS_DESCRIPTOR->hideSearchTermThumbnail()Z + move-result v$freeRegister + if-nez v$freeRegister, :hidden + """, ExternalLabel("hidden", getInstruction(jumpIndex)) + ) + } } if (is_19_16_or_greater) { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt index c3c3b5b21..c6be90e33 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/player/components/PlayerComponentsPatch.kt @@ -634,8 +634,8 @@ val playerComponentsPatch = bytecodePatch( fingerprint.methodOrThrow(filmStripOverlayEnterParentFingerprint).hookFilmstripOverlay() } - // Removed in YouTube 20.05+ - if (!is_20_05_or_greater) { + // Removed in YouTube 20.03+ + if (!is_20_03_or_greater) { youtubeControlsOverlayFingerprint.methodOrThrow().apply { val constIndex = indexOfFirstLiteralInstructionOrThrow(fadeDurationFast) val constRegister = getInstruction(constIndex).registerA @@ -663,7 +663,7 @@ val playerComponentsPatch = bytecodePatch( ) removeInstruction(insertIndex) } - } else { + } else if (is_20_05_or_greater) { // This is a new film strip overlay added to YouTube 20.05+ // Disabling this flag is not related to the operation of the patch. filmStripOverlayConfigV2Fingerprint.injectLiteralInstructionBooleanCall( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/compatibility/Constants.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/compatibility/Constants.kt index f08e8b1d2..671f24067 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/compatibility/Constants.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/compatibility/Constants.kt @@ -13,7 +13,8 @@ internal object Constants { "19.16.39", // This is the last version where the 'Restore old seekbar thumbnails' setting works. "19.43.41", // This is the latest version where edge-to-edge display is not enforced on Android 15+. "19.44.39", // This is the only version that has experimental shortcut icons. - "19.47.53", // This is the latest version supported by the RVX patch. + "19.47.53", // This was the latest version supported by the previous RVX patch. + "20.03.45", // This is the latest version supported by the RVX patch. ) ) } \ No newline at end of file