diff --git a/extensions/shared/src/main/java/app/revanced/extension/reddit/patches/RemoveSubRedditDialogPatch.java b/extensions/shared/src/main/java/app/revanced/extension/reddit/patches/RemoveSubRedditDialogPatch.java index a92e406e4..fae8d0627 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/reddit/patches/RemoveSubRedditDialogPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/reddit/patches/RemoveSubRedditDialogPatch.java @@ -33,6 +33,10 @@ public class RemoveSubRedditDialogPatch { clickViewDelayed(cancelButtonView); } + public static boolean spoofHasBeenVisitedStatus(boolean hasBeenVisited) { + return Settings.REMOVE_NSFW_DIALOG.get() || hasBeenVisited; + } + public static void dismissNSFWDialog(Object customDialog) { if (Settings.REMOVE_NSFW_DIALOG.get() && customDialog instanceof Dialog dialog) { diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/Fingerprints.kt index 06bd1b5b4..bea8e6697 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/Fingerprints.kt @@ -10,7 +10,6 @@ import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference -import com.android.tools.smali.dexlib2.iface.reference.TypeReference internal val frequentUpdatesSheetScreenFingerprint = legacyFingerprint( name = "frequentUpdatesSheetScreenFingerprint", @@ -54,13 +53,6 @@ fun listOfIsLoggedInInstruction(method: Method) = ?.reversed() ?: emptyList() -fun indexOfGetOverInstruction(method: Method) = - method.indexOfFirstInstruction { - val reference = getReference() - opcode == Opcode.INVOKE_VIRTUAL && - reference?.name == "getOver18" - } - internal val nsfwAlertEmitFingerprint = legacyFingerprint( name = "nsfwAlertEmitFingerprint", returnType = "Ljava/lang/Object;", @@ -68,24 +60,17 @@ internal val nsfwAlertEmitFingerprint = legacyFingerprint( strings = listOf("reddit://reddit/r/", "nsfwAlertDelegate"), customFingerprint = { method, _ -> method.name == "emit" && - indexOfGetOverInstruction(method) >= 0 + indexOfHasBeenVisitedInstruction(method) >= 0 } ) -internal val nsfwAlertObserverFingerprint = legacyFingerprint( - name = "nsfwAlertObserverFingerprint", - returnType = "Ljava/lang/Object;", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - strings = listOf("nsfwAlertDelegate"), - customFingerprint = { method, _ -> - method.name == "invokeSuspend" && - indexOfGetOverInstruction(method) >= 0 && - method.indexOfFirstInstruction { - opcode == Opcode.NEW_INSTANCE && - getReference()?.type?.startsWith("Lcom/reddit/frontpage/presentation/detail/DetailHolderPresenter\$showDialogIfNeverVisitedOrSubscribed\$") == true - } >= 0 +fun indexOfHasBeenVisitedInstruction(method: Method) = + method.indexOfFirstInstruction { + val reference = getReference() + opcode == Opcode.INVOKE_VIRTUAL && + reference?.name == "getHasBeenVisited" && + reference.returnType == "Z" } -) internal val nsfwAlertBuilderFingerprint = legacyFingerprint( name = "nsfwAlertBuilderFingerprint", diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt index db196001c..58e8d5fbc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt @@ -2,11 +2,9 @@ package app.revanced.patches.reddit.layout.subredditdialog import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.bytecodePatch -import app.revanced.patcher.util.smali.ExternalLabel 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.patch.PatchList.REMOVE_SUBREDDIT_DIALOG @@ -17,7 +15,6 @@ import app.revanced.patches.reddit.utils.settings.is_2025_05_or_greater 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.updatePatchStatus -import app.revanced.util.findFreeRegister import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.fingerprint.mutableClassOrThrow import app.revanced.util.getReference @@ -80,26 +77,17 @@ val subRedditDialogPatch = bytecodePatch( } if (is_2025_01_or_greater) { - arrayOf( - nsfwAlertEmitFingerprint, - nsfwAlertObserverFingerprint - ).forEach { fingerprint -> - fingerprint.methodOrThrow().apply { - val getOverIndex = indexOfGetOverInstruction(this) - val getOverRegister = getInstruction(getOverIndex).registerC - val freeRegister = findFreeRegister(getOverIndex, getOverRegister) + nsfwAlertEmitFingerprint.methodOrThrow().apply { + val hasBeenVisitedIndex = indexOfHasBeenVisitedInstruction(this) + val hasBeenVisitedRegister = + getInstruction(hasBeenVisitedIndex + 1).registerA - val returnIndex = indexOfFirstInstructionOrThrow(getOverIndex, Opcode.RETURN_OBJECT) - val jumpIndex = indexOfFirstInstructionReversedOrThrow(returnIndex, Opcode.SGET_OBJECT) - - addInstructionsWithLabels( - getOverIndex, """ - invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->removeNSFWDialog()Z - move-result v$freeRegister - if-nez v$freeRegister, :jump - """, ExternalLabel("jump", getInstruction(jumpIndex)) - ) - } + addInstructions( + hasBeenVisitedIndex + 2, """ + invoke-static {v$hasBeenVisitedRegister}, $EXTENSION_CLASS_DESCRIPTOR->spoofHasBeenVisitedStatus(Z)Z + move-result v$hasBeenVisitedRegister + """ + ) } var hookCount = 0