Skip to content

Commit 7eb0c06

Browse files
committed
fix(Reddit - Hide ads): View all comments button hidden if comment ads are hidden inotia00/ReVanced_Extended#2765 (Also close inotia00/ReVanced_Extended#2678)
1 parent 2ec24f9 commit 7eb0c06

File tree

3 files changed

+35
-82
lines changed

3 files changed

+35
-82
lines changed

extensions/shared/src/main/java/app/revanced/extension/reddit/settings/ActivityHook.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
import app.revanced.extension.reddit.settings.preference.ReVancedPreferenceFragment;
99

10-
/**
11-
* @noinspection ALL
12-
*/
10+
@SuppressWarnings("all")
1311
public class ActivityHook {
1412
public static void initialize(Activity activity) {
1513
SettingsStatus.load();

patches/src/main/kotlin/app/revanced/patches/reddit/ad/AdsPatch.kt

Lines changed: 34 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,42 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
55
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
66
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
77
import app.revanced.patcher.patch.bytecodePatch
8-
import app.revanced.patcher.patch.resourcePatch
9-
import app.revanced.patcher.util.smali.ExternalLabel
108
import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE
119
import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH
1210
import app.revanced.patches.reddit.utils.patch.PatchList.HIDE_ADS
1311
import app.revanced.patches.reddit.utils.settings.settingsPatch
1412
import app.revanced.patches.reddit.utils.settings.updatePatchStatus
15-
import app.revanced.util.fingerprint.matchOrThrow
13+
import app.revanced.util.findMutableMethodOf
1614
import app.revanced.util.fingerprint.methodOrThrow
1715
import app.revanced.util.getReference
18-
import app.revanced.util.getWalkerMethod
1916
import app.revanced.util.indexOfFirstInstructionOrThrow
2017
import app.revanced.util.indexOfFirstStringInstruction
18+
import app.revanced.util.or
19+
import com.android.tools.smali.dexlib2.AccessFlags
20+
import com.android.tools.smali.dexlib2.iface.Method
2121
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
2222
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
2323
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
2424

25-
private const val RESOURCE_FILE_PATH = "res/layout/merge_listheader_link_detail.xml"
26-
27-
private val bannerAdsPatch = resourcePatch(
28-
description = "bannerAdsPatch",
29-
) {
30-
execute {
31-
document(RESOURCE_FILE_PATH).use { document ->
32-
document.getElementsByTagName("merge").item(0).childNodes.apply {
33-
val attributes = arrayOf("height", "width")
34-
35-
for (i in 1 until length) {
36-
val view = item(i)
37-
if (
38-
view.hasAttributes() &&
39-
view.attributes.getNamedItem("android:id").nodeValue.endsWith("ad_view_stub")
40-
) {
41-
attributes.forEach { attribute ->
42-
view.attributes.getNamedItem("android:layout_$attribute").nodeValue =
43-
"0.0dip"
44-
}
45-
46-
break
47-
}
48-
}
49-
}
50-
}
51-
}
52-
}
53-
54-
private const val EXTENSION_METHOD_DESCRIPTOR =
55-
"$PATCHES_PATH/GeneralAdsPatch;->hideCommentAds()Z"
56-
57-
private val commentAdsPatch = bytecodePatch(
58-
description = "commentAdsPatch",
59-
) {
60-
execute {
61-
commentAdsFingerprint.matchOrThrow().let {
62-
val walkerMethod = it.getWalkerMethod(it.patternMatch!!.startIndex)
63-
walkerMethod.apply {
64-
addInstructionsWithLabels(
65-
0, """
66-
invoke-static {}, $EXTENSION_METHOD_DESCRIPTOR
67-
move-result v0
68-
if-eqz v0, :show
69-
new-instance v0, Ljava/lang/Object;
70-
invoke-direct {v0}, Ljava/lang/Object;-><init>()V
71-
return-object v0
72-
""", ExternalLabel("show", getInstruction(0))
73-
)
74-
}
75-
}
76-
}
77-
}
78-
7925
private const val EXTENSION_CLASS_DESCRIPTOR =
8026
"$PATCHES_PATH/GeneralAdsPatch;"
8127

28+
private val isCommentAdsMethod: Method.() -> Boolean = {
29+
parameterTypes.size == 1 &&
30+
parameterTypes.first().startsWith("Lcom/reddit/ads/conversation/") &&
31+
accessFlags == AccessFlags.PUBLIC or AccessFlags.FINAL &&
32+
returnType == "V" &&
33+
indexOfFirstStringInstruction("ad") >= 0
34+
}
35+
8236
@Suppress("unused")
8337
val adsPatch = bytecodePatch(
8438
HIDE_ADS.title,
8539
HIDE_ADS.summary,
8640
) {
8741
compatibleWith(COMPATIBLE_PACKAGE)
8842

89-
dependsOn(
90-
settingsPatch,
91-
bannerAdsPatch,
92-
commentAdsPatch,
93-
)
43+
dependsOn(settingsPatch)
9444

9545
execute {
9646
// region Filter promoted ads (does not work in popular or latest feed)
@@ -127,6 +77,27 @@ val adsPatch = bytecodePatch(
12777
)
12878
}
12979

80+
// region Filter comment ads
81+
classes.forEach { classDef ->
82+
classDef.methods.forEach { method ->
83+
if (method.isCommentAdsMethod()) {
84+
proxy(classDef)
85+
.mutableClass
86+
.findMutableMethodOf(method)
87+
.addInstructionsWithLabels(
88+
0, """
89+
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->hideCommentAds()Z
90+
move-result v0
91+
if-eqz v0, :show
92+
return-void
93+
:show
94+
nop
95+
"""
96+
)
97+
}
98+
}
99+
}
100+
130101
updatePatchStatus(
131102
"enableGeneralAds",
132103
HIDE_ADS

patches/src/main/kotlin/app/revanced/patches/reddit/ad/Fingerprints.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@ import com.android.tools.smali.dexlib2.Opcode
99
import com.android.tools.smali.dexlib2.iface.Method
1010
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
1111

12-
internal val commentAdsFingerprint = legacyFingerprint(
13-
name = "commentAdsFingerprint",
14-
returnType = "L",
15-
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
16-
parameters = listOf("L"),
17-
opcodes = listOf(
18-
Opcode.INVOKE_STATIC,
19-
Opcode.MOVE_RESULT_OBJECT,
20-
Opcode.RETURN_OBJECT
21-
),
22-
customFingerprint = { method, _ ->
23-
method.definingClass.endsWith("/PostDetailPresenter\$loadAd\$1;") &&
24-
method.name == "invokeSuspend"
25-
},
26-
)
27-
2812
internal val adPostFingerprint = legacyFingerprint(
2913
name = "adPostFingerprint",
3014
returnType = "V",

0 commit comments

Comments
 (0)