Skip to content

Commit

Permalink
fix(YouTube/Hide feed components): Hide Latest videos button settin…
Browse files Browse the repository at this point in the history
…g does not support tablets (inotia00#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 <[email protected]>
  • Loading branch information
YT-Advanced and inotia00 authored Oct 3, 2024
1 parent ffcc9e5 commit c932956
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,7 +57,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(
ChipCloudFingerprint,
ContentPillInFingerprint,
ContentPillFingerprint,
FloatingButtonParentFingerprint,
HistoryMenuItemFingerprint,
HistoryMenuItemOfflineTabFingerprint,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,15 +38,21 @@ 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
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
Expand Down Expand Up @@ -78,6 +85,7 @@ object FeedComponentsPatch : BaseBytecodePatch(
ChannelListSubMenuTabletFingerprint,
ChannelListSubMenuTabletSyntheticFingerprint,
ChannelTabRendererFingerprint,
ContentPillFingerprint,
ElementParserParentFingerprint,
EngagementPanelBuilderFingerprint,
FilterBarHeightFingerprint,
Expand Down Expand Up @@ -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<OneRegisterInstruction>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
)
Original file line number Diff line number Diff line change
@@ -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 },
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit c932956

Please sign in to comment.