refactor(hide-shorts-component): add Hide shorts player paid promotion settings

This commit is contained in:
inotia00 2023-04-08 06:41:23 +09:00
parent ff43393daa
commit c802034640
7 changed files with 90 additions and 1 deletions

View File

@ -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
}
)

View File

@ -29,6 +29,7 @@ import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus
SharedResourceIdPatch::class,
ShortsCommentButtonPatch::class,
ShortsInfoPanelPatch::class,
ShortsPaidContentBannerPatch::class,
ShortsRemixButtonPatch::class,
ShortsSubscriptionsButtonPatch::class
]

View File

@ -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
"""
)
}
}
}

View File

@ -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")

View File

@ -441,6 +441,7 @@ Please do not report any issues you encounter while using this feature."</string
<string name="revanced_hide_shorts_player_join_button_summary_off">Shorts player join button is shown</string>
<string name="revanced_hide_shorts_player_join_button_summary_on">Shorts player join button is hidden</string>
<string name="revanced_hide_shorts_player_join_button_title">Hide shorts player join button</string>
<string name="revanced_hide_shorts_player_paid_content_title">Hide shorts player paid promotion</string>
<string name="revanced_hide_shorts_player_remix_button_summary_off">Shorts player remix button is shown</string>
<string name="revanced_hide_shorts_player_remix_button_summary_on">Shorts player remix button is hidden</string>
<string name="revanced_hide_shorts_player_remix_button_title">Hide shorts player remix button</string>

View File

@ -10,6 +10,8 @@
<string name="revanced_extended_settings_title">ReVanced Extended</string>
<string name="revanced_hide_shorts_player_info_panel_summary_off">@string/revanced_hide_info_panel_summary_off</string>
<string name="revanced_hide_shorts_player_info_panel_summary_on">@string/revanced_hide_info_panel_summary_on</string>
<string name="revanced_hide_shorts_player_paid_content_summary_off">@string/revanced_adremover_paid_content_summary_off</string>
<string name="revanced_hide_shorts_player_paid_content_summary_on">@string/revanced_adremover_paid_content_summary_on</string>
<string name="revanced_whitelisting_speed_button">@string/camera_speed_button_label</string>
<string name="revanced_icons_blue">afn / blue</string>

View File

@ -71,7 +71,9 @@
<SwitchPreference android:title="@string/revanced_hide_shorts_player_remix_button_title" android:key="revanced_hide_shorts_player_remix_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_remix_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_remix_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_player_thanks_button_title" android:key="revanced_hide_shorts_player_thanks_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_thanks_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_thanks_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_player_subscriptions_button_title" android:key="revanced_hide_shorts_player_subscriptions_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_subscriptions_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_subscriptions_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_player_join_button_title" android:key="revanced_hide_shorts_player_join_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_join_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_join_button_summary_off" />SETTINGS: HIDE_SHORTS_COMPONENTS -->
<SwitchPreference android:title="@string/revanced_hide_shorts_player_join_button_title" android:key="revanced_hide_shorts_player_join_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_join_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_join_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_player_info_panel_title" android:key="revanced_hide_shorts_player_info_panel" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_info_panel_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_info_panel_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_player_paid_content_title" android:key="revanced_hide_shorts_player_paid_content" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_player_paid_content_summary_on" android:summaryOff="@string/revanced_hide_shorts_player_paid_content_summary_off" />SETTINGS: HIDE_SHORTS_COMPONENTS -->
<!-- SETTINGS: SHORTS_COMPONENT.PARENT
</PreferenceScreen>SETTINGS: SHORTS_COMPONENT.PARENT -->