From c802034640dfe59cc58073aee287b54ed244be8c Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sat, 8 Apr 2023 06:41:23 +0900 Subject: [PATCH] refactor(hide-shorts-component): add `Hide shorts player paid promotion` settings --- .../ShortsPaidContentFingerprint.kt | 15 +++++ .../patch/ShortsComponentPatch.kt | 1 + .../patch/ShortsPaidContentBannerPatch.kt | 64 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 4 ++ .../youtube/settings/host/values/strings.xml | 1 + .../youtube/settings/values-v21/strings.xml | 2 + .../youtube/settings/xml/revanced_prefs.xml | 4 +- 7 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsPaidContentBannerPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt new file mode 100644 index 000000000..1e339b989 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/fingerprints/ShortsPaidContentFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.youtube.layout.general.shortscomponent.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 ShortsPaidContentFingerprint : MethodFingerprint( + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerBadgeLabelId + } == true + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsComponentPatch.kt index c55834747..d1c8ef7ed 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsComponentPatch.kt @@ -29,6 +29,7 @@ import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus SharedResourceIdPatch::class, ShortsCommentButtonPatch::class, ShortsInfoPanelPatch::class, + ShortsPaidContentBannerPatch::class, ShortsRemixButtonPatch::class, ShortsSubscriptionsButtonPatch::class ] diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsPaidContentBannerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsPaidContentBannerPatch.kt new file mode 100644 index 000000000..d1ec1b71c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortscomponent/patch/ShortsPaidContentBannerPatch.kt @@ -0,0 +1,64 @@ +package app.revanced.patches.youtube.layout.general.shortscomponent.patch + +import app.revanced.extensions.toErrorResult +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.addInstructions +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.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.layout.general.shortscomponent.fingerprints.ShortsPaidContentFingerprint +import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.util.integrations.Constants +import app.revanced.util.integrations.Constants.GENERAL +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +@Name("hide-shorts-paid-content") +@DependsOn([SharedResourceIdPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class ShortsPaidContentBannerPatch : BytecodePatch( + listOf(ShortsPaidContentFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + ShortsPaidContentFingerprint.result?.mutableMethod?.let { method -> + with (method.implementation!!.instructions) { + val primaryIndex = this.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerBadgeLabelId + } + 3 + + val secondaryIndex = this.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerBadge2LabelId + } + 3 + + if (primaryIndex > secondaryIndex) { + method.insertHook(primaryIndex) + method.insertHook(secondaryIndex) + } else { + method.insertHook(secondaryIndex) + method.insertHook(primaryIndex) + } + } + } ?: return ShortsPaidContentFingerprint.toErrorResult() + + return PatchResultSuccess() + } + private companion object { + fun MutableMethod.insertHook(insertIndex: Int) { + val insertRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA + addInstructions( + insertIndex + 1, """ + invoke-static {v$insertRegister}, $GENERAL->hideShortsPlayerPaidContent(Landroid/view/ViewStub;)Landroid/view/ViewStub; + move-result-object v$insertRegister + """ + ) + } + } +} 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 b379a270a..191e519a9 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 @@ -39,6 +39,8 @@ class SharedResourceIdPatch : ResourcePatch { var layoutIcon: Long = -1 var layoutVideo: Long = -1 var liveChatButtonId: Long = -1 + var reelPlayerBadgeLabelId: Long = -1 + var reelPlayerBadge2LabelId: Long = -1 var reelPlayerFooterLabelId: Long = -1 var reelPlayerInfoPanelLabelId: Long = -1 var reelPlayerPausedLabelId: Long = -1 @@ -78,6 +80,8 @@ class SharedResourceIdPatch : ResourcePatch { layoutIcon = find(LAYOUT, "endscreen_element_layout_icon") layoutVideo = find(LAYOUT, "endscreen_element_layout_video") liveChatButtonId = find(ID, "live_chat_overlay_button") + reelPlayerBadgeLabelId = find(ID, "reel_player_badge") + reelPlayerBadge2LabelId = find(ID, "reel_player_badge2") reelPlayerFooterLabelId = find(LAYOUT, "reel_player_dyn_footer_vert_stories3") reelPlayerInfoPanelLabelId = find(ID, "reel_player_info_panel") reelPlayerPausedLabelId = find(ID, "reel_player_paused_state_buttons") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index de80ad956..f8f6ec11e 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -441,6 +441,7 @@ Please do not report any issues you encounter while using this feature."Shorts player join button is shown Shorts player join button is hidden Hide shorts player join button + Hide shorts player paid promotion Shorts player remix button is shown Shorts player remix button is hidden Hide shorts player remix button diff --git a/src/main/resources/youtube/settings/values-v21/strings.xml b/src/main/resources/youtube/settings/values-v21/strings.xml index bce056845..3972d37ac 100644 --- a/src/main/resources/youtube/settings/values-v21/strings.xml +++ b/src/main/resources/youtube/settings/values-v21/strings.xml @@ -10,6 +10,8 @@ ReVanced Extended @string/revanced_hide_info_panel_summary_off @string/revanced_hide_info_panel_summary_on + @string/revanced_adremover_paid_content_summary_off + @string/revanced_adremover_paid_content_summary_on @string/camera_speed_button_label afn / blue diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index cd02194fc..23d076d9e 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -71,7 +71,9 @@ - SETTINGS: HIDE_SHORTS_COMPONENTS --> + + + SETTINGS: HIDE_SHORTS_COMPONENTS -->