mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-02 23:52:57 +01:00
fix(youtube/theme): apply custom seekbar color to video thumbnails (#2085)
This commit is contained in:
parent
1b76da8559
commit
d4970273ad
@ -16,11 +16,16 @@ import app.revanced.patches.shared.fingerprints.SeekbarOnDrawFingerprint
|
|||||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
||||||
import app.revanced.patches.youtube.layout.hide.seekbar.annotations.HideSeekbarCompatibility
|
import app.revanced.patches.youtube.layout.hide.seekbar.annotations.HideSeekbarCompatibility
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.patch.SeekbarColorBytecodePatch
|
||||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@DependsOn([IntegrationsPatch::class, SettingsPatch::class])
|
@DependsOn([
|
||||||
|
IntegrationsPatch::class,
|
||||||
|
SettingsPatch::class,
|
||||||
|
SeekbarColorBytecodePatch::class // Used to hide the seekbar in the feed and watch history
|
||||||
|
])
|
||||||
@Name("hide-seekbar")
|
@Name("hide-seekbar")
|
||||||
@Description("Hides the seekbar.")
|
@Description("Hides the seekbar.")
|
||||||
@HideSeekbarCompatibility
|
@HideSeekbarCompatibility
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.seekbar.annotations
|
||||||
|
|
||||||
|
import app.revanced.patcher.annotation.Compatibility
|
||||||
|
import app.revanced.patcher.annotation.Package
|
||||||
|
|
||||||
|
@Compatibility([Package("com.google.android.youtube")])
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
internal annotation class SeekbarColorCompatibility
|
@ -0,0 +1,15 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
|
||||||
|
import app.revanced.util.patch.indexOfFirstConstantInstruction
|
||||||
|
import org.jf.dexlib2.AccessFlags
|
||||||
|
|
||||||
|
object CreateDarkThemeSeekbarFingerprint : MethodFingerprint(
|
||||||
|
access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||||
|
customFingerprint = { method ->
|
||||||
|
method.indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) != -1
|
||||||
|
&& method.indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId) != -1
|
||||||
|
}
|
||||||
|
)
|
@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patches.youtube.layout.theme.bytecode.fingerprints
|
package app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
@ -0,0 +1,85 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.seekbar.bytecode.patch
|
||||||
|
|
||||||
|
import app.revanced.extensions.toErrorResult
|
||||||
|
import app.revanced.patcher.annotation.Description
|
||||||
|
import app.revanced.patcher.annotation.Version
|
||||||
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.data.toMethodWalker
|
||||||
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
|
import app.revanced.patcher.extensions.instruction
|
||||||
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.annotations.SeekbarColorCompatibility
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.SetSeekbarClickedColorFingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch
|
||||||
|
import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch.Companion.lithoColorOverrideHook
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
|
||||||
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||||
|
import app.revanced.util.patch.indexOfFirstConstantInstruction
|
||||||
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||||
|
|
||||||
|
@Description("Hide or set a custom seekbar color")
|
||||||
|
@DependsOn([IntegrationsPatch::class, LithoColorHookPatch::class, SeekbarColorResourcePatch::class])
|
||||||
|
@SeekbarColorCompatibility
|
||||||
|
@Version("0.0.1")
|
||||||
|
class SeekbarColorBytecodePatch : BytecodePatch(
|
||||||
|
listOf(CreateDarkThemeSeekbarFingerprint, SetSeekbarClickedColorFingerprint)
|
||||||
|
) {
|
||||||
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
CreateDarkThemeSeekbarFingerprint.result?.mutableMethod?.apply {
|
||||||
|
var registerIndex = indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) + 2
|
||||||
|
var colorRegister = (instruction(registerIndex) as OneRegisterInstruction).registerA
|
||||||
|
addInstructions(
|
||||||
|
registerIndex + 1,
|
||||||
|
"""
|
||||||
|
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue(I)I
|
||||||
|
move-result v$colorRegister
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
registerIndex = indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId) + 2
|
||||||
|
colorRegister = (instruction(registerIndex) as OneRegisterInstruction).registerA
|
||||||
|
addInstructions(
|
||||||
|
registerIndex + 1,
|
||||||
|
"""
|
||||||
|
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue(I)I
|
||||||
|
move-result v$colorRegister
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
} ?: return CreateDarkThemeSeekbarFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
SetSeekbarClickedColorFingerprint.result?.let { result ->
|
||||||
|
result.mutableMethod.let {
|
||||||
|
val setColorMethodIndex = result.scanResult.patternScanResult!!.startIndex + 1
|
||||||
|
val method = context
|
||||||
|
.toMethodWalker(it)
|
||||||
|
.nextMethod(setColorMethodIndex, true)
|
||||||
|
.getMethod() as MutableMethod
|
||||||
|
|
||||||
|
method.apply {
|
||||||
|
val colorRegister = (method.instruction(0) as TwoRegisterInstruction).registerA
|
||||||
|
addInstructions(
|
||||||
|
0,
|
||||||
|
"""
|
||||||
|
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorOverride(I)I
|
||||||
|
move-result v$colorRegister
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: return SetSeekbarClickedColorFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getSeekbarColorOverride")
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/SeekbarColorPatch;"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.seekbar.resource
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.ResourceContext
|
||||||
|
import app.revanced.patcher.patch.*
|
||||||
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
|
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
||||||
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
|
import org.w3c.dom.Element
|
||||||
|
|
||||||
|
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
|
||||||
|
class SeekbarColorResourcePatch : ResourcePatch {
|
||||||
|
override fun execute(context: ResourceContext): PatchResult {
|
||||||
|
// Edit theme colors via bytecode.
|
||||||
|
// For that the resource id is used in a bytecode patch to change the color.
|
||||||
|
|
||||||
|
val seekbarErrorMessage = "Could not find seekbar resource"
|
||||||
|
inlineTimeBarColorizedBarPlayedColorDarkId = ResourceMappingPatch.resourceMappings
|
||||||
|
.find { it.name == "inline_time_bar_colorized_bar_played_color_dark" }?.id
|
||||||
|
?: return PatchResultError(seekbarErrorMessage)
|
||||||
|
inlineTimeBarPlayedNotHighlightedColorId = ResourceMappingPatch.resourceMappings
|
||||||
|
.find { it.name == "inline_time_bar_played_not_highlighted_color" }?.id
|
||||||
|
?: return PatchResultError(seekbarErrorMessage)
|
||||||
|
|
||||||
|
// Edit the resume playback drawable and replace the progress bar with a custom drawable
|
||||||
|
context.xmlEditor["res/drawable/resume_playback_progressbar_drawable.xml"].use { editor ->
|
||||||
|
val layerList = editor.file.getElementsByTagName("layer-list").item(0) as Element
|
||||||
|
val progressNode = layerList.getElementsByTagName("item").item(1) as Element
|
||||||
|
if (!progressNode.getAttributeNode("android:id").value.endsWith("progress")) {
|
||||||
|
return PatchResultError("Could not find progress bar")
|
||||||
|
}
|
||||||
|
val scaleNode = progressNode.getElementsByTagName("scale").item(0) as Element
|
||||||
|
val shapeNode = scaleNode.getElementsByTagName("shape").item(0) as Element
|
||||||
|
val replacementNode = editor.file.createElement(
|
||||||
|
"app.revanced.integrations.patches.theme.ProgressBarDrawable")
|
||||||
|
scaleNode.replaceChild(replacementNode, shapeNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
internal var inlineTimeBarColorizedBarPlayedColorDarkId = -1L
|
||||||
|
internal var inlineTimeBarPlayedNotHighlightedColorId = -1L
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.layout.theme.bytecode.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint.indexOfInstructionWithSeekbarId
|
|
||||||
import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch
|
|
||||||
import org.jf.dexlib2.AccessFlags
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
import org.jf.dexlib2.iface.Method
|
|
||||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
|
||||||
|
|
||||||
object CreateDarkThemeSeekbarFingerprint : MethodFingerprint(
|
|
||||||
access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
|
||||||
customFingerprint = { method -> method.indexOfInstructionWithSeekbarId != -1 },
|
|
||||||
) {
|
|
||||||
/**
|
|
||||||
* The index of the instruction that loads the resource id of the seekbar.
|
|
||||||
*/
|
|
||||||
internal val Method.indexOfInstructionWithSeekbarId
|
|
||||||
get() = implementation?.let {
|
|
||||||
it.instructions.indexOfFirst { instruction ->
|
|
||||||
instruction.opcode == Opcode.CONST && (instruction as WideLiteralInstruction).wideLiteral == ThemeResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patches.youtube.layout.theme.fingerprints
|
package app.revanced.patches.youtube.layout.theme.bytecode.fingerprints
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
@ -0,0 +1,47 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.theme.bytecode.patch
|
||||||
|
|
||||||
|
import app.revanced.extensions.toErrorResult
|
||||||
|
import app.revanced.patcher.annotation.Description
|
||||||
|
import app.revanced.patcher.annotation.Name
|
||||||
|
import app.revanced.patcher.annotation.Version
|
||||||
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
|
import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility
|
||||||
|
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.LithoThemeFingerprint
|
||||||
|
|
||||||
|
@Name("litho-color-hook")
|
||||||
|
@Description("Adds a hook to set color of Litho components.")
|
||||||
|
@ThemeCompatibility
|
||||||
|
@Version("0.0.1")
|
||||||
|
class LithoColorHookPatch : BytecodePatch(listOf(LithoThemeFingerprint)) {
|
||||||
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
LithoThemeFingerprint.result?.let {
|
||||||
|
insertionIndex = it.scanResult.patternScanResult!!.endIndex - 1
|
||||||
|
colorRegister = "p1"
|
||||||
|
insertionMethod = it.mutableMethod
|
||||||
|
} ?: return LithoThemeFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
companion object {
|
||||||
|
private var insertionIndex : Int = -1
|
||||||
|
private lateinit var colorRegister : String
|
||||||
|
private lateinit var insertionMethod : MutableMethod
|
||||||
|
|
||||||
|
internal fun lithoColorOverrideHook(targetMethodClass: String, targetMethodName: String) {
|
||||||
|
insertionMethod.addInstructions(
|
||||||
|
insertionIndex,
|
||||||
|
"""
|
||||||
|
invoke-static {$colorRegister}, $targetMethodClass->$targetMethodName(I)I
|
||||||
|
move-result $colorRegister
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
insertionIndex += 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,76 +1,34 @@
|
|||||||
package app.revanced.patches.youtube.layout.theme.bytecode.patch
|
package app.revanced.patches.youtube.layout.theme.bytecode.patch
|
||||||
|
|
||||||
import app.revanced.extensions.toErrorResult
|
|
||||||
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.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.data.toMethodWalker
|
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
|
||||||
import app.revanced.patcher.extensions.instruction
|
|
||||||
import app.revanced.patcher.patch.*
|
import app.revanced.patcher.patch.*
|
||||||
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
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.patch.SeekbarColorBytecodePatch
|
||||||
import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint
|
||||||
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.SetSeekbarClickedColorFingerprint
|
||||||
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint.indexOfInstructionWithSeekbarId
|
|
||||||
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.SetSeekbarClickedColorFingerprint
|
|
||||||
import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch
|
import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch
|
||||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
|
||||||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("theme")
|
@Name("theme")
|
||||||
@Description("Applies a custom theme.")
|
@Description("Applies a custom theme.")
|
||||||
@DependsOn([ThemeLithoComponentsPatch::class, ThemeResourcePatch::class, IntegrationsPatch::class])
|
@DependsOn([LithoColorHookPatch::class, SeekbarColorBytecodePatch::class, ThemeResourcePatch::class])
|
||||||
@ThemeCompatibility
|
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class ThemeBytecodePatch : BytecodePatch(
|
class ThemeBytecodePatch : BytecodePatch(
|
||||||
listOf(CreateDarkThemeSeekbarFingerprint, SetSeekbarClickedColorFingerprint)
|
listOf(CreateDarkThemeSeekbarFingerprint, SetSeekbarClickedColorFingerprint)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
CreateDarkThemeSeekbarFingerprint.result?.let {
|
LithoColorHookPatch.lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getValue")
|
||||||
val putColorValueIndex = it.method.indexOfInstructionWithSeekbarId!! + 3
|
|
||||||
|
|
||||||
it.mutableMethod.apply {
|
|
||||||
val overrideRegister = instruction<TwoRegisterInstruction>(putColorValueIndex).registerA
|
|
||||||
|
|
||||||
addInstructions(
|
|
||||||
putColorValueIndex,
|
|
||||||
"""
|
|
||||||
invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue()I
|
|
||||||
move-result v$overrideRegister
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} ?: return CreateDarkThemeSeekbarFingerprint.toErrorResult()
|
|
||||||
|
|
||||||
SetSeekbarClickedColorFingerprint.result?.let { result ->
|
|
||||||
result.mutableMethod.let {
|
|
||||||
val setColorMethodIndex = result.scanResult.patternScanResult!!.startIndex + 1
|
|
||||||
val method = context
|
|
||||||
.toMethodWalker(it)
|
|
||||||
.nextMethod(setColorMethodIndex, true)
|
|
||||||
.getMethod() as MutableMethod
|
|
||||||
|
|
||||||
method.apply {
|
|
||||||
val colorRegister = method.instruction<TwoRegisterInstruction>(0).registerA
|
|
||||||
addInstructions(
|
|
||||||
0,
|
|
||||||
"""
|
|
||||||
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarClickedColorValue(I)I
|
|
||||||
move-result v$colorRegister
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} ?: return SetSeekbarClickedColorFingerprint.toErrorResult()
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : OptionsContainer() {
|
companion object : OptionsContainer() {
|
||||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemePatch;"
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemeLithoComponentsPatch;"
|
||||||
|
|
||||||
var darkThemeBackgroundColor: String? by option(
|
var darkThemeBackgroundColor: String? by option(
|
||||||
PatchOption.StringOption(
|
PatchOption.StringOption(
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.layout.theme.bytecode.patch
|
|
||||||
|
|
||||||
import app.revanced.extensions.toErrorResult
|
|
||||||
import app.revanced.patcher.annotation.Description
|
|
||||||
import app.revanced.patcher.annotation.Name
|
|
||||||
import app.revanced.patcher.annotation.Version
|
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
|
||||||
import app.revanced.patcher.patch.PatchResult
|
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
|
||||||
import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility
|
|
||||||
import app.revanced.patches.youtube.layout.theme.fingerprints.LithoThemeFingerprint
|
|
||||||
|
|
||||||
@Name("theme-litho-components")
|
|
||||||
@Description("Applies a custom theme to Litho components.")
|
|
||||||
@ThemeCompatibility
|
|
||||||
@Version("0.0.1")
|
|
||||||
class ThemeLithoComponentsPatch : BytecodePatch(listOf(LithoThemeFingerprint)) {
|
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
|
||||||
LithoThemeFingerprint.result?.let {
|
|
||||||
it.mutableMethod.apply {
|
|
||||||
val patchIndex = it.scanResult.patternScanResult!!.endIndex - 1
|
|
||||||
|
|
||||||
addInstructions(
|
|
||||||
patchIndex,
|
|
||||||
"""
|
|
||||||
invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->getValue(I)I
|
|
||||||
move-result p1
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} ?: return LithoThemeFingerprint.toErrorResult()
|
|
||||||
return PatchResultSuccess()
|
|
||||||
}
|
|
||||||
|
|
||||||
private companion object {
|
|
||||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemeLithoComponentsPatch;"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,7 @@
|
|||||||
package app.revanced.patches.youtube.layout.theme.resource
|
package app.revanced.patches.youtube.layout.theme.resource
|
||||||
|
|
||||||
import app.revanced.patcher.data.ResourceContext
|
import app.revanced.patcher.data.ResourceContext
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.*
|
||||||
import app.revanced.patcher.patch.PatchResultError
|
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
|
||||||
import app.revanced.patcher.patch.ResourcePatch
|
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
||||||
import app.revanced.patches.shared.settings.preference.impl.InputType
|
import app.revanced.patches.shared.settings.preference.impl.InputType
|
||||||
@ -28,19 +25,11 @@ class ThemeResourcePatch : ResourcePatch {
|
|||||||
"#FF0000",
|
"#FF0000",
|
||||||
StringResource(
|
StringResource(
|
||||||
"revanced_seekbar_color_summary",
|
"revanced_seekbar_color_summary",
|
||||||
"The color of the seekbar for the dark theme."
|
"The color of the seekbar"
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Edit theme colors via bytecode.
|
|
||||||
// For that the resource id is used in a bytecode patch to change the color.
|
|
||||||
|
|
||||||
inlineTimeBarColorizedBarPlayedColorDarkId = ResourceMappingPatch.resourceMappings
|
|
||||||
.find { it.name == "inline_time_bar_colorized_bar_played_color_dark" }?.id
|
|
||||||
?: return PatchResultError("Could not find seekbar resource")
|
|
||||||
|
|
||||||
|
|
||||||
val darkThemeBackgroundColor = darkThemeBackgroundColor!!
|
val darkThemeBackgroundColor = darkThemeBackgroundColor!!
|
||||||
val lightThemeBackgroundColor = lightThemeBackgroundColor!!
|
val lightThemeBackgroundColor = lightThemeBackgroundColor!!
|
||||||
|
|
||||||
@ -72,7 +61,4 @@ class ThemeResourcePatch : ResourcePatch {
|
|||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal companion object {
|
|
||||||
var inlineTimeBarColorizedBarPlayedColorDarkId = -1L
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
16
src/main/kotlin/app/revanced/util/patch/BytecodeUtils.kt
Normal file
16
src/main/kotlin/app/revanced/util/patch/BytecodeUtils.kt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package app.revanced.util.patch
|
||||||
|
|
||||||
|
import org.jf.dexlib2.Opcode
|
||||||
|
import org.jf.dexlib2.iface.Method
|
||||||
|
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the first constant instruction with the resource id, or -1 if not found.
|
||||||
|
*/
|
||||||
|
fun Method.indexOfFirstConstantInstruction(constantValue: Long): Int {
|
||||||
|
return implementation?.let {
|
||||||
|
it.instructions.indexOfFirst { instruction ->
|
||||||
|
instruction.opcode == Opcode.CONST && (instruction as WideLiteralInstruction).wideLiteral == constantValue
|
||||||
|
}
|
||||||
|
} ?: -1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user