Skip to content

Commit

Permalink
feat(Twitter): Added Hide nudge button patch
Browse files Browse the repository at this point in the history
  • Loading branch information
swakwork committed Sep 24, 2024
1 parent 9e15934 commit ad27484
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<OneRegisterInstruction>(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")

}
}
2 changes: 2 additions & 0 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
<string name="piko_pref_hide_hidden_replies">hidden replies</string>
<string name="piko_pref_force_hd">force HD videos</string>
<string name="piko_pref_force_hd_desc">Videos will be played in highest quality always</string>
<string name="piko_pref_hide_nudge_button">Hide nudge button</string>
<string name="piko_pref_hide_nudge_button_desc">Hides follow/subscribe/follow back buttons on posts</string>

<string name="piko_title_customisation">Customization</string>
<string name="piko_pref_customisation_profiletabs">Profile tabs to hide</string>
Expand Down

0 comments on commit ad27484

Please sign in to comment.