Skip to content

Commit

Permalink
feat(Twitter): Added Profile tabs customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Swakshan committed Apr 19, 2024
1 parent fcb789b commit db0298b
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package crimera.patches.twitter.misc.customize.profiletabs

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
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.extensions.InstructionExtensions.removeInstruction
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 CustomiseProfileTabsFingerprint:MethodFingerprint(
returnType = "Ljava/util/ArrayList;",
strings = listOf(
"fragment_page_number",
"arg_is_unlimited_timeline",
"statuses_count",
"tweets",
"blue_business_affiliates_list_consumption_ui_enabled",
)
)

@Patch(
name = "Customize profile tabs",
dependencies = [SettingsPatch::class],
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = false,
requiresIntegrations = true
)
@Suppress("unused")
object CustomiseProfileTabsPatch:BytecodePatch(
setOf(CustomiseProfileTabsFingerprint,SettingsStatusLoadFingerprint)
){
override fun execute(context: BytecodeContext) {
val results = CustomiseProfileTabsFingerprint.result
?:throw PatchException("CustomiseProfileTabsFingerprint not found")

val method = results.mutableMethod
val instructions = method.getInstructions()

val returnObj_loc = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index
val r0 = method.getInstruction<OneRegisterInstruction>(returnObj_loc).registerA

val METHOD = """
invoke-static {v$r0}, ${SettingsPatch.CUSTOMISE_DESCRIPTOR}/ProfileTabs;->a(Ljava/util/ArrayList;)Ljava/util/ArrayList;
move-result-object v$r0
""".trimIndent()

method.addInstructions(returnObj_loc,METHOD)

val last_if_eqz = instructions.last { it.opcode == Opcode.IF_EQZ }.location.index
val r1 = method.getInstruction<OneRegisterInstruction>(last_if_eqz).registerA

val last_if_nez_loc = instructions.last { it.opcode == Opcode.IF_NEZ }.location.index
val r2 = method.getInstruction<OneRegisterInstruction>(last_if_nez_loc).registerA

//it works dont ask me how
method.removeInstruction(last_if_eqz)
method.removeInstruction(last_if_eqz)
method.removeInstruction(last_if_eqz)

method.addInstructionsWithLabels(last_if_eqz,
"""
if-eqz v$r1, :check2
const/4 v$r2, 0x1
:check2
if-nez v$r2, :check1
""".trimIndent(), ExternalLabel("check1",instructions.last { it.opcode == Opcode.INVOKE_STATIC })
)

SettingsStatusLoadFingerprint.result!!.mutableMethod.addInstruction(
0,
"${SettingsPatch.SSTS_DESCRIPTOR}->profileTabCustomisation()V"
)
//end
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object SettingsPatch : BytecodePatch(
private const val UTILS_DESCRIPTOR = "$INTEGRATIONS_PACKAGE/Utils"
const val PREF_DESCRIPTOR = "$INTEGRATIONS_PACKAGE/Pref"
const val PATCHES_DESCRIPTOR = "$INTEGRATIONS_PACKAGE/patches"
const val CUSTOMISE_DESCRIPTOR = "$PATCHES_DESCRIPTOR/customise"
private const val ADD_PREF_DESCRIPTOR = "$UTILS_DESCRIPTOR;->addPref([Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;"
const val SSTS_DESCRIPTOR = "invoke-static {}, $INTEGRATIONS_PACKAGE/settings/SettingsStatus;"
const val FSTS_DESCRIPTOR = "invoke-static {}, $INTEGRATIONS_PACKAGE/patches/FeatureSwitchPatch;"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ object SettingsResourcePatch: ResourcePatch() {

//credits @inotia00
context.copyXmlNode("twitter/settings", "values/strings.xml", "resources")
context.copyXmlNode("twitter/settings", "values/arrays.xml", "resources")

/**
* create directory for the untranslated language resources
*/
//Strings
val languages = arrayOf(
"ar",
"ja",
Expand All @@ -70,8 +72,8 @@ object SettingsResourcePatch: ResourcePatch() {
"ru",
"pl",
"pt-rBR",
"v21",
"tr"
"tr",
"v21"
).map { "values-$it" }

languages.forEach {
Expand All @@ -82,5 +84,7 @@ object SettingsResourcePatch: ResourcePatch() {
context.copyResources("twitter/settings", ResourceGroup(it, "strings.xml"))
}
}

//end
}
}
4 changes: 2 additions & 2 deletions src/main/resources/twitter/settings/values-v21/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Translation Exception -->
<string name="piko_title_settings">Piko Mod Settings</string>
<!-- Dont translate these -->
<string name="piko_title_settings">Piko mod Settings</string>
<string name="piko_title_feature_flags">Feature flags</string>
</resources>
15 changes: 15 additions & 0 deletions src/main/resources/twitter/settings/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<!-- Dont translate these -->
<string-array name="piko_array_profiletabs">
<item>@string/profile_tab_title_timeline</item>
<item>@string/profile_tab_title_timeline_tweets_and_replies_sentence_case</item>
<item>@string/profile_tab_title_affiliates</item>
<item>@string/profile_tab_title_timeline_super_follow_tweets</item>
<item>@string/profile_tab_title_highlights</item>
<item>@string/profile_tab_title_articles</item>
<item>@string/profile_tab_title_media</item>
<item>@string/profile_tab_title_likes</item>
</string-array>
</resources>
3 changes: 3 additions & 0 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<string name="piko_pref_hide_immersive_player">Hide immersive player</string>
<string name="piko_pref_hide_immersive_player_desc">Removes swipe up for more videos in video player</string>

<string name="piko_title_customisation">Customization</string>
<string name="piko_pref_customisation_profiletabs">Profile tabs</string>

<string name="piko_title_backup">Backup and restore</string>
<string name="piko_pref_export">Export preferences</string>
<string name="piko_pref_export_flags">Export feature flags</string>
Expand Down

0 comments on commit db0298b

Please sign in to comment.