From 473e0512314dfa9790cf83b4cfcc7505058d3a51 Mon Sep 17 00:00:00 2001 From: Aunali321 <48486084+Aunali321@users.noreply.github.com> Date: Thu, 29 Jun 2023 06:37:03 +0530 Subject: [PATCH] feat(reddit): add `disable-screenshot-popup` patch (#2387) Co-authored-by: oSumAtrIX --- .idea/misc.xml | 2 +- .../DisableScreenshotPopupCompatibility.kt | 8 +++++ .../DisableScreenshotPopupFingerprint.kt | 14 +++++++++ .../patch/DisableScreenshotPopupPatch.kt | 30 +++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/annotations/DisableScreenshotPopupCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/fingerprints/DisableScreenshotPopupFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/patch/DisableScreenshotPopupPatch.kt diff --git a/.idea/misc.xml b/.idea/misc.xml index f1854e4b..e086a70c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,5 +4,5 @@ - + \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/annotations/DisableScreenshotPopupCompatibility.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/annotations/DisableScreenshotPopupCompatibility.kt new file mode 100644 index 00000000..d0620b56 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/annotations/DisableScreenshotPopupCompatibility.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.reddit.layout.disablescreenshotpopup.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.reddit.frontpage")]) +@Target(AnnotationTarget.CLASS) +internal annotation class DisableScreenshotPopupCompatibility \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/fingerprints/DisableScreenshotPopupFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/fingerprints/DisableScreenshotPopupFingerprint.kt new file mode 100644 index 00000000..de74945c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/fingerprints/DisableScreenshotPopupFingerprint.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.reddit.layout.disablescreenshotpopup.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object DisableScreenshotPopupFingerprint : MethodFingerprint( + "V", + parameters = listOf("Landroidx/compose/runtime/", "I"), + customFingerprint = custom@{ methodDef, classDef -> + if (!classDef.type.endsWith("\$ScreenshotTakenBannerKt\$lambda-1\$1;")) + return@custom false + + methodDef.name == "invoke" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/patch/DisableScreenshotPopupPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/patch/DisableScreenshotPopupPatch.kt new file mode 100644 index 00000000..6c6c652b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/patch/DisableScreenshotPopupPatch.kt @@ -0,0 +1,30 @@ +package app.revanced.patches.reddit.layout.disablescreenshotpopup.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.reddit.layout.disablescreenshotpopup.annotations.DisableScreenshotPopupCompatibility +import app.revanced.patches.reddit.layout.disablescreenshotpopup.fingerprints.DisableScreenshotPopupFingerprint + +@Patch +@Name("disable-screenshot-popup") +@Description("Disables the popup that shows up when taking a screenshot.") +@DisableScreenshotPopupCompatibility +@Version("0.0.1") +class DisableScreenshotPopupPatch : BytecodePatch( + listOf(DisableScreenshotPopupFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + DisableScreenshotPopupFingerprint.result?.mutableMethod?.addInstruction(0, "return-void") + ?: return DisableScreenshotPopupFingerprint.toErrorResult() + + return PatchResultSuccess() + } +}