feat(Hide ads): add Close fullscreen ads settings https://github.com/inotia00/ReVanced_Extended/issues/2017

This commit is contained in:
inotia00
2024-06-11 03:01:50 +09:00
parent 4aa18cce25
commit c003ad99bc
10 changed files with 163 additions and 103 deletions

View File

@ -1,12 +1,13 @@
package app.revanced.patches.youtube.ads.general
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.ads.general.MusicAdsPatch.hookLithoFullscreenAds
import app.revanced.patches.youtube.ads.general.VideoAdsPatch.hookNonLithoFullscreenAds
import app.revanced.patches.youtube.ads.general.fingerprints.CompactYpcOfferModuleViewFingerprint
import app.revanced.patches.youtube.ads.general.fingerprints.InterstitialsContainerFingerprint
import app.revanced.patches.youtube.ads.general.fingerprints.ShowDialogCommandFingerprint
@ -15,11 +16,9 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AdAttribution
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.InterstitialsContainer
import app.revanced.util.findMutableMethodOf
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.injectHideViewCall
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction31i
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
@ -37,34 +36,14 @@ object AdsBytecodePatch : BytecodePatch(
// region patch for hide fullscreen ads
// non-litho view, used in some old clients.
InterstitialsContainerFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(InterstitialsContainer) + 2
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $ADS_CLASS_DESCRIPTOR->hideFullscreenAds(Landroid/view/View;)V"
)
}
}
InterstitialsContainerFingerprint
.resultOrThrow()
.hookNonLithoFullscreenAds(InterstitialsContainer)
// litho view, used in 'ShowDialogCommandOuterClass' in innertube
ShowDialogCommandFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
// In this method, custom dialog is created and shown.
// There were no issues despite adding “return-void” to the first index.
addInstructionsWithLabels(
0,
"""
invoke-static/range {p2 .. p2}, $ADS_CLASS_DESCRIPTOR->hideFullscreenAds(Ljava/lang/Object;)Z
move-result v0
if-eqz v0, :show
return-void
""", ExternalLabel("show", getInstruction(0))
)
}
}
ShowDialogCommandFingerprint
.resultOrThrow()
.hookLithoFullscreenAds(context)
// endregion

View File

@ -47,11 +47,15 @@ object AdsPatch : BaseResourcePatch(
"Top"
)
private const val FILTER_CLASS_DESCRIPTOR =
private const val ADS_FILTER_CLASS_DESCRIPTOR =
"$COMPONENTS_PATH/AdsFilter;"
private const val FULLSCREEN_ADS_FILTER_CLASS_DESCRIPTOR =
"${app.revanced.patches.shared.integrations.Constants.COMPONENTS_PATH}/FullscreenAdsFilter;"
override fun execute(context: ResourceContext) {
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
LithoFilterPatch.addFilter(ADS_FILTER_CLASS_DESCRIPTOR)
LithoFilterPatch.addFilter(FULLSCREEN_ADS_FILTER_CLASS_DESCRIPTOR)
context.forEach {

View File

@ -1,9 +1,28 @@
package app.revanced.patches.youtube.ads.general.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SlidingDialogAnimation
import app.revanced.util.fingerprint.LiteralValueFingerprint
import app.revanced.util.containsWideLiteralInstructionIndex
import com.android.tools.smali.dexlib2.Opcode
internal object ShowDialogCommandFingerprint : LiteralValueFingerprint(
internal object ShowDialogCommandFingerprint : MethodFingerprint(
returnType = "V",
literalSupplier = { SlidingDialogAnimation }
opcodes = listOf(
Opcode.IF_EQ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET, // get dialog code
),
// 18.43 and earlier has a different first parameter.
// Since this fingerprint is somewhat weak, work around by checking for both method parameter signatures.
customFingerprint = custom@{ methodDef, _ ->
if (!methodDef.containsWideLiteralInstructionIndex(SlidingDialogAnimation)) {
return@custom false
}
// 18.43 and earlier parameters are: "L", "L"
// 18.44+ parameters are "[B", "L"
val parameterTypes = methodDef.parameterTypes
parameterTypes.size == 2 && parameterTypes[1].startsWith("L")
},
)