From ea608e09b7b0775f38ca1914503e1b54dc7b73f9 Mon Sep 17 00:00:00 2001 From: swakwork Date: Tue, 12 Nov 2024 00:03:40 +0530 Subject: [PATCH] feat(Twitter): Added `Customise post font size` patch --- .../postFontSize/CustomizePostFontSize.kt | 50 +++++++++++++++++++ .../twitter/settings/values/strings.xml | 1 + 2 files changed, 51 insertions(+) create mode 100644 src/main/kotlin/crimera/patches/twitter/misc/customize/postFontSize/CustomizePostFontSize.kt diff --git a/src/main/kotlin/crimera/patches/twitter/misc/customize/postFontSize/CustomizePostFontSize.kt b/src/main/kotlin/crimera/patches/twitter/misc/customize/postFontSize/CustomizePostFontSize.kt new file mode 100644 index 00000000..02f907ef --- /dev/null +++ b/src/main/kotlin/crimera/patches/twitter/misc/customize/postFontSize/CustomizePostFontSize.kt @@ -0,0 +1,50 @@ +package crimera.patches.twitter.misc.customize.postFontSize + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstructions +import app.revanced.patcher.extensions.or +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 com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode +import crimera.patches.twitter.misc.settings.SettingsPatch +import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint + +object CustomizePostFontSizeFingerprint : MethodFingerprint( + accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("TextContentView;") + }, +) + +@Patch( + name = "Customise post font size", + description = "", + dependencies = [SettingsPatch::class], + compatiblePackages = [CompatiblePackage("com.twitter.android")], + use = true, +) +object CustomizePostFontSize : BytecodePatch( + setOf(CustomizePostFontSizeFingerprint, SettingsStatusLoadFingerprint), +) { + override fun execute(context: BytecodeContext) { + val result1 = + CustomizePostFontSizeFingerprint.result + ?: throw PatchException("CustomizePostFontSizeFingerprint not found") + + val method1 = result1.mutableMethod + + val index1 = + method1 + .getInstructions() + .last { it.opcode == Opcode.MOVE_RESULT } + .location.index + method1.addInstruction(index1 + 1, "sget p1, ${SettingsPatch.PREF_DESCRIPTOR};->POST_FONT_SIZE:F") + + SettingsStatusLoadFingerprint.enableSettings("customPostFontSize") + } +} diff --git a/src/main/resources/twitter/settings/values/strings.xml b/src/main/resources/twitter/settings/values/strings.xml index ebd3244f..6a87ef4a 100644 --- a/src/main/resources/twitter/settings/values/strings.xml +++ b/src/main/resources/twitter/settings/values/strings.xml @@ -121,6 +121,7 @@ Inline bar items to hide Default reply sorting filter Previously selected + Post font size Backup and restore