mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
fix(settings): dark theme not applied in ReVanced settings https://github.com/inotia00/ReVanced_Extended/issues/690
This commit is contained in:
@ -9,7 +9,6 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableField
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.smali.toInstruction
|
||||
import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH
|
||||
import app.revanced.util.integrations.Constants.PATCHES_PATH
|
||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
||||
import org.jf.dexlib2.iface.Method
|
||||
@ -28,17 +27,6 @@ internal fun MutableMethodImplementation.injectHideCall(
|
||||
)
|
||||
}
|
||||
|
||||
internal fun MutableMethodImplementation.injectTheme(
|
||||
index: Int,
|
||||
register: Int,
|
||||
method: String
|
||||
) {
|
||||
this.addInstruction(
|
||||
index,
|
||||
"invoke-static { v$register }, $INTEGRATIONS_PATH/utils/ThemeHelper;->$method(I)V".toInstruction()
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: populate this to all patches
|
||||
/**
|
||||
* Convert a [MethodFingerprint] to a [PatchResultError].
|
||||
|
@ -1,12 +1,11 @@
|
||||
package app.revanced.patches.youtube.misc.settings.bytecode.patch
|
||||
|
||||
import app.revanced.extensions.findMutableMethodOf
|
||||
import app.revanced.extensions.injectTheme
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.addInstruction
|
||||
import app.revanced.patcher.extensions.replaceInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
@ -18,8 +17,6 @@ import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeSetterSystemFingerprint
|
||||
import app.revanced.util.bytecode.BytecodeHelper.injectInit
|
||||
import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
|
||||
|
||||
@Name("settings-bytecode-patch")
|
||||
@DependsOn(
|
||||
@ -34,61 +31,19 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction31i
|
||||
class SettingsBytecodePatch : BytecodePatch(
|
||||
listOf(ThemeSetterSystemFingerprint)
|
||||
) {
|
||||
|
||||
// list of resource names to get the id of
|
||||
private val resourceIds = arrayOf(
|
||||
"Theme.YouTube.Light",
|
||||
"Theme.YouTube.Light.DarkerPalette"
|
||||
).map { name ->
|
||||
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
|
||||
}
|
||||
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
context.classes.forEach { classDef ->
|
||||
classDef.methods.forEach { method ->
|
||||
with(method.implementation) {
|
||||
this?.instructions?.forEachIndexed { index, instruction ->
|
||||
when (instruction.opcode) {
|
||||
Opcode.CONST -> {
|
||||
when ((instruction as Instruction31i).wideLiteral) {
|
||||
resourceIds[0] -> { // primary theme
|
||||
val insertIndex = index - 3
|
||||
val invokeInstruction = instructions.elementAt(insertIndex)
|
||||
if (invokeInstruction.opcode != Opcode.IF_NE) return@forEachIndexed
|
||||
|
||||
val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method)
|
||||
|
||||
val viewRegister = (instructions.elementAt(index) as Instruction31i).registerA
|
||||
mutableMethod.implementation!!.injectTheme(mutableMethod.implementation!!.instructions.size - 1 , viewRegister, "setPrimaryTheme")
|
||||
}
|
||||
|
||||
resourceIds[1] -> { // secondary theme
|
||||
val insertIndex = index - 3
|
||||
val invokeInstruction = instructions.elementAt(insertIndex)
|
||||
if (invokeInstruction.opcode != Opcode.IF_NE) return@forEachIndexed
|
||||
|
||||
val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method)
|
||||
|
||||
val viewRegister = (instructions.elementAt(index) as Instruction31i).registerA
|
||||
mutableMethod.implementation!!.injectTheme(index + 2, viewRegister, "setSecondaryTheme")
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> return@forEachIndexed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// apply the current theme of the settings page
|
||||
ThemeSetterSystemFingerprint.result?.let {
|
||||
with(it.mutableMethod) {
|
||||
addInstruction(
|
||||
it.scanResult.patternScanResult!!.startIndex,
|
||||
val targetIndex = it.scanResult.patternScanResult!!.startIndex
|
||||
replaceInstruction(
|
||||
targetIndex,
|
||||
SET_THEME
|
||||
)
|
||||
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"return-object v0"
|
||||
)
|
||||
addInstruction(
|
||||
this.implementation!!.instructions.size - 1,
|
||||
SET_THEME
|
||||
|
Reference in New Issue
Block a user