From 6da93f984235aa52492de117bd62f43edaed35c4 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 21 Dec 2023 02:08:34 +0900 Subject: [PATCH] feat(YouTube Music/Hide general ads): add `Hide interstitial ads` settings --- .../music/ads/general/GeneralAdsPatch.kt | 49 +++++++++++++++++-- .../automotive}/AutoMotiveFingerprint.kt | 2 +- .../NavigationButtonsPatch.kt | 2 +- .../music/settings/host/values/strings.xml | 4 +- 4 files changed, 51 insertions(+), 6 deletions(-) rename src/main/kotlin/app/revanced/patches/{youtube/navigation/navigationbuttons/fingerprints => shared/fingerprints/automotive}/AutoMotiveFingerprint.kt (80%) diff --git a/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt b/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt index f0102c9a1..71b3f30c3 100644 --- a/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt @@ -2,10 +2,13 @@ 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.addInstructions 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.proxy.mutableTypes.MutableMethod +import app.revanced.patches.shared.fingerprints.automotive.AutoMotiveFingerprint 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 @@ -20,6 +23,7 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.Interst import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.util.exception +import app.revanced.util.getStringInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -37,6 +41,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") object GeneralAdsPatch : BytecodePatch( setOf( + AutoMotiveFingerprint, FloatingLayoutFingerprint, InterstitialsContainerFingerprint, NotifierShelfFingerprint @@ -48,6 +53,27 @@ object GeneralAdsPatch : BytecodePatch( /** * Hides interstitials banner (non-litho) */ + AutoMotiveFingerprint.result?.let { + it.mutableMethod.apply { + with( + context + .toMethodWalker(this) + .nextMethod(getStringInstructionIndex("Android Automotive") - 3, true) + .getMethod() as MutableMethod + ) { + val targetIndex = implementation!!.instructions.size - 1 + val targetRegister = getInstruction(targetIndex).registerA + + addInstructions( + targetIndex, """ + invoke-static {v$targetRegister}, $ADS_PATH/InterstitialsBannerPatch;->hideInterstitialsBanner(Z)Z + move-result v$targetRegister + """ + ) + } + } + } ?: throw AutoMotiveFingerprint.exception + InterstitialsContainerFingerprint.result?.let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(InterstitialsContainer) + 2 @@ -96,14 +122,31 @@ object GeneralAdsPatch : BytecodePatch( "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_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") + SettingsPatch.addMusicPreference( + CategoryType.ADS, + "revanced_hide_premium_renewal", + "true" + ) } private const val FILTER_CLASS_DESCRIPTOR = diff --git a/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/fingerprints/AutoMotiveFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/automotive/AutoMotiveFingerprint.kt similarity index 80% rename from src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/fingerprints/AutoMotiveFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/fingerprints/automotive/AutoMotiveFingerprint.kt index bfe608944..6bb79582e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/fingerprints/AutoMotiveFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/automotive/AutoMotiveFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.navigation.navigationbuttons.fingerprints +package app.revanced.patches.shared.fingerprints.automotive import app.revanced.patcher.fingerprint.MethodFingerprint import com.android.tools.smali.dexlib2.Opcode diff --git a/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt index dbfb9275a..054797c35 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt @@ -8,7 +8,7 @@ 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.proxy.mutableTypes.MutableMethod -import app.revanced.patches.youtube.navigation.navigationbuttons.fingerprints.AutoMotiveFingerprint +import app.revanced.patches.shared.fingerprints.automotive.AutoMotiveFingerprint import app.revanced.patches.youtube.navigation.navigationbuttons.fingerprints.PivotBarEnumFingerprint import app.revanced.patches.youtube.navigation.navigationbuttons.fingerprints.PivotBarShortsButtonViewFingerprint import app.revanced.patches.youtube.utils.fingerprints.PivotBarCreateButtonViewFingerprint diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index a48936d48..927473d32 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -22,7 +22,7 @@ Subscription Changes the start page of the app. Change start page - Automatically close interstitial ads. + Automatically closes interstitial ads that cannot be hidden by \"Hide interstitial ads\". Close interstitial ads Closing interstitial ads. Filter component names by line-seperated. @@ -150,6 +150,8 @@ WARNING: Do not enable new player backgrounds while this is enabled." Hide history button Hides the home button. Hide home button + Hides the interstitial ads. + Hide interstitial ads Hides the library button. Hide library button Hides ads before playing a music.