From 2d6142bce89dee7e919ed03084dae906f714916c Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:11:39 +0900 Subject: [PATCH] feat(Hide ads): remove `Close fullscreen ads` setting https://github.com/inotia00/ReVanced_Extended/issues/2017#issuecomment-2351327068 --- .../patches/music/ads/general/AdsPatch.kt | 12 +--- .../patches/shared/ads/BaseAdsPatch.kt | 72 +++++++------------ .../youtube/ads/general/AdsBytecodePatch.kt | 2 +- .../patches/youtube/ads/general/AdsPatch.kt | 4 -- .../music/settings/host/values/strings.xml | 5 -- .../youtube/settings/host/values/strings.xml | 7 -- .../youtube/settings/xml/revanced_prefs.xml | 1 - 7 files changed, 28 insertions(+), 75 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/music/ads/general/AdsPatch.kt b/src/main/kotlin/app/revanced/patches/music/ads/general/AdsPatch.kt index 841f0527a3..d490534a5e 100644 --- a/src/main/kotlin/app/revanced/patches/music/ads/general/AdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/ads/general/AdsPatch.kt @@ -61,9 +61,6 @@ object AdsPatch : BaseBytecodePatch( 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;" - private const val PREMIUM_PROMOTION_POP_UP_CLASS_DESCRIPTOR = "$ADS_PATH/PremiumPromotionPatch;" @@ -82,7 +79,7 @@ object AdsPatch : BaseBytecodePatch( // litho view, used in 'ShowDialogCommandOuterClass' in innertube ShowDialogCommandFingerprint .resultOrThrow() - .hookLithoFullscreenAds(context) + .hookLithoFullscreenAds() // endregion @@ -174,19 +171,12 @@ object AdsPatch : BaseBytecodePatch( // endregion LithoFilterPatch.addFilter(ADS_FILTER_CLASS_DESCRIPTOR) - LithoFilterPatch.addFilter(FULLSCREEN_ADS_FILTER_CLASS_DESCRIPTOR) SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_fullscreen_ads", "true" ) - SettingsPatch.addSwitchPreference( - CategoryType.ADS, - "revanced_hide_fullscreen_ads_type", - "true", - "revanced_hide_fullscreen_ads" - ) SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_general_ads", diff --git a/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt b/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt index 590371d12c..c99fa68fa6 100644 --- a/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt @@ -12,14 +12,12 @@ import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.ads.fingerprints.MusicAdsFingerprint import app.revanced.patches.shared.ads.fingerprints.VideoAdsFingerprint import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH -import app.revanced.util.getTargetIndexOrThrow -import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow +import app.revanced.util.getReference import app.revanced.util.getWalkerMethod import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference @@ -82,7 +80,7 @@ abstract class BaseAdsPatch( } } - internal fun MethodFingerprintResult.hookLithoFullscreenAds(context: BytecodeContext) { + internal fun MethodFingerprintResult.hookLithoFullscreenAds() { mutableMethod.apply { val dialogCodeIndex = scanResult.patternScanResult!!.endIndex val dialogCodeField = @@ -90,52 +88,34 @@ abstract class BaseAdsPatch( if (dialogCodeField.type != "I") throw PatchException("Invalid dialogCodeField: $dialogCodeField") - // Disable fullscreen ads - addInstructionsWithLabels( - 0, + var prependInstructions = """ + move-object/from16 v0, p1 + move-object/from16 v1, p2 """ - move-object/from16 v0, p2 - - # In the latest version of YouTube and YouTube Music, it is used after being cast - - check-cast v0, ${dialogCodeField.definingClass} - iget v0, v0, $dialogCodeField - invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->disableFullscreenAds(I)Z - move-result v0 - if-eqz v0, :show - return-void - """, ExternalLabel("show", getInstruction(0)) - ) - // Close fullscreen ads + if (parameterTypes.firstOrNull() != "[B") { + val toByteArrayReference = getInstruction( + indexOfFirstInstructionOrThrow { + getReference()?.name == "toByteArray" + } + ).reference - // Find the instruction whose name is "show" in [MethodReference] and click the 'AlertDialog.BUTTON_POSITIVE' button. - // In this case, an instruction for 'getButton' must be added to smali, not in integrations - // (This custom dialog cannot be cast to [AlertDialog] or [Dialog]) - val dialogIndex = getTargetIndexWithMethodReferenceNameOrThrow("show") - val dialogReference = getInstruction(dialogIndex).reference - val dialogDefiningClass = (dialogReference as MethodReference).definingClass - val getButtonMethod = context.findClass(dialogDefiningClass)!! - .mutableClass.methods.first { method -> - method.parameters == listOf("I") - && method.returnType == "Landroid/widget/Button;" - } - val getButtonCall = - dialogDefiningClass + "->" + getButtonMethod.name + "(I)Landroid/widget/Button;" - val dialogRegister = getInstruction(dialogIndex).registerC - val freeIndex = getTargetIndexOrThrow(dialogIndex, Opcode.IF_EQZ) - val freeRegister = getInstruction(freeIndex).registerA - - addInstructions( - dialogIndex + 1, """ - # Get the 'AlertDialog.BUTTON_POSITIVE' from custom dialog - # Since this custom dialog cannot be cast to AlertDialog or Dialog, - # It should come from smali, not integrations. - const/4 v$freeRegister, -0x1 - invoke-virtual {v$dialogRegister, v$freeRegister}, $getButtonCall - move-result-object v$freeRegister - invoke-static {v$freeRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->setCloseButton(Landroid/widget/Button;)V + prependInstructions += """ + invoke-virtual {v0}, $toByteArrayReference + move-result-object v0 """ + } + + // Disable fullscreen ads + addInstructionsWithLabels( + 0, prependInstructions + """ + check-cast v1, ${dialogCodeField.definingClass} + iget v1, v1, $dialogCodeField + invoke-static {v0, v1}, $INTEGRATIONS_CLASS_DESCRIPTOR->disableFullscreenAds([BI)Z + move-result v1 + if-eqz v1, :show + return-void + """, ExternalLabel("show", getInstruction(0)) ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsBytecodePatch.kt index c6470cfcf7..9a9868502c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsBytecodePatch.kt @@ -43,7 +43,7 @@ object AdsBytecodePatch : BytecodePatch( // litho view, used in 'ShowDialogCommandOuterClass' in innertube ShowDialogCommandFingerprint .resultOrThrow() - .hookLithoFullscreenAds(context) + .hookLithoFullscreenAds() // endregion diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsPatch.kt index 3e7c435ee2..613c33dde4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/general/AdsPatch.kt @@ -50,12 +50,8 @@ object AdsPatch : BaseResourcePatch( 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(ADS_FILTER_CLASS_DESCRIPTOR) - LithoFilterPatch.addFilter(FULLSCREEN_ADS_FILTER_CLASS_DESCRIPTOR) context.forEach { diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 51e591a927..9cd52c3ae1 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -58,11 +58,6 @@ Please download %2$s from the website." Hide fullscreen ads Hides fullscreen ads. - Close fullscreen ads - "If it is enabled, fullscreen ads are closed through the Close button. -If it is disabled, fullscreen ads are blocked. (there may be side effects)" - Fullscreen ads have been blocked. (DialogType: %s) - Fullscreen ads have been closed. Hide general ads Hides general ads. Hide media ads diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index a3f41b233c..3046453dd2 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -29,13 +29,6 @@ Please download %2$s from the website." Hide fullscreen ads Fullscreen ads are hidden. Fullscreen ads are shown. - Close fullscreen ads - Fullscreen ads are closed through the Close button. - "Fullscreen ads are blocked. - -Side effect: Community post images may be blocked in fullscreen." - Fullscreen ads have been blocked. (DialogType: %s) - Fullscreen ads have been closed. Hide general ads General ads are hidden. General ads are shown. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index f627560bc7..543ebbcf26 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -5,7 +5,6 @@