fix(Reddit - Hide ads): Promoted ads showing in comments

This commit is contained in:
inotia00 2025-03-15 14:40:54 +09:00
parent 81f262ef62
commit 3fb1ef2546
2 changed files with 51 additions and 16 deletions

View File

@ -5,9 +5,11 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH
import app.revanced.patches.reddit.utils.patch.PatchList.HIDE_ADS import app.revanced.patches.reddit.utils.patch.PatchList.HIDE_ADS
import app.revanced.patches.reddit.utils.settings.is_2025_06_or_greater
import app.revanced.patches.reddit.utils.settings.settingsPatch import app.revanced.patches.reddit.utils.settings.settingsPatch
import app.revanced.patches.reddit.utils.settings.updatePatchStatus import app.revanced.patches.reddit.utils.settings.updatePatchStatus
import app.revanced.util.findMutableMethodOf import app.revanced.util.findMutableMethodOf
@ -78,13 +80,8 @@ val adsPatch = bytecodePatch(
} }
// region Filter comment ads // region Filter comment ads
classes.forEach { classDef -> fun MutableMethod.hook() =
classDef.methods.forEach { method -> addInstructionsWithLabels(
if (method.isCommentAdsMethod()) {
proxy(classDef)
.mutableClass
.findMutableMethodOf(method)
.addInstructionsWithLabels(
0, """ 0, """
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->hideCommentAds()Z invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->hideCommentAds()Z
move-result v0 move-result v0
@ -94,6 +91,22 @@ val adsPatch = bytecodePatch(
nop nop
""" """
) )
if (is_2025_06_or_greater) {
listOf(
commentAdCommentScreenAdViewFingerprint,
commentAdDetailListHeaderViewFingerprint
).forEach { fingerprint ->
fingerprint.methodOrThrow().hook()
}
} else {
classes.forEach { classDef ->
classDef.methods.forEach { method ->
if (method.isCommentAdsMethod()) {
proxy(classDef)
.mutableClass
.findMutableMethodOf(method)
.hook()
}
} }
} }
} }

View File

@ -27,6 +27,28 @@ internal val adPostFingerprint = legacyFingerprint(
}, },
) )
internal val commentAdCommentScreenAdViewFingerprint = legacyFingerprint(
name = "commentAdCommentScreenAdViewFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
strings = listOf("ad"),
customFingerprint = { _, classDef ->
classDef.type.endsWith("/CommentScreenAdView;")
},
)
internal val commentAdDetailListHeaderViewFingerprint = legacyFingerprint(
name = "commentAdDetailListHeaderViewFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
strings = listOf("ad"),
customFingerprint = { _, classDef ->
classDef.type.endsWith("/DetailListHeaderView;")
},
)
internal val newAdPostFingerprint = legacyFingerprint( internal val newAdPostFingerprint = legacyFingerprint(
name = "newAdPostFingerprint", name = "newAdPostFingerprint",
returnType = "L", returnType = "L",