mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-04 16:44:29 +02:00
feat(Hide ads): remove Close fullscreen ads
setting https://github.com/inotia00/ReVanced_Extended/issues/2017#issuecomment-2351327068
This commit is contained in:
parent
bd6690cd2b
commit
2d6142bce8
@ -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",
|
||||
|
@ -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")
|
||||
|
||||
var prependInstructions = """
|
||||
move-object/from16 v0, p1
|
||||
move-object/from16 v1, p2
|
||||
"""
|
||||
|
||||
if (parameterTypes.firstOrNull() != "[B") {
|
||||
val toByteArrayReference = getInstruction<ReferenceInstruction>(
|
||||
indexOfFirstInstructionOrThrow {
|
||||
getReference<MethodReference>()?.name == "toByteArray"
|
||||
}
|
||||
).reference
|
||||
|
||||
prependInstructions += """
|
||||
invoke-virtual {v0}, $toByteArrayReference
|
||||
move-result-object v0
|
||||
"""
|
||||
}
|
||||
|
||||
// Disable fullscreen ads
|
||||
addInstructionsWithLabels(
|
||||
0,
|
||||
"""
|
||||
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
|
||||
|
||||
// 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<ReferenceInstruction>(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<FiveRegisterInstruction>(dialogIndex).registerC
|
||||
val freeIndex = getTargetIndexOrThrow(dialogIndex, Opcode.IF_EQZ)
|
||||
val freeRegister = getInstruction<OneRegisterInstruction>(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
|
||||
"""
|
||||
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))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ object AdsBytecodePatch : BytecodePatch(
|
||||
// litho view, used in 'ShowDialogCommandOuterClass' in innertube
|
||||
ShowDialogCommandFingerprint
|
||||
.resultOrThrow()
|
||||
.hookLithoFullscreenAds(context)
|
||||
.hookLithoFullscreenAds()
|
||||
|
||||
// endregion
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -58,11 +58,6 @@ Please download %2$s from the website."</string>
|
||||
|
||||
<string name="revanced_hide_fullscreen_ads_title">Hide fullscreen ads</string>
|
||||
<string name="revanced_hide_fullscreen_ads_summary">Hides fullscreen ads.</string>
|
||||
<string name="revanced_hide_fullscreen_ads_type_title">Close fullscreen ads</string>
|
||||
<string name="revanced_hide_fullscreen_ads_type_summary">"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)"</string>
|
||||
<string name="revanced_hide_fullscreen_ads_blocked_success">Fullscreen ads have been blocked. (DialogType: %s)</string>
|
||||
<string name="revanced_hide_fullscreen_ads_closed_success">Fullscreen ads have been closed.</string>
|
||||
<string name="revanced_hide_general_ads_title">Hide general ads</string>
|
||||
<string name="revanced_hide_general_ads_summary">Hides general ads.</string>
|
||||
<string name="revanced_hide_music_ads_title">Hide media ads</string>
|
||||
|
@ -29,13 +29,6 @@ Please download %2$s from the website."</string>
|
||||
<string name="revanced_hide_fullscreen_ads_title">Hide fullscreen ads</string>
|
||||
<string name="revanced_hide_fullscreen_ads_summary_on">Fullscreen ads are hidden.</string>
|
||||
<string name="revanced_hide_fullscreen_ads_summary_off">Fullscreen ads are shown.</string>
|
||||
<string name="revanced_hide_fullscreen_ads_type_title">Close fullscreen ads</string>
|
||||
<string name="revanced_hide_fullscreen_ads_type_summary_on">Fullscreen ads are closed through the Close button.</string>
|
||||
<string name="revanced_hide_fullscreen_ads_type_summary_off">"Fullscreen ads are blocked.
|
||||
|
||||
Side effect: Community post images may be blocked in fullscreen."</string>
|
||||
<string name="revanced_hide_fullscreen_ads_blocked_success">Fullscreen ads have been blocked. (DialogType: %s)</string>
|
||||
<string name="revanced_hide_fullscreen_ads_closed_success">Fullscreen ads have been closed.</string>
|
||||
<string name="revanced_hide_general_ads_title">Hide general ads</string>
|
||||
<string name="revanced_hide_general_ads_summary_on">General ads are hidden.</string>
|
||||
<string name="revanced_hide_general_ads_summary_off">General ads are shown.</string>
|
||||
|
@ -5,7 +5,6 @@
|
||||
<!-- PREFERENCE_SCREEN: ADS
|
||||
<PreferenceScreen android:title="@string/revanced_preference_screen_ads_title" android:key="revanced_preference_screen_ads">
|
||||
<SwitchPreference android:title="@string/revanced_hide_fullscreen_ads_title" android:key="revanced_hide_fullscreen_ads" android:summaryOn="@string/revanced_hide_fullscreen_ads_summary_on" android:summaryOff="@string/revanced_hide_fullscreen_ads_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_hide_fullscreen_ads_type_title" android:key="revanced_hide_fullscreen_ads_type" android:summaryOn="@string/revanced_hide_fullscreen_ads_type_summary_on" android:summaryOff="@string/revanced_hide_fullscreen_ads_type_summary_off" android:dependency="revanced_hide_fullscreen_ads" />
|
||||
<SwitchPreference android:title="@string/revanced_hide_general_ads_title" android:key="revanced_hide_general_ads" android:summaryOn="@string/revanced_hide_general_ads_summary_on" android:summaryOff="@string/revanced_hide_general_ads_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_hide_merchandise_shelf_title" android:key="revanced_hide_merchandise_shelf" android:summaryOn="@string/revanced_hide_merchandise_shelf_summary_on" android:summaryOff="@string/revanced_hide_merchandise_shelf_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_hide_paid_promotion_label_title" android:key="revanced_hide_paid_promotion_label" android:summaryOn="@string/revanced_hide_paid_promotion_label_summary_on" android:summaryOff="@string/revanced_hide_paid_promotion_label_summary_off" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user