Skip to content

Commit

Permalink
feat(YouTube - Hide ads): Add Hide end screen store banner setting
Browse files Browse the repository at this point in the history
  • Loading branch information
MondayNitro authored and anddea committed Jan 30, 2025
1 parent 7fdc97b commit 177abbc
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@

import android.view.View;

import java.util.List;

import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.youtube.settings.Settings;

@SuppressWarnings("unused")
public class AdsPatch {
private static final boolean hideGeneralAdsEnabled = Settings.HIDE_GENERAL_ADS.get();
private static final boolean hideGetPremiumAdsEnabled = Settings.HIDE_GET_PREMIUM.get();
private static final boolean hideVideoAdsEnabled = Settings.HIDE_VIDEO_ADS.get();
private static final boolean HIDE_END_SCREEN_STORE_BANNER =
Settings.HIDE_END_SCREEN_STORE_BANNER.get();
private static final boolean HIDE_GENERAL_ADS =
Settings.HIDE_GENERAL_ADS.get();
private static final boolean HIDE_GET_PREMIUM =
Settings.HIDE_GET_PREMIUM.get();
private static final boolean HIDE_VIDEO_ADS =
Settings.HIDE_VIDEO_ADS.get();

// https://encrypted-tbn0.gstatic.com/shopping?q=tbn
private static final String STORE_BANNER_DOMAIN =
"gstatic.com/shopping";

/**
* Injection point.
Expand All @@ -19,18 +31,37 @@ public class AdsPatch {
* @param view The view, which shows ads.
*/
public static void hideAdAttributionView(View view) {
hideViewBy0dpUnderCondition(hideGeneralAdsEnabled, view);
hideViewBy0dpUnderCondition(HIDE_GENERAL_ADS, view);
}

/**
* Injection point.
*
* @param elementsList List of components of the end screen container.
* @param protobufList Component (ProtobufList).
*/
public static void hideEndScreenStoreBanner(List<Object> elementsList, Object protobufList) {
if (HIDE_END_SCREEN_STORE_BANNER &&
protobufList.toString().contains(STORE_BANNER_DOMAIN)) {
Logger.printDebug(() -> "Hiding store banner");
return;
}

elementsList.add(protobufList);
}

/**
* Injection point.
*/
public static boolean hideGetPremium() {
return hideGetPremiumAdsEnabled;
return HIDE_GET_PREMIUM;
}

/**
* Injection point.
*/
public static boolean hideVideoAds() {
return !hideVideoAdsEnabled;
return !HIDE_VIDEO_ADS;
}

/**
Expand All @@ -40,7 +71,7 @@ public static boolean hideVideoAds() {
* It is presumed to have been deprecated, and if it is confirmed that it is no longer used, remove it.
*/
public static boolean hideVideoAds(boolean original) {
return !hideVideoAdsEnabled && original;
return !HIDE_VIDEO_ADS && original;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
@SuppressWarnings("unused")
public class Settings extends BaseSettings {
// PreferenceScreen: Ads
public static final BooleanSetting HIDE_END_SCREEN_STORE_BANNER = new BooleanSetting("revanced_hide_end_screen_store_banner", TRUE, true);
public static final BooleanSetting HIDE_GENERAL_ADS = new BooleanSetting("revanced_hide_general_ads", TRUE);
public static final BooleanSetting HIDE_GET_PREMIUM = new BooleanSetting("revanced_hide_get_premium", TRUE, true);
public static final BooleanSetting HIDE_MERCHANDISE_SHELF = new BooleanSetting("revanced_hide_merchandise_shelf", TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.injectHideViewCall
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction31i
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
Expand Down Expand Up @@ -132,6 +133,24 @@ val adsPatch = bytecodePatch(

// endregion

// region patch for hide end screen store banner

fullScreenEngagementAdContainerFingerprint.methodOrThrow().apply {
val addListIndex = indexOfAddListInstruction(this)
val addListInstruction =
getInstruction<FiveRegisterInstruction>(addListIndex)
val listRegister = addListInstruction.registerC
val objectRegister = addListInstruction.registerD

replaceInstruction(
addListIndex,
"invoke-static { v$listRegister, v$objectRegister }, " +
"$ADS_CLASS_DESCRIPTOR->hideEndScreenStoreBanner(Ljava/util/List;Ljava/lang/Object;)V"
)
}

// endregion

findMethodOrThrow("$PATCHES_PATH/PatchStatus;") {
name == "HideFullscreenAdsDefaultBoolean"
}.replaceInstruction(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package app.revanced.patches.youtube.ads.general

import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementAdContainer
import app.revanced.patches.youtube.utils.resourceid.interstitialsContainer
import app.revanced.patches.youtube.utils.resourceid.slidingDialogAnimation
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal val compactYpcOfferModuleViewFingerprint = legacyFingerprint(
name = "compactYpcOfferModuleViewFingerprint",
Expand All @@ -24,6 +29,23 @@ internal val compactYpcOfferModuleViewFingerprint = legacyFingerprint(
}
)

internal val fullScreenEngagementAdContainerFingerprint = legacyFingerprint(
name = "fullScreenEngagementAdContainerFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(),
literals = listOf(fullScreenEngagementAdContainer),
customFingerprint = { method, _ ->
indexOfAddListInstruction(method) >= 0
}
)

internal fun indexOfAddListInstruction(method: Method) =
method.indexOfFirstInstructionReversed {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "add"
}

internal val interstitialsContainerFingerprint = legacyFingerprint(
name = "interstitialsContainerFingerprint",
returnType = "V",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ var floatyBarTopMargin = -1L
private set
var fullScreenButton = -1L
private set
var fullScreenEngagementAdContainer = -1L
private set
var fullScreenEngagementOverlay = -1L
private set
var fullScreenEngagementPanel = -1L
Expand Down Expand Up @@ -426,6 +428,10 @@ internal val sharedResourceIdPatch = resourcePatch(
ID,
"fullscreen_button"
]
fullScreenEngagementAdContainer = resourceMappings[
ID,
"fullscreen_engagement_ad_container"
]
fullScreenEngagementOverlay = resourceMappings[
LAYOUT,
"fullscreen_engagement_overlay"
Expand Down

0 comments on commit 177abbc

Please sign in to comment.