From ad27484f4cc0d727cf07cb4f202c8ddd6b582d67 Mon Sep 17 00:00:00 2001 From: swakwork Date: Tue, 24 Sep 2024 23:53:18 +0530 Subject: [PATCH] feat(Twitter): Added `Hide nudge button` patch --- .../hideNudgeButtons/HideNudgeButtonPatch.kt | 59 +++++++++++++++++++ .../twitter/settings/values/strings.xml | 2 + 2 files changed, 61 insertions(+) create mode 100644 src/main/kotlin/crimera/patches/twitter/timeline/hideNudgeButtons/HideNudgeButtonPatch.kt diff --git a/src/main/kotlin/crimera/patches/twitter/timeline/hideNudgeButtons/HideNudgeButtonPatch.kt b/src/main/kotlin/crimera/patches/twitter/timeline/hideNudgeButtons/HideNudgeButtonPatch.kt new file mode 100644 index 00000000..436259ea --- /dev/null +++ b/src/main/kotlin/crimera/patches/twitter/timeline/hideNudgeButtons/HideNudgeButtonPatch.kt @@ -0,0 +1,59 @@ +package crimera.patches.twitter.timeline.hideNudgeButtons + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstructions +import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.smali.ExternalLabel +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import crimera.patches.twitter.misc.settings.SettingsPatch +import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint + +object HideNudgeButtonPatchFingerprint : MethodFingerprint( + strings = listOf("creator_subscriptions_subscribe_button_tweet_detail_enabled"), + customFingerprint = {methodDef, _ -> + methodDef.parameters.size == 1 && methodDef.name == "invoke" + } +) + +@Patch( + name = "Hide nudge button", + description = "Hides follow/subscribe/follow back buttons on posts", + compatiblePackages = [CompatiblePackage("com.twitter.android")], + dependencies = [SettingsPatch::class], + use = true, +) +@Suppress("unused") +object HideNudgeButtonPatch:BytecodePatch( + setOf(HideNudgeButtonPatchFingerprint,SettingsStatusLoadFingerprint) +) { + const val HOOK_DESCRIPTOR = + "invoke-static {}, ${SettingsPatch.PREF_DESCRIPTOR};->hideNudgeButton()Z" + + override fun execute(context: BytecodeContext) { + val result = HideNudgeButtonPatchFingerprint.result + ?: throw PatchException("HideNudgeButtonPatchFingerprint not found") + + val method = result.mutableMethod + val instructions = method.getInstructions() + + val injectLocation = instructions.first { it.opcode == Opcode.IF_NEZ}.location.index + val dummyReg = method.getInstruction(injectLocation-1).registerA + + method.addInstructionsWithLabels(injectLocation-1,""" + $HOOK_DESCRIPTOR + move-result v$dummyReg + if-nez v$dummyReg, :piko + """.trimIndent(), ExternalLabel("piko",instructions.last { it.opcode == Opcode.SGET_OBJECT }) + ) + + SettingsStatusLoadFingerprint.enableSettings("hideNudgeButton") + + } +} \ No newline at end of file diff --git a/src/main/resources/twitter/settings/values/strings.xml b/src/main/resources/twitter/settings/values/strings.xml index 50e102fd..3a51cc12 100644 --- a/src/main/resources/twitter/settings/values/strings.xml +++ b/src/main/resources/twitter/settings/values/strings.xml @@ -97,6 +97,8 @@ hidden replies force HD videos Videos will be played in highest quality always + Hide nudge button + Hides follow/subscribe/follow back buttons on posts Customization Profile tabs to hide