From 359e6e4dae113769c54abcb9c87c3e492549c4f6 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sat, 1 Apr 2023 17:51:54 +0900 Subject: [PATCH] add `hide-channel-avatar-section` patch --- .../ChannelListSubMenuFingerprint.kt | 21 ++++++ .../patch/ChannelListSubMenuPatch.kt | 66 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 2 + .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 4 ++ 5 files changed, 96 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt new file mode 100644 index 000000000..cddb86e2d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/fingerprints/ChannelListSubMenuFingerprint.kt @@ -0,0 +1,21 @@ +package app.revanced.patches.youtube.layout.general.channellistsubmenu.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +object ChannelListSubMenuFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.CONST, + Opcode.CONST_4, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.channelListSubMenuLabelId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt new file mode 100644 index 000000000..b889f4209 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/channellistsubmenu/patch/ChannelListSubMenuPatch.kt @@ -0,0 +1,66 @@ +package app.revanced.patches.youtube.layout.general.channellistsubmenu.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.instruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.layout.general.channellistsubmenu.fingerprints.ChannelListSubMenuFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.GENERAL_LAYOUT +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("hide-channel-avatar-section") +@Description("Hides the channel avatar section of the subscription feed.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class ChannelListSubMenuPatch : BytecodePatch( + listOf( + ChannelListSubMenuFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + ChannelListSubMenuFingerprint.result?.let { + with (it.mutableMethod) { + val endIndex = it.scanResult.patternScanResult!!.endIndex + val register = (instruction(endIndex) as OneRegisterInstruction).registerA + + addInstruction( + endIndex + 1, + "invoke-static {v$register}, $GENERAL_LAYOUT->hideChannelListSubMenu(Landroid/view/View;)V" + ) + } + } ?: return ChannelListSubMenuFingerprint.toErrorResult() + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: GENERAL_LAYOUT_SETTINGS", + "SETTINGS: HIDE_CHANNEL_LIST_SUBMENU" + ) + ) + + SettingsPatch.updatePatchStatus("hide-channel-avatar-section") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index 8e5f5d54d..513bcce3c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -22,6 +22,7 @@ class SharedResourceIdPatch : ResourcePatch { var backgroundCategoryLabelId: Long = -1 var barContainerHeightLabelId: Long = -1 var bottomUiContainerResourceId: Long = -1 + var channelListSubMenuLabelId: Long = -1 var chapterRepeatOnResourceId: Long = -1 var compactLinkLabelId: Long = -1 var controlsLayoutStubResourceId: Long = -1 @@ -56,6 +57,7 @@ class SharedResourceIdPatch : ResourcePatch { backgroundCategoryLabelId = findSharedResourceId("string", "pref_background_and_offline_category") barContainerHeightLabelId = findSharedResourceId("dimen", "bar_container_height") bottomUiContainerResourceId = findSharedResourceId("id", "bottom_ui_container_stub") + channelListSubMenuLabelId = findSharedResourceId("layout", "channel_list_sub_menu") chapterRepeatOnResourceId = findSharedResourceId("string", "chapter_repeat_on") compactLinkLabelId = findSharedResourceId("layout", "compact_link") controlsLayoutStubResourceId = findSharedResourceId("id", "controls_layout_stub") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 767ca8af8..006e43757 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -326,6 +326,9 @@ Please do not report any issues you encounter while using this feature."Hide category bar in search results Category bar is shown Category bar is hidden + Channel avatar section of the subscriptions feed is shown + Channel avatar section of the subscriptions feed is hidden + Hide channel avatar section Channel watermark is shown Channel watermark is hidden Hide channel watermark diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index c752e7b15..07dca3559 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -121,6 +121,9 @@ SETTINGS: HIDE_CATEGORY_BAR --> + +