mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-22 19:09:12 +02:00
feat(YouTube Music/Hide general ads): add Hide fullscreen ads
settings
This commit is contained in:
parent
b25413cb3b
commit
d8aec4abd2
@ -2,12 +2,16 @@ package app.revanced.patches.music.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.CompatiblePackage
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.music.ads.general.fingerprints.FloatingLayoutFingerprint
|
||||
import app.revanced.patches.music.ads.general.fingerprints.InterstitialsContainerFingerprint
|
||||
import app.revanced.patches.music.ads.general.fingerprints.NotifierShelfFingerprint
|
||||
import app.revanced.patches.music.ads.general.fingerprints.ShowDialogCommandFingerprint
|
||||
import app.revanced.patches.music.ads.music.MusicAdsPatch
|
||||
import app.revanced.patches.music.navigation.component.NavigationBarComponentPatch
|
||||
import app.revanced.patches.music.utils.integrations.Constants.ADS_PATH
|
||||
@ -16,6 +20,7 @@ import app.revanced.patches.music.utils.litho.LithoFilterPatch
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ButtonContainer
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.FloatingLayout
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.InterstitialsContainer
|
||||
import app.revanced.patches.music.utils.settings.CategoryType
|
||||
import app.revanced.patches.music.utils.settings.SettingsPatch
|
||||
import app.revanced.util.exception
|
||||
@ -54,15 +59,98 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
object GeneralAdsPatch : BytecodePatch(
|
||||
setOf(
|
||||
FloatingLayoutFingerprint,
|
||||
NotifierShelfFingerprint
|
||||
InterstitialsContainerFingerprint,
|
||||
NotifierShelfFingerprint,
|
||||
ShowDialogCommandFingerprint
|
||||
)
|
||||
) {
|
||||
private const val FILTER_CLASS_DESCRIPTOR =
|
||||
"$COMPONENTS_PATH/AdsFilter;"
|
||||
|
||||
private const val FULLSCREEN_ADS_CLASS_DESCRIPTOR =
|
||||
"$ADS_PATH/FullscreenAdsPatch;"
|
||||
|
||||
private const val PREMIUM_PROMOTION_POP_UP_CLASS_DESCRIPTOR =
|
||||
"$ADS_PATH/PremiumPromotionPatch;"
|
||||
|
||||
private const val PREMIUM_PROMOTION_BANNER_CLASS_DESCRIPTOR =
|
||||
"$ADS_PATH/PremiumRenewalPatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
|
||||
|
||||
/**
|
||||
* Hides fullscreen ads
|
||||
* Non-litho view, used in some old clients.
|
||||
*/
|
||||
InterstitialsContainerFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val targetIndex = getWideLiteralInstructionIndex(InterstitialsContainer) + 2
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"invoke-static {v$targetRegister}, $FULLSCREEN_ADS_CLASS_DESCRIPTOR->hideFullscreenAds(Landroid/view/View;)V"
|
||||
)
|
||||
}
|
||||
} ?: throw InterstitialsContainerFingerprint.exception
|
||||
|
||||
/**
|
||||
* Hides fullscreen ads
|
||||
* Litho view, used in 'ShowDialogCommandOuterClass' in innertube
|
||||
*/
|
||||
ShowDialogCommandFingerprint.result?.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.
|
||||
//
|
||||
// If an issue occurs due to patching due to server-side changes in the future,
|
||||
// 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])
|
||||
//
|
||||
// See the comments below.
|
||||
addInstructionsWithLabels(
|
||||
0,
|
||||
"""
|
||||
invoke-static {}, $FULLSCREEN_ADS_CLASS_DESCRIPTOR->hideFullscreenAds()Z
|
||||
move-result v0
|
||||
if-eqz v0, :show
|
||||
return-void
|
||||
""", ExternalLabel("show", getInstruction(0))
|
||||
)
|
||||
|
||||
/*
|
||||
val dialogIndex = getTargetIndexWithMethodReferenceName("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 = getTargetIndex(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, $freeRegister}, $getButtonCall
|
||||
move-result-object $freeRegister
|
||||
invoke-static {$freeRegister}, $FULLSCREEN_ADS_CLASS_DESCRIPTOR->confirmDialog(Landroid/widget/Button;)V
|
||||
"""
|
||||
)
|
||||
*/
|
||||
}
|
||||
} ?: throw ShowDialogCommandFingerprint.exception
|
||||
|
||||
/**
|
||||
* Hides premium promotion popup
|
||||
*/
|
||||
@ -73,7 +161,7 @@ object GeneralAdsPatch : BytecodePatch(
|
||||
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"invoke-static {v$targetRegister}, $ADS_PATH/PremiumPromotionPatch;->hidePremiumPromotion(Landroid/view/View;)V"
|
||||
"invoke-static {v$targetRegister}, $PREMIUM_PROMOTION_POP_UP_CLASS_DESCRIPTOR->hidePremiumPromotion(Landroid/view/View;)V"
|
||||
)
|
||||
}
|
||||
} ?: throw FloatingLayoutFingerprint.exception
|
||||
@ -89,11 +177,16 @@ object GeneralAdsPatch : BytecodePatch(
|
||||
|
||||
addInstruction(
|
||||
linearLayoutIndex + 1,
|
||||
"invoke-static {v$linearLayoutRegister}, $ADS_PATH/PremiumRenewalPatch;->hidePremiumRenewal(Landroid/widget/LinearLayout;)V"
|
||||
"invoke-static {v$linearLayoutRegister}, $PREMIUM_PROMOTION_BANNER_CLASS_DESCRIPTOR->hidePremiumRenewal(Landroid/widget/LinearLayout;)V"
|
||||
)
|
||||
}
|
||||
} ?: throw NotifierShelfFingerprint.exception
|
||||
|
||||
SettingsPatch.addMusicPreference(
|
||||
CategoryType.ADS,
|
||||
"revanced_hide_fullscreen_ads",
|
||||
"true"
|
||||
)
|
||||
SettingsPatch.addMusicPreference(
|
||||
CategoryType.ADS,
|
||||
"revanced_hide_general_ads",
|
||||
|
@ -0,0 +1,10 @@
|
||||
package app.revanced.patches.music.ads.general.fingerprints
|
||||
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.InterstitialsContainer
|
||||
import app.revanced.util.fingerprint.LiteralValueFingerprint
|
||||
|
||||
object InterstitialsContainerFingerprint : LiteralValueFingerprint(
|
||||
returnType = "V",
|
||||
strings= listOf("overlay_controller_param"),
|
||||
literalSupplier = { InterstitialsContainer }
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
package app.revanced.patches.music.ads.general.fingerprints
|
||||
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.SlidingDialogAnimation
|
||||
import app.revanced.util.fingerprint.LiteralValueFingerprint
|
||||
|
||||
object ShowDialogCommandFingerprint : LiteralValueFingerprint(
|
||||
returnType = "V",
|
||||
literalSupplier = { SlidingDialogAnimation }
|
||||
)
|
@ -26,6 +26,7 @@ object SharedResourceIdPatch : ResourcePatch() {
|
||||
var FloatingLayout: Long = -1
|
||||
var HistoryMenuItem: Long = -1
|
||||
var InlineTimeBarAdBreakMarkerColor: Long = -1
|
||||
var InterstitialsContainer: Long = -1
|
||||
var IsTablet: Long = -1
|
||||
var LikeDislikeContainer: Long = -1
|
||||
var MenuEntry: Long = -1
|
||||
@ -41,6 +42,7 @@ object SharedResourceIdPatch : ResourcePatch() {
|
||||
var PrivacyTosFooter: Long = -1
|
||||
var QualityAuto: Long = -1
|
||||
var RemixGenericButtonSize: Long = -1
|
||||
var SlidingDialogAnimation: Long = -1
|
||||
var Text1: Long = -1
|
||||
var ToolTipContentView: Long = -1
|
||||
var TopEnd: Long = -1
|
||||
@ -66,6 +68,7 @@ object SharedResourceIdPatch : ResourcePatch() {
|
||||
FloatingLayout = find(ID, "floating_layout")
|
||||
HistoryMenuItem = find(ID, "history_menu_item")
|
||||
InlineTimeBarAdBreakMarkerColor = find(COLOR, "inline_time_bar_ad_break_marker_color")
|
||||
InterstitialsContainer = find(ID, "interstitials_container")
|
||||
IsTablet = find(BOOL, "is_tablet")
|
||||
LikeDislikeContainer = find(ID, "like_dislike_container")
|
||||
MenuEntry = find(LAYOUT, "menu_entry")
|
||||
@ -81,6 +84,7 @@ object SharedResourceIdPatch : ResourcePatch() {
|
||||
PrivacyTosFooter = find(ID, "privacy_tos_footer")
|
||||
QualityAuto = find(STRING, "quality_auto")
|
||||
RemixGenericButtonSize = find(DIMEN, "remix_generic_button_size")
|
||||
SlidingDialogAnimation = find(STYLE, "SlidingDialogAnimation")
|
||||
Text1 = find(ID, "text1")
|
||||
ToolTipContentView = find(LAYOUT, "tooltip_content_view")
|
||||
TopEnd = find(ID, "TOP_END")
|
||||
|
@ -154,6 +154,8 @@ Some features may not work properly in the old player layout."</string>
|
||||
<string name="revanced_hide_flyout_panel_stats_for_nerds_title">Hide stats for nerds menu</string>
|
||||
<string name="revanced_hide_flyout_panel_subscribe_title">Hide subscribe / unsubscribe menu</string>
|
||||
<string name="revanced_hide_flyout_panel_view_song_credit_title">Hide view song credit menu</string>
|
||||
<string name="revanced_hide_fullscreen_ads_summary">Hides fullscreen ads.</string>
|
||||
<string name="revanced_hide_fullscreen_ads_title">Hide fullscreen ads</string>
|
||||
<string name="revanced_hide_fullscreen_share_button_summary">Hides the share button in the fullscreen player.</string>
|
||||
<string name="revanced_hide_fullscreen_share_button_title">Hide fullscreen share button</string>
|
||||
<string name="revanced_hide_general_ads_summary">Hides general ads.</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user