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 98dd6c53b..aaeb7468d 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 @@ -8,6 +8,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import app.revanced.extension.reddit.settings.Settings; +import app.revanced.extension.shared.utils.Logger; import app.revanced.extension.shared.utils.Utils; @SuppressWarnings("unused") @@ -30,6 +31,22 @@ public class RemoveSubRedditDialogPatch { clickViewDelayed(cancelButtonView); } + public static void dismissDialogV2(Object object) { + if (!Settings.REMOVE_NOTIFICATION_DIALOG.get()) + return; + + Utils.runOnMainThreadDelayed(() -> { + try { + dismissRedditDialogV2(object); + } catch (Exception ex) { + Logger.printException(() -> "dismissDialogV2 failed", ex); + } + }, 0); + } + + private static void dismissRedditDialogV2(Object object) { + } + private static void clickViewDelayed(View view) { Utils.runOnMainThreadDelayed(() -> { if (view != null) { 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 bebd879c6..f8ab5cc7b 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 @@ -3,6 +3,7 @@ package app.revanced.patches.reddit.layout.subredditdialog import app.revanced.util.fingerprint.legacyFingerprint import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.indexOfFirstInstructionReversed import app.revanced.util.or import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode @@ -25,6 +26,40 @@ internal val frequentUpdatesSheetScreenFingerprint = legacyFingerprint( } ) +internal val frequentUpdatesSheetV2ScreenFingerprint = legacyFingerprint( + name = "frequentUpdatesSheetV2ScreenFingerprint", + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + strings = listOf("subreddit_name"), + customFingerprint = { method, classDef -> + classDef.type == "Lcom/reddit/screens/pager/v2/FrequentUpdatesSheetV2Screen;" + } +) + +internal val frequentUpdatesSheetV2ScreenInvokeFingerprint = legacyFingerprint( + name = "frequentUpdatesSheetV2ScreenInvokeFingerprint", + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + opcodes = listOf( + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID, + ), + customFingerprint = { method, classDef -> + classDef.type.startsWith("Lcom/reddit/screens/pager/v2/FrequentUpdatesSheetV2Screen${'$'}SheetContent${'$'}") && + method.name == "invoke" && + indexOfDismissScreenInstruction(method) >= 0 + } +) + +fun indexOfDismissScreenInstruction(method: Method) = + method.indexOfFirstInstructionReversed { + val reference = getReference() + opcode == Opcode.INVOKE_VIRTUAL && + reference?.returnType == "V" && + reference.parameterTypes.isEmpty() + } + internal val redditAlertDialogsFingerprint = legacyFingerprint( name = "redditAlertDialogsFingerprint", returnType = "V", 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 fa57ecabe..bed1778a3 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 @@ -1,20 +1,25 @@ 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.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction import app.revanced.patcher.patch.bytecodePatch 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 +import app.revanced.patches.reddit.utils.settings.is_2024_41_or_greater import app.revanced.patches.reddit.utils.settings.settingsPatch import app.revanced.patches.reddit.utils.settings.updatePatchStatus -import app.revanced.util.fingerprint.matchOrThrow +import app.revanced.util.findMethodOrThrow import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.indexOfFirstInstructionReversedOrThrow 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.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = @@ -30,20 +35,50 @@ val subRedditDialogPatch = bytecodePatch( dependsOn(settingsPatch) execute { - frequentUpdatesSheetScreenFingerprint.matchOrThrow().let { - it.method.apply { - val cancelButtonViewIndex = it.patternMatch!!.startIndex + 2 - val cancelButtonViewRegister = - getInstruction(cancelButtonViewIndex).registerA - addInstruction( - cancelButtonViewIndex + 1, - "invoke-static {v$cancelButtonViewRegister}, $EXTENSION_CLASS_DESCRIPTOR->dismissDialog(Landroid/view/View;)V" - ) - } + frequentUpdatesSheetScreenFingerprint.methodOrThrow().apply { + val index = indexOfFirstInstructionReversedOrThrow(Opcode.RETURN_OBJECT) + val register = + getInstruction(index).registerA + + addInstruction( + index, + "invoke-static {v$register}, $EXTENSION_CLASS_DESCRIPTOR->onDialogCreated(Landroid/view/View;)V" + ) } - redditAlertDialogsFingerprint.methodOrThrow().apply { + if (is_2024_41_or_greater) { + val dismissReference = with (frequentUpdatesSheetV2ScreenInvokeFingerprint.methodOrThrow()) { + val index = indexOfDismissScreenInstruction(this) + getInstruction(index).reference as MethodReference + } + + findMethodOrThrow(EXTENSION_CLASS_DESCRIPTOR) { + name == "dismissRedditDialogV2" + }.addInstructions( + 0, """ + check-cast p0, ${dismissReference.definingClass} + invoke-virtual {p0}, $dismissReference + """ + ) + + frequentUpdatesSheetV2ScreenFingerprint + .methodOrThrow() + .apply { + val targetIndex = implementation!!.instructions.lastIndex + + addInstructions( + targetIndex + 1, """ + invoke-static {p0}, $EXTENSION_CLASS_DESCRIPTOR->dismissDialogV2(Ljava/lang/Object;)V + return-void + """ + ) + removeInstruction(targetIndex) + } + } + + // Not used in latest Reddit client. + redditAlertDialogsFingerprint.second.methodOrNull?.apply { val backgroundTintIndex = indexOfSetBackgroundTintListInstruction(this) val insertIndex = indexOfFirstInstructionOrThrow(backgroundTintIndex) { diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt index 65ca353e8..f92060401 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt @@ -35,6 +35,8 @@ private lateinit var settingsStatusLoadMethod: MutableMethod var is_2024_18_or_greater = false private set +var is_2024_41_or_greater = false + private set private val settingsBytecodePatch = bytecodePatch( description = "settingsBytecodePatch" @@ -56,6 +58,7 @@ private val settingsBytecodePatch = bytecodePatch( .replace(".", "").toInt() is_2024_18_or_greater = 2024180 <= versionNumber + is_2024_41_or_greater = 2024100 <= versionNumber } /**