From c932956808c5d3c6cde126ba65a7c6f7935652f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20Gia=20B=E1=BA=A3o?= <70064328+YT-Advanced@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:42:44 +0700 Subject: [PATCH] fix(YouTube/Hide feed components): `Hide Latest videos button` setting does not support tablets (#89) * fix(YouTube - Hide Latest Video button): Patch should handle `Tap to update` button * Update fingerprint * Add layout resources * Update patches * feat: instead of checking the opcode pattern, use the `injectLiteralInstructionViewCall` function --------- Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com> --- .../components/LayoutComponentsPatch.kt | 6 +-- ...ngerprint.kt => ContentPillFingerprint.kt} | 2 +- .../feed/components/FeedComponentsPatch.kt | 54 +++++++++++++------ .../fingerprints/BreakingNewsFingerprint.kt | 7 --- .../ChannelListSubMenuFingerprint.kt | 7 --- .../fingerprints/ContentPillFingerprint.kt | 13 +++++ .../LatestVideosButtonFingerprint.kt | 7 --- .../utils/resourceid/SharedResourceIdPatch.kt | 2 + 8 files changed, 56 insertions(+), 42 deletions(-) rename src/main/kotlin/app/revanced/patches/music/general/components/fingerprints/{ContentPillInFingerprint.kt => ContentPillFingerprint.kt} (76%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ContentPillFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt index f43d509f2..6a9b3724c 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/components/LayoutComponentsPatch.kt @@ -9,7 +9,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.PatchException import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.music.general.components.fingerprints.ChipCloudFingerprint -import app.revanced.patches.music.general.components.fingerprints.ContentPillInFingerprint +import app.revanced.patches.music.general.components.fingerprints.ContentPillFingerprint import app.revanced.patches.music.general.components.fingerprints.FloatingButtonFingerprint import app.revanced.patches.music.general.components.fingerprints.FloatingButtonParentFingerprint import app.revanced.patches.music.general.components.fingerprints.HistoryMenuItemFingerprint @@ -57,7 +57,7 @@ object LayoutComponentsPatch : BaseBytecodePatch( compatiblePackages = COMPATIBLE_PACKAGE, fingerprints = setOf( ChipCloudFingerprint, - ContentPillInFingerprint, + ContentPillFingerprint, FloatingButtonParentFingerprint, HistoryMenuItemFingerprint, HistoryMenuItemOfflineTabFingerprint, @@ -208,7 +208,7 @@ object LayoutComponentsPatch : BaseBytecodePatch( // region patch for hide tap to update button - ContentPillInFingerprint.resultOrThrow().let { + ContentPillFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, diff --git a/src/main/kotlin/app/revanced/patches/music/general/components/fingerprints/ContentPillInFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/general/components/fingerprints/ContentPillFingerprint.kt similarity index 76% rename from src/main/kotlin/app/revanced/patches/music/general/components/fingerprints/ContentPillInFingerprint.kt rename to src/main/kotlin/app/revanced/patches/music/general/components/fingerprints/ContentPillFingerprint.kt index 6fed0ad94..cfb292686 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/components/fingerprints/ContentPillInFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/components/fingerprints/ContentPillFingerprint.kt @@ -2,7 +2,7 @@ package app.revanced.patches.music.general.components.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint -internal object ContentPillInFingerprint : MethodFingerprint( +internal object ContentPillFingerprint : MethodFingerprint( returnType = "V", strings = listOf("Content pill VE is null") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt index 1ed6fc011..742a38879 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt @@ -18,6 +18,7 @@ import app.revanced.patches.youtube.feed.components.fingerprints.ChannelListSubM import app.revanced.patches.youtube.feed.components.fingerprints.ChannelListSubMenuTabletSyntheticFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ChannelTabBuilderFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ChannelTabRendererFingerprint +import app.revanced.patches.youtube.feed.components.fingerprints.ContentPillFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ElementParserFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ElementParserParentFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.EngagementPanelUpdateFingerprint @@ -37,8 +38,13 @@ import app.revanced.patches.youtube.utils.integrations.Constants.FEED_PATH import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Bar import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CaptionToggleContainer +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ChannelListSubMenu +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ContentPill +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.HorizontalCardList import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT import app.revanced.util.alsoResolve import app.revanced.util.getReference import app.revanced.util.getWalkerMethod @@ -46,6 +52,7 @@ import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionReversedOrThrow import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow +import app.revanced.util.injectLiteralInstructionViewCall import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode @@ -78,6 +85,7 @@ object FeedComponentsPatch : BaseBytecodePatch( ChannelListSubMenuTabletFingerprint, ChannelListSubMenuTabletSyntheticFingerprint, ChannelTabRendererFingerprint, + ContentPillFingerprint, ElementParserParentFingerprint, EngagementPanelBuilderFingerprint, FilterBarHeightFingerprint, @@ -106,23 +114,35 @@ object FeedComponentsPatch : BaseBytecodePatch( // region patch for hide carousel shelf, subscriptions channel section, latest videos button - mapOf( - BreakingNewsFingerprint to "hideBreakingNewsShelf", // carousel shelf, only used to tablet layout. - ChannelListSubMenuFingerprint to "hideSubscriptionsChannelSection", // subscriptions channel section - LatestVideosButtonFingerprint to "hideLatestVideosButton", // latest videos button - ).forEach { (fingerprint, methodName) -> - fingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val targetIndex = it.scanResult.patternScanResult!!.endIndex - val targetRegister = - getInstruction(targetIndex).registerA - - addInstruction( - targetIndex + 1, - "invoke-static {v$targetRegister}, $FEED_CLASS_DESCRIPTOR->$methodName(Landroid/view/View;)V" - ) - } - } + listOf( + // carousel shelf, only used to tablet layout. + Triple( + BreakingNewsFingerprint, + "hideBreakingNewsShelf", + HorizontalCardList + ), + // subscriptions channel section. + Triple( + ChannelListSubMenuFingerprint, + "hideSubscriptionsChannelSection", + ChannelListSubMenu + ), + // latest videos button + Triple( + ContentPillFingerprint, + "hideLatestVideosButton", + ContentPill + ), + Triple( + LatestVideosButtonFingerprint, + "hideLatestVideosButton", + Bar + ), + ).forEach { (fingerprint, methodName, literal) -> + val smaliInstruction = """ + invoke-static {v$REGISTER_TEMPLATE_REPLACEMENT}, $FEED_CLASS_DESCRIPTOR->$methodName(Landroid/view/View;)V + """ + fingerprint.injectLiteralInstructionViewCall(literal, smaliInstruction) } // endregion diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/BreakingNewsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/BreakingNewsFingerprint.kt index 2f64e057c..4ff593594 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/BreakingNewsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/BreakingNewsFingerprint.kt @@ -4,15 +4,8 @@ import app.revanced.patcher.extensions.or import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.HorizontalCardList import app.revanced.util.fingerprint.LiteralValueFingerprint import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode internal object BreakingNewsFingerprint : LiteralValueFingerprint( accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - opcodes = listOf( - Opcode.CONST, - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT - ), literalSupplier = { HorizontalCardList }, ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelListSubMenuFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelListSubMenuFingerprint.kt index 30da50be5..26979d9c0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelListSubMenuFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ChannelListSubMenuFingerprint.kt @@ -2,14 +2,7 @@ package app.revanced.patches.youtube.feed.components.fingerprints import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ChannelListSubMenu import app.revanced.util.fingerprint.LiteralValueFingerprint -import com.android.tools.smali.dexlib2.Opcode internal object ChannelListSubMenuFingerprint : LiteralValueFingerprint( - opcodes = listOf( - Opcode.CONST, - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT - ), literalSupplier = { ChannelListSubMenu }, ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ContentPillFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ContentPillFingerprint.kt new file mode 100644 index 000000000..0b2a092e7 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/ContentPillFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.feed.components.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ContentPill +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ContentPillFingerprint : LiteralValueFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "Z"), + literalSupplier = { ContentPill }, +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/LatestVideosButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/LatestVideosButtonFingerprint.kt index 8ae3e97c4..93ec87b80 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/LatestVideosButtonFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/fingerprints/LatestVideosButtonFingerprint.kt @@ -4,17 +4,10 @@ import app.revanced.patcher.extensions.or import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Bar import app.revanced.util.fingerprint.LiteralValueFingerprint import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode internal object LatestVideosButtonFingerprint : LiteralValueFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L", "Z"), - opcodes = listOf( - Opcode.CONST, - Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT - ), literalSupplier = { Bar }, ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index a8c77ce03..0320937b2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -42,6 +42,7 @@ object SharedResourceIdPatch : ResourcePatch() { var CompactLink = -1L var CompactListItem = -1L var ComponentLongClickListener = -1L + var ContentPill = -1L var ControlsLayoutStub = -1L var DarkBackground = -1L var DarkSplashAnimation = -1L @@ -150,6 +151,7 @@ object SharedResourceIdPatch : ResourcePatch() { CompactLink = getId(LAYOUT, "compact_link") CompactListItem = getId(LAYOUT, "compact_list_item") ComponentLongClickListener = getId(ID, "component_long_click_listener") + ContentPill = getId(LAYOUT, "content_pill") ControlsLayoutStub = getId(ID, "controls_layout_stub") DarkBackground = getId(ID, "dark_background") DarkSplashAnimation = getId(ID, "dark_splash_animation")