mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-04-29 22:24:31 +02:00
feat(Reddit/Settings): add patch option RVX settings menu name
This commit is contained in:
parent
b4c4b26f7a
commit
bb2bf73d23
@ -15,6 +15,7 @@ import app.revanced.patches.shared.settings.fingerprints.SharedSettingFingerprin
|
|||||||
import app.revanced.util.getInstruction
|
import app.revanced.util.getInstruction
|
||||||
import app.revanced.util.getTargetIndexOrThrow
|
import app.revanced.util.getTargetIndexOrThrow
|
||||||
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
|
import app.revanced.util.getTargetIndexWithMethodReferenceNameOrThrow
|
||||||
|
import app.revanced.util.getWideLiteralInstructionIndex
|
||||||
import app.revanced.util.resultOrThrow
|
import app.revanced.util.resultOrThrow
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
||||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
@ -32,16 +33,31 @@ class SettingsBytecodePatch : BytecodePatch(
|
|||||||
private const val INTEGRATIONS_METHOD_DESCRIPTOR =
|
private const val INTEGRATIONS_METHOD_DESCRIPTOR =
|
||||||
"$INTEGRATIONS_PATH/settings/ActivityHook;->initialize(Landroid/app/Activity;)V"
|
"$INTEGRATIONS_PATH/settings/ActivityHook;->initialize(Landroid/app/Activity;)V"
|
||||||
|
|
||||||
|
private lateinit var acknowledgementsLabelBuilderMethod: MutableMethod
|
||||||
private lateinit var settingsStatusLoadMethod: 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<OneRegisterInstruction>(insertIndex - 1).registerA
|
||||||
|
|
||||||
|
addInstruction(
|
||||||
|
insertIndex,
|
||||||
|
"const-string v$insertRegister, \"$label\""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun updateSettingsStatus(description: String) =
|
||||||
settingsStatusLoadMethod.addInstruction(
|
settingsStatusLoadMethod.addInstruction(
|
||||||
0,
|
0,
|
||||||
"invoke-static {}, $INTEGRATIONS_PATH/settings/SettingsStatus;->$description()V"
|
"invoke-static {}, $INTEGRATIONS_PATH/settings/SettingsStatus;->$description()V"
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lateinit var contexts: BytecodeContext
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,19 +78,9 @@ class SettingsBytecodePatch : BytecodePatch(
|
|||||||
/**
|
/**
|
||||||
* Replace settings label
|
* Replace settings label
|
||||||
*/
|
*/
|
||||||
AcknowledgementsLabelBuilderFingerprint.resultOrThrow().let {
|
acknowledgementsLabelBuilderMethod = AcknowledgementsLabelBuilderFingerprint
|
||||||
it.mutableMethod.apply {
|
.resultOrThrow()
|
||||||
val insertIndex =
|
.mutableMethod
|
||||||
getTargetIndexWithMethodReferenceNameOrThrow("getString") + 2
|
|
||||||
val insertRegister =
|
|
||||||
getInstruction<OneRegisterInstruction>(insertIndex - 1).registerA
|
|
||||||
|
|
||||||
addInstruction(
|
|
||||||
insertIndex,
|
|
||||||
"const-string v$insertRegister, \"ReVanced Extended\""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize settings activity
|
* Initialize settings activity
|
||||||
|
@ -4,6 +4,8 @@ import app.revanced.patcher.ResourceContext
|
|||||||
import app.revanced.patcher.annotation.Description
|
import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.apk.Apk
|
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.ResourcePatch
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
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.annotation.RedditCompatibility
|
||||||
import app.revanced.patches.reddit.utils.integrations.IntegrationsPatch
|
import app.revanced.patches.reddit.utils.integrations.IntegrationsPatch
|
||||||
import app.revanced.util.ResourceUtils.editText
|
import app.revanced.util.ResourceUtils.editText
|
||||||
|
import app.revanced.util.ResourceUtils.valueOrThrow
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("Settings for Reddit")
|
@Name("Settings for Reddit")
|
||||||
@ -19,20 +22,39 @@ import app.revanced.util.ResourceUtils.editText
|
|||||||
@RedditCompatibility
|
@RedditCompatibility
|
||||||
@RequiresIntegrations
|
@RequiresIntegrations
|
||||||
class SettingsPatch : ResourcePatch {
|
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) {
|
override fun execute(context: ResourceContext) {
|
||||||
/**
|
/**
|
||||||
* Replace settings icon and label
|
* Replace settings icon and label
|
||||||
*/
|
*/
|
||||||
|
val settingsLabel = RVXSettingsMenuName
|
||||||
|
.valueOrThrow()
|
||||||
|
|
||||||
arrayOf("preferences", "preferences_logged_in").forEach { targetXML ->
|
arrayOf("preferences", "preferences_logged_in").forEach { targetXML ->
|
||||||
fun Apk.transform() {
|
fun Apk.transform() {
|
||||||
resources.openFile("res/xml/$targetXML.xml").editText {
|
resources.openFile("res/xml/$targetXML.xml").editText {
|
||||||
it.replace(
|
it.replace(
|
||||||
"\"@drawable/icon_text_post\" android:title=\"@string/label_acknowledgements\"",
|
"\"@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)
|
context.apkBundle.all.forEach(Apk::transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsBytecodePatch.updateSettingsLabel(settingsLabel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user