From bf064ecc1d5de8b592d14d34acfa1a4314c374ba Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 8 Feb 2024 20:08:44 +0100 Subject: [PATCH] feat(X): Add `Hide view count` patch --- api/revanced-patches.api | 6 ++++ .../layout/viewcount/HideViewCountPatch.kt | 30 +++++++++++++++++++ .../ViewCountsEnabledFingerprint.kt | 8 +++++ 3 files changed, 44 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/fingerprints/ViewCountsEnabledFingerprint.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index e66cfeba..262eb3e9 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1065,6 +1065,12 @@ public final class app/revanced/patches/twitch/misc/settings/SettingsResourcePat public static final field INSTANCE Lapp/revanced/patches/twitch/misc/settings/SettingsResourcePatch; } +public final class app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/twitter/layout/viewcount/HideViewCountPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch : app/revanced/patcher/patch/ResourcePatch { public static final field INSTANCE Lapp/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch; public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V diff --git a/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt b/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt new file mode 100644 index 00000000..9951e50b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt @@ -0,0 +1,30 @@ +package app.revanced.patches.twitter.layout.viewcount + + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.twitter.layout.viewcount.fingerprints.ViewCountsEnabledFingerprint +import app.revanced.util.exception + +@Patch( + name = "Hide view count", + description = "Hides the view count of Posts.", + compatiblePackages = [CompatiblePackage("com.twitter.android")], + use = false +) +@Suppress("unused") +object HideViewCountPatch : BytecodePatch( + setOf(ViewCountsEnabledFingerprint) +) { + override fun execute(context: BytecodeContext) = + ViewCountsEnabledFingerprint.result?.mutableMethod?.addInstructions( + 0, + """ + const/4 v0, 0x0 + return v0 + """ + ) ?: throw ViewCountsEnabledFingerprint.exception +} diff --git a/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/fingerprints/ViewCountsEnabledFingerprint.kt b/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/fingerprints/ViewCountsEnabledFingerprint.kt new file mode 100644 index 00000000..3b3e7aff --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/fingerprints/ViewCountsEnabledFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.twitter.layout.viewcount.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object ViewCountsEnabledFingerprint : MethodFingerprint( + returnType = "Z", + strings = listOf("view_counts_public_visibility_enabled") +)