mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-08 02:24:35 +02:00
feat(YouTube Music): add Hide general ads
patch
This commit is contained in:
parent
4f21f4c586
commit
1b57096357
@ -0,0 +1,87 @@
|
||||
package app.revanced.patches.music.ads.general
|
||||
|
||||
import app.revanced.extensions.exception
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
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.patches.music.ads.general.fingerprints.FloatingLayoutFingerprint
|
||||
import app.revanced.patches.music.ads.general.fingerprints.NotifierShelfFingerprint
|
||||
import app.revanced.patches.music.ads.music.MusicAdsPatch
|
||||
import app.revanced.patches.music.utils.litho.LithoFilterPatch
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.FloatingLayout
|
||||
import app.revanced.patches.music.utils.settings.SettingsPatch
|
||||
import app.revanced.util.bytecode.getWideLiteralIndex
|
||||
import app.revanced.util.enum.CategoryType
|
||||
import app.revanced.util.integrations.Constants.MUSIC_ADS_PATH
|
||||
import app.revanced.util.integrations.Constants.MUSIC_COMPONENTS_PATH
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
|
||||
@Patch(
|
||||
name = "Hide general ads",
|
||||
description = "Hides general ads.",
|
||||
dependencies = [
|
||||
LithoFilterPatch::class,
|
||||
MusicAdsPatch::class,
|
||||
SettingsPatch::class,
|
||||
SharedResourceIdPatch::class
|
||||
],
|
||||
compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")]
|
||||
)
|
||||
@Suppress("unused")
|
||||
object GeneralAdsPatch : BytecodePatch(
|
||||
setOf(
|
||||
FloatingLayoutFingerprint,
|
||||
NotifierShelfFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
|
||||
|
||||
/**
|
||||
* Hides premium promotion popup
|
||||
*/
|
||||
FloatingLayoutFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val targetIndex = getWideLiteralIndex(FloatingLayout) + 2
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"invoke-static {v$targetRegister}, $MUSIC_ADS_PATH/PremiumPromotionPatch;->hidePremiumPromotion(Landroid/view/View;)V"
|
||||
)
|
||||
}
|
||||
} ?: throw FloatingLayoutFingerprint.exception
|
||||
|
||||
/**
|
||||
* Hides premium renewal banner
|
||||
*/
|
||||
NotifierShelfFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val linearLayoutIndex = it.scanResult.patternScanResult!!.startIndex
|
||||
val linearLayoutRegister = getInstruction<FiveRegisterInstruction>(linearLayoutIndex).registerC
|
||||
|
||||
val textViewIndex = linearLayoutIndex + 2
|
||||
val textViewRegister = getInstruction<OneRegisterInstruction>(textViewIndex).registerA
|
||||
|
||||
addInstruction(
|
||||
textViewIndex,
|
||||
"invoke-static {v$linearLayoutRegister, v$textViewRegister}, $MUSIC_ADS_PATH/PremiumRenewalPatch;->hidePremiumRenewal(Landroid/widget/LinearLayout;Landroid/view/View;)V"
|
||||
)
|
||||
}
|
||||
} ?: throw NotifierShelfFingerprint.exception
|
||||
|
||||
SettingsPatch.addMusicPreference(CategoryType.ADS, "revanced_close_interstitial_ads", "true")
|
||||
SettingsPatch.addMusicPreference(CategoryType.ADS, "revanced_hide_general_ads", "true")
|
||||
SettingsPatch.addMusicPreference(CategoryType.ADS, "revanced_hide_music_ads", "true")
|
||||
SettingsPatch.addMusicPreference(CategoryType.ADS, "revanced_hide_premium_promotion", "true")
|
||||
SettingsPatch.addMusicPreference(CategoryType.ADS, "revanced_hide_premium_renewal", "true")
|
||||
}
|
||||
|
||||
private const val FILTER_CLASS_DESCRIPTOR =
|
||||
"$MUSIC_COMPONENTS_PATH/AdsFilter;"
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package app.revanced.patches.music.ads.general.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.FloatingLayout
|
||||
import app.revanced.util.bytecode.isWideLiteralExists
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
object FloatingLayoutFingerprint : MethodFingerprint(
|
||||
returnType = "Landroid/view/View;",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = emptyList(),
|
||||
customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(FloatingLayout) }
|
||||
)
|
@ -0,0 +1,20 @@
|
||||
package app.revanced.patches.music.ads.general.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicNotifierShelf
|
||||
import app.revanced.util.bytecode.isWideLiteralExists
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
object NotifierShelfFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.IPUT_OBJECT
|
||||
),
|
||||
customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(MusicNotifierShelf) }
|
||||
)
|
@ -1,37 +1,8 @@
|
||||
package app.revanced.patches.music.ads.music
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patches.music.utils.litho.LithoFilterPatch
|
||||
import app.revanced.patches.music.utils.settings.SettingsPatch
|
||||
import app.revanced.patches.shared.patch.ads.AbstractAdsPatch
|
||||
import app.revanced.util.enum.CategoryType
|
||||
import app.revanced.util.integrations.Constants.MUSIC_ADS_PATH
|
||||
import app.revanced.util.integrations.Constants.MUSIC_COMPONENTS_PATH
|
||||
|
||||
@Patch(
|
||||
name = "Hide music ads",
|
||||
description = "Hides ads before playing a music.",
|
||||
dependencies = [
|
||||
LithoFilterPatch::class,
|
||||
SettingsPatch::class
|
||||
],
|
||||
compatiblePackages = [CompatiblePackage("com.google.android.apps.youtube.music")]
|
||||
)
|
||||
@Suppress("unused")
|
||||
object MusicAdsPatch : AbstractAdsPatch(
|
||||
"$MUSIC_ADS_PATH/MusicAdsPatch;->hideMusicAds()Z"
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
super.execute(context)
|
||||
|
||||
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
|
||||
|
||||
SettingsPatch.addMusicPreference(CategoryType.ADS, "revanced_close_interstitial_ads", "false")
|
||||
SettingsPatch.addMusicPreference(CategoryType.ADS, "revanced_hide_music_ads", "true")
|
||||
}
|
||||
|
||||
private const val FILTER_CLASS_DESCRIPTOR =
|
||||
"$MUSIC_COMPONENTS_PATH/AdsFilter;"
|
||||
}
|
||||
)
|
||||
|
@ -15,25 +15,27 @@ import app.revanced.util.enum.ResourceType.STYLE
|
||||
|
||||
@Patch(dependencies = [ResourceMappingPatch::class])
|
||||
object SharedResourceIdPatch : ResourcePatch() {
|
||||
internal var AccountSwitcherAccessibility = -1L
|
||||
internal var ActionsContainer = -1L
|
||||
internal var ButtonIconPaddingMedium = -1L
|
||||
internal var ChipCloud = -1L
|
||||
internal var ColorGrey = -1L
|
||||
internal var DialogSolid = -1L
|
||||
internal var HistoryMenuItem = -1L
|
||||
internal var InlineTimeBarAdBreakMarkerColor = -1L
|
||||
internal var IsTablet = -1L
|
||||
internal var MenuEntry = -1L
|
||||
internal var MusicMenuLikeButtons = -1L
|
||||
internal var NamesInactiveAccountThumbnailSize = -1L
|
||||
internal var PlayerCastMediaRouteButton = -1L
|
||||
internal var PlayerOverlayChip = -1L
|
||||
internal var PrivacyTosFooter = -1L
|
||||
internal var QualityAuto = -1L
|
||||
internal var Text1 = -1L
|
||||
internal var ToolTipContentView = -1L
|
||||
internal var TosFooter = -1L
|
||||
var AccountSwitcherAccessibility: Long = -1
|
||||
var ActionsContainer: Long = -1
|
||||
var ButtonIconPaddingMedium: Long = -1
|
||||
var ChipCloud: Long = -1
|
||||
var ColorGrey: Long = -1
|
||||
var DialogSolid: Long = -1
|
||||
var FloatingLayout: Long = -1
|
||||
var HistoryMenuItem: Long = -1
|
||||
var InlineTimeBarAdBreakMarkerColor: Long = -1
|
||||
var IsTablet: Long = -1
|
||||
var MenuEntry: Long = -1
|
||||
var MusicMenuLikeButtons: Long = -1
|
||||
var MusicNotifierShelf: Long = -1
|
||||
var NamesInactiveAccountThumbnailSize: Long = -1
|
||||
var PlayerCastMediaRouteButton: Long = -1
|
||||
var PlayerOverlayChip: Long = -1
|
||||
var PrivacyTosFooter: Long = -1
|
||||
var QualityAuto: Long = -1
|
||||
var Text1: Long = -1
|
||||
var ToolTipContentView: Long = -1
|
||||
var TosFooter: Long = -1
|
||||
|
||||
override fun execute(context: ResourceContext) {
|
||||
|
||||
@ -48,11 +50,13 @@ object SharedResourceIdPatch : ResourcePatch() {
|
||||
ChipCloud = find(LAYOUT, "chip_cloud")
|
||||
ColorGrey = find(COLOR, "ytm_color_grey_12")
|
||||
DialogSolid = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
|
||||
FloatingLayout = find(ID, "floating_layout")
|
||||
HistoryMenuItem = find(ID, "history_menu_item")
|
||||
InlineTimeBarAdBreakMarkerColor = find(COLOR, "inline_time_bar_ad_break_marker_color")
|
||||
IsTablet = find(BOOL, "is_tablet")
|
||||
MenuEntry = find(LAYOUT, "menu_entry")
|
||||
MusicMenuLikeButtons = find(LAYOUT, "music_menu_like_buttons")
|
||||
MusicNotifierShelf = find(LAYOUT, "music_notifier_shelf")
|
||||
NamesInactiveAccountThumbnailSize = find(DIMEN, "names_inactive_account_thumbnail_size")
|
||||
PlayerCastMediaRouteButton = find(LAYOUT, "player_cast_media_route_button")
|
||||
PlayerOverlayChip = find(ID, "player_overlay_chip")
|
||||
|
@ -15,6 +15,9 @@
|
||||
<string name="revanced_category_navigation">Navigation</string>
|
||||
<string name="revanced_category_player">Player</string>
|
||||
<string name="revanced_category_video">Video</string>
|
||||
<string name="revanced_close_interstitial_ads_summary">Automatically close interstitial ads.</string>
|
||||
<string name="revanced_close_interstitial_ads_title">Close interstitial ads</string>
|
||||
<string name="revanced_close_interstitial_ads_toast">Closing interstitial ads.</string>
|
||||
<string name="revanced_custom_filter_strings_summary">Filter component names by line-seperated.</string>
|
||||
<string name="revanced_custom_filter_strings_title">Edit custom filter</string>
|
||||
<string name="revanced_custom_filter_strings_warning">Invalid custom filter, resetting to default.</string>
|
||||
@ -124,6 +127,8 @@ WARNING: Do not enable new player backgrounds while this is enabled."</string>
|
||||
<string name="revanced_hide_flyout_panel_share_title">Hide share menu</string>
|
||||
<string name="revanced_hide_flyout_panel_start_radio_title">Hide start radio menu</string>
|
||||
<string name="revanced_hide_flyout_panel_view_song_credit_title">Hide view song credit menu</string>
|
||||
<string name="revanced_hide_general_ads_summary">Hides general ads.</string>
|
||||
<string name="revanced_hide_general_ads_title">Hide general ads</string>
|
||||
<string name="revanced_hide_handle_summary">Hides the handle in the account switcher.</string>
|
||||
<string name="revanced_hide_handle_title">Hide handle</string>
|
||||
<string name="revanced_hide_history_button_summary">Hides history button in toolbar.</string>
|
||||
@ -142,6 +147,10 @@ WARNING: Do not enable new player backgrounds while this is enabled."</string>
|
||||
<string name="revanced_hide_new_playlist_button_title">Hide new playlist button</string>
|
||||
<string name="revanced_hide_playlist_card_summary">Hides the playlist card from homepage.</string>
|
||||
<string name="revanced_hide_playlist_card_title">Hide playlist card</string>
|
||||
<string name="revanced_hide_premium_promotion_summary">Hides premium promotion popup.</string>
|
||||
<string name="revanced_hide_premium_promotion_title">Hide premium promotion popup</string>
|
||||
<string name="revanced_hide_premium_renewal_summary">Hides premium renewal banner.</string>
|
||||
<string name="revanced_hide_premium_renewal_title">Hide premium renewal banner</string>
|
||||
<string name="revanced_hide_samples_button_summary">Hides the samples button.</string>
|
||||
<string name="revanced_hide_samples_button_title">Hide samples button</string>
|
||||
<string name="revanced_hide_terms_container_summary">Hides terms of service container.</string>
|
||||
|
@ -1,10 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Translation Exception -->
|
||||
<string name="revanced_close_interstitial_ads_summary">"If Interstitial ads are detected, press the back button automatically to close it.
|
||||
Since it hasn't been tested, it most likely won't work."</string>
|
||||
<string name="revanced_close_interstitial_ads_title">Close interstitial ads</string>
|
||||
|
||||
<string name="revanced_extended_settings_title">ReVanced Extended</string>
|
||||
|
||||
<string name="revanced_hide_account_menu_filter_strings_summary">@string/revanced_custom_filter_strings_summary</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user