diff --git a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt index 8542bc819..dba34f5a0 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt @@ -15,6 +15,7 @@ import app.revanced.patches.shared.settings.fingerprints.SharedSettingFingerprin import app.revanced.util.getInstruction import app.revanced.util.getTargetIndexOrThrow import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow +import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.resultOrThrow import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @@ -32,16 +33,31 @@ class SettingsBytecodePatch : BytecodePatch( private const val INTEGRATIONS_METHOD_DESCRIPTOR = "$INTEGRATIONS_PATH/settings/ActivityHook;->initialize(Landroid/app/Activity;)V" + private lateinit var acknowledgementsLabelBuilderMethod: MutableMethod private lateinit var settingsStatusLoadMethod: MutableMethod - internal fun updateSettingsStatus(description: String) { + internal fun updateSettingsLabel(label: String) = + acknowledgementsLabelBuilderMethod.apply { + val insertIndex = + getTargetIndexWithMethodReferenceNameOrThrow("getString") + 2 + val insertRegister = + getInstruction(insertIndex - 1).registerA + + addInstruction( + insertIndex, + "const-string v$insertRegister, \"$label\"" + ) + } + + internal fun updateSettingsStatus(description: String) = settingsStatusLoadMethod.addInstruction( 0, "invoke-static {}, $INTEGRATIONS_PATH/settings/SettingsStatus;->$description()V" ) - } } + lateinit var contexts: BytecodeContext + override fun execute(context: BytecodeContext) { /** @@ -62,19 +78,9 @@ class SettingsBytecodePatch : BytecodePatch( /** * Replace settings label */ - AcknowledgementsLabelBuilderFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val insertIndex = - getTargetIndexWithMethodReferenceNameOrThrow("getString") + 2 - val insertRegister = - getInstruction(insertIndex - 1).registerA - - addInstruction( - insertIndex, - "const-string v$insertRegister, \"ReVanced Extended\"" - ) - } - } + acknowledgementsLabelBuilderMethod = AcknowledgementsLabelBuilderFingerprint + .resultOrThrow() + .mutableMethod /** * Initialize settings activity diff --git a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt index 853d00fd2..be356c348 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsPatch.kt @@ -4,6 +4,8 @@ import app.revanced.patcher.ResourceContext import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.apk.Apk +import app.revanced.patcher.patch.OptionsContainer +import app.revanced.patcher.patch.PatchOption import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch @@ -11,6 +13,7 @@ import app.revanced.patcher.patch.annotations.RequiresIntegrations import app.revanced.patches.reddit.utils.annotation.RedditCompatibility import app.revanced.patches.reddit.utils.integrations.IntegrationsPatch import app.revanced.util.ResourceUtils.editText +import app.revanced.util.ResourceUtils.valueOrThrow @Patch @Name("Settings for Reddit") @@ -19,20 +22,39 @@ import app.revanced.util.ResourceUtils.editText @RedditCompatibility @RequiresIntegrations class SettingsPatch : ResourcePatch { + companion object : OptionsContainer() { + private const val DEFAULT_NAME = "ReVanced Extended" + + private var RVXSettingsMenuName = option( + PatchOption.StringOption( + key = "RVXSettingsMenuName", + default = DEFAULT_NAME, + title = "RVX settings menu name", + description = "The name of the RVX settings menu.", + required = true + ) + ) + } + override fun execute(context: ResourceContext) { /** * Replace settings icon and label */ + val settingsLabel = RVXSettingsMenuName + .valueOrThrow() + arrayOf("preferences", "preferences_logged_in").forEach { targetXML -> fun Apk.transform() { resources.openFile("res/xml/$targetXML.xml").editText { it.replace( "\"@drawable/icon_text_post\" android:title=\"@string/label_acknowledgements\"", - "\"@drawable/icon_beta_planet\" android:title=\"ReVanced Extended\"" + "\"@drawable/icon_beta_planet\" android:title=\"$settingsLabel\"" ) } } context.apkBundle.all.forEach(Apk::transform) } + + SettingsBytecodePatch.updateSettingsLabel(settingsLabel) } }