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