fix(YouTube Music - Hide ads): Hide fullscreen ads setting does not completely hide the fullscreen ads https://github.com/inotia00/ReVanced_Extended/issues/2515

This commit is contained in:
inotia00
2025-02-10 16:21:07 +09:00
parent 7667b70c67
commit af447be6cc
7 changed files with 58 additions and 39 deletions

View File

@ -150,10 +150,12 @@ val adsPatch = bytecodePatch(
addLithoFilter(ADS_FILTER_CLASS_DESCRIPTOR)
// endregion
addSwitchPreference(
CategoryType.ADS,
"revanced_hide_fullscreen_ads",
"false"
"true"
)
addSwitchPreference(
CategoryType.ADS,

View File

@ -16,6 +16,7 @@ import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
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
@ -91,17 +92,32 @@ internal fun MutableMethod.hookNonLithoFullscreenAds(literal: Long) {
internal fun Match.hookLithoFullscreenAds() {
method.apply {
// It is ideal to check the dialog type and protobuffer before closing the dialog.
// There is no register that can be used freely, so it is divided into two hooking.
val showDialogIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "show"
}
val dialogRegister = getInstruction<FiveRegisterInstruction>(showDialogIndex).registerC
addInstruction(
showDialogIndex + 1,
"invoke-static {v$dialogRegister}, $EXTENSION_CLASS_DESCRIPTOR->dismissDialog(Ljava/lang/Object;)V"
)
// Dialog type should be checked first.
val dialogCodeIndex = patternMatch!!.endIndex
val dialogCodeField =
getInstruction<ReferenceInstruction>(dialogCodeIndex).reference as FieldReference
if (dialogCodeField.type != "I")
if (dialogCodeField.type != "I") {
throw PatchException("Invalid dialogCodeField: $dialogCodeField")
}
var prependInstructions = """
move-object/from16 v0, p1
move-object/from16 v1, p2
"""
// Used only in very old versions.
if (parameterTypes.firstOrNull() != "[B") {
val toByteArrayReference = getInstruction<ReferenceInstruction>(
indexOfFirstInstructionOrThrow {
@ -116,15 +132,12 @@ internal fun Match.hookLithoFullscreenAds() {
}
// Disable fullscreen ads
addInstructionsWithLabels(
addInstructions(
0, prependInstructions + """
check-cast v1, ${dialogCodeField.definingClass}
iget v1, v1, $dialogCodeField
invoke-static {v0, v1}, $EXTENSION_CLASS_DESCRIPTOR->disableFullscreenAds([BI)Z
move-result v1
if-eqz v1, :show
return-void
""", ExternalLabel("show", getInstruction(0))
invoke-static {v0, v1}, $EXTENSION_CLASS_DESCRIPTOR->checkDialog([BI)V
"""
)
}
}

View File

@ -8,7 +8,6 @@ import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.ads.baseAdsPatch
import app.revanced.patches.shared.ads.hookLithoFullscreenAds
import app.revanced.patches.shared.ads.hookNonLithoFullscreenAds
import app.revanced.patches.shared.extension.Constants.PATCHES_PATH
import app.revanced.patches.shared.litho.addLithoFilter
import app.revanced.patches.shared.litho.lithoFilterPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
@ -22,7 +21,6 @@ import app.revanced.patches.youtube.utils.resourceid.interstitialsContainer
import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.findMethodOrThrow
import app.revanced.util.findMutableMethodOf
import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
@ -151,13 +149,6 @@ val adsPatch = bytecodePatch(
// endregion
findMethodOrThrow("$PATCHES_PATH/PatchStatus;") {
name == "HideFullscreenAdsDefaultBoolean"
}.replaceInstruction(
0,
"const/4 v0, 0x1"
)
// region add settings
addPreference(