feat(reddit): add hide-screenshot-popup patch

This commit is contained in:
inotia00 2023-06-23 18:57:25 +09:00
parent 5a6c741bb4
commit ca3ff3d28d
4 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package app.revanced.patches.reddit.layout.screenshotpopup.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.reddit.utils.resourceid.patch.SharedResourceIdPatch.Companion.ScreenShotShareBanner
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.AccessFlags
object ScreenshotTakenBannerFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
customFingerprint = { methodDef, classDef -> methodDef.isWideLiteralExists(ScreenShotShareBanner) && classDef.sourceFile == "ScreenshotTakenBanner.kt" }
)

View File

@ -0,0 +1,61 @@
package app.revanced.patches.reddit.layout.screenshotpopup.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.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.reddit.layout.screenshotpopup.fingerprints.ScreenshotTakenBannerFingerprint
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
import app.revanced.patches.reddit.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch.Companion.updateSettingsStatus
@Patch
@Name("hide-screenshot-popup")
@Description("Hides the popup when taking a screenshot.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@RedditCompatibility
@Version("0.0.1")
class ScreenshotPopupPatch : BytecodePatch(
listOf(ScreenshotTakenBannerFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
ScreenshotTakenBannerFingerprint.result?.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0, """
invoke-static {}, $INTEGRATIONS_METHOD_DESCRIPTOR
move-result v0
if-eqz v0, :dismiss
return-void
""", ExternalLabel("dismiss", getInstruction(0))
)
}
} ?: return ScreenshotTakenBannerFingerprint.toErrorResult()
updateSettingsStatus("ScreenshotPopup")
return PatchResultSuccess()
}
private companion object {
private const val INTEGRATIONS_METHOD_DESCRIPTOR =
"Lapp/revanced/reddit/patches/ScreenshotPopupPatch;" +
"->hideScreenshotPopup()Z"
}
}

View File

@ -0,0 +1,36 @@
package app.revanced.patches.reddit.utils.resourceid.patch
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
import app.revanced.util.enum.ResourceType
import app.revanced.util.enum.ResourceType.STRING
@Name("reddit-resource-id")
@DependsOn([ResourceMappingPatch::class])
@RedditCompatibility
@Version("0.0.1")
class SharedResourceIdPatch : ResourcePatch {
internal companion object {
var ScreenShotShareBanner: Long = -1
}
override fun execute(context: ResourceContext): PatchResult {
fun find(resourceType: ResourceType, resourceName: String) = ResourceMappingPatch
.resourceMappings
.find { it.type == resourceType.value && it.name == resourceName }?.id
?: throw PatchResultError("Failed to find resource id : $resourceName")
ScreenShotShareBanner = find(STRING, "screenshot_share_banner_title")
return PatchResultSuccess()
}
}

View File

@ -3,4 +3,6 @@
<string name="revanced_enable_sanitize_url_query_summary">Removes (tracking) query parameters from the URLs when sharing links</string>
<string name="revanced_enable_sanitize_url_query_title">Sanitize sharing links</string>
<string name="revanced_extended_settings_title">ReVanced Extended</string>
<string name="revanced_hide_screenshot_popup_summary">Hides the popup when taking a screenshot</string>
<string name="revanced_hide_screenshot_popup_title">Hide screenshot popup</string>
</resources>