mirror of
https://github.com/revanced/revanced-patches
synced 2024-11-10 14:49:27 +01:00
fix(YouTube - Theme): apply custom seekbar color to shorts (#2670)
This commit is contained in:
parent
5c39985888
commit
1f6fe3da42
@ -6,7 +6,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|||||||
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
|
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
|
|
||||||
object CreateDarkThemeSeekbarFingerprint : MethodFingerprint(
|
object PlayerSeekbarColorFingerprint : MethodFingerprint(
|
||||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||||
customFingerprint = { method, _ ->
|
customFingerprint = { method, _ ->
|
||||||
method.containsConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId)
|
method.containsConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId)
|
@ -0,0 +1,11 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
|
||||||
|
import app.revanced.util.patch.LiteralValueFingerprint
|
||||||
|
import org.jf.dexlib2.AccessFlags
|
||||||
|
|
||||||
|
object ShortsSeekbarColorFingerprint : LiteralValueFingerprint(
|
||||||
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||||
|
literal = SeekbarColorResourcePatch.reelTimeBarPlayedColorId,
|
||||||
|
)
|
@ -14,8 +14,9 @@ import app.revanced.patcher.patch.PatchResultSuccess
|
|||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import app.revanced.patches.youtube.layout.seekbar.annotations.SeekbarColorCompatibility
|
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.PlayerSeekbarColorFingerprint
|
||||||
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.SetSeekbarClickedColorFingerprint
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.SetSeekbarClickedColorFingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.ShortsSeekbarColorFingerprint
|
||||||
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
|
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
|
||||||
import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch
|
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.theme.bytecode.patch.LithoColorHookPatch.Companion.lithoColorOverrideHook
|
||||||
@ -28,12 +29,12 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
|||||||
@SeekbarColorCompatibility
|
@SeekbarColorCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class SeekbarColorBytecodePatch : BytecodePatch(
|
class SeekbarColorBytecodePatch : BytecodePatch(
|
||||||
listOf(CreateDarkThemeSeekbarFingerprint, SetSeekbarClickedColorFingerprint)
|
listOf(PlayerSeekbarColorFingerprint, ShortsSeekbarColorFingerprint, SetSeekbarClickedColorFingerprint)
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
CreateDarkThemeSeekbarFingerprint.result?.mutableMethod?.apply {
|
fun MutableMethod.addColorChangeInstructions(resourceId: Long) {
|
||||||
var registerIndex = indexOfFirstConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) + 2
|
var registerIndex = indexOfFirstConstantInstructionValue(resourceId) + 2
|
||||||
var colorRegister = (getInstruction(registerIndex) as OneRegisterInstruction).registerA
|
var colorRegister = getInstruction<OneRegisterInstruction>(registerIndex).registerA
|
||||||
addInstructions(
|
addInstructions(
|
||||||
registerIndex + 1,
|
registerIndex + 1,
|
||||||
"""
|
"""
|
||||||
@ -41,17 +42,16 @@ class SeekbarColorBytecodePatch : BytecodePatch(
|
|||||||
move-result v$colorRegister
|
move-result v$colorRegister
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
registerIndex = indexOfFirstConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId) + 2
|
PlayerSeekbarColorFingerprint.result?.mutableMethod?.apply {
|
||||||
colorRegister = (getInstruction(registerIndex) as OneRegisterInstruction).registerA
|
addColorChangeInstructions(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId)
|
||||||
addInstructions(
|
addColorChangeInstructions(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId)
|
||||||
registerIndex + 1,
|
} ?: return PlayerSeekbarColorFingerprint.toErrorResult()
|
||||||
"""
|
|
||||||
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I
|
ShortsSeekbarColorFingerprint.result?.mutableMethod?.apply {
|
||||||
move-result v$colorRegister
|
addColorChangeInstructions(SeekbarColorResourcePatch.reelTimeBarPlayedColorId)
|
||||||
"""
|
} ?: return ShortsSeekbarColorFingerprint.toErrorResult()
|
||||||
)
|
|
||||||
} ?: return CreateDarkThemeSeekbarFingerprint.toErrorResult()
|
|
||||||
|
|
||||||
SetSeekbarClickedColorFingerprint.result?.let { result ->
|
SetSeekbarClickedColorFingerprint.result?.let { result ->
|
||||||
result.mutableMethod.let {
|
result.mutableMethod.let {
|
||||||
@ -62,7 +62,7 @@ class SeekbarColorBytecodePatch : BytecodePatch(
|
|||||||
.getMethod() as MutableMethod
|
.getMethod() as MutableMethod
|
||||||
|
|
||||||
method.apply {
|
method.apply {
|
||||||
val colorRegister = (method.getInstruction(0) as TwoRegisterInstruction).registerA
|
val colorRegister = getInstruction<TwoRegisterInstruction>(0).registerA
|
||||||
addInstructions(
|
addInstructions(
|
||||||
0,
|
0,
|
||||||
"""
|
"""
|
||||||
|
@ -9,17 +9,20 @@ import org.w3c.dom.Element
|
|||||||
|
|
||||||
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
|
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
|
||||||
class SeekbarColorResourcePatch : ResourcePatch {
|
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"
|
override fun execute(context: ResourceContext): PatchResult {
|
||||||
inlineTimeBarColorizedBarPlayedColorDarkId = ResourceMappingPatch.resourceMappings
|
fun findColorResource(resourceName: String): Long {
|
||||||
.find { it.name == "inline_time_bar_colorized_bar_played_color_dark" }?.id
|
return ResourceMappingPatch.resourceMappings
|
||||||
?: return PatchResultError(seekbarErrorMessage)
|
.find { it.type == "color" && it.name == resourceName }?.id
|
||||||
inlineTimeBarPlayedNotHighlightedColorId = ResourceMappingPatch.resourceMappings
|
?: throw PatchResultError("Could not find color resource: $resourceName")
|
||||||
.find { it.name == "inline_time_bar_played_not_highlighted_color" }?.id
|
}
|
||||||
?: return PatchResultError(seekbarErrorMessage)
|
|
||||||
|
reelTimeBarPlayedColorId =
|
||||||
|
findColorResource("reel_time_bar_played_color")
|
||||||
|
inlineTimeBarColorizedBarPlayedColorDarkId =
|
||||||
|
findColorResource("inline_time_bar_colorized_bar_played_color_dark")
|
||||||
|
inlineTimeBarPlayedNotHighlightedColorId =
|
||||||
|
findColorResource("inline_time_bar_played_not_highlighted_color")
|
||||||
|
|
||||||
// Edit the resume playback drawable and replace the progress bar with a custom drawable
|
// 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 ->
|
context.xmlEditor["res/drawable/resume_playback_progressbar_drawable.xml"].use { editor ->
|
||||||
@ -39,6 +42,7 @@ class SeekbarColorResourcePatch : ResourcePatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
internal var reelTimeBarPlayedColorId = -1L
|
||||||
internal var inlineTimeBarColorizedBarPlayedColorDarkId = -1L
|
internal var inlineTimeBarColorizedBarPlayedColorDarkId = -1L
|
||||||
internal var inlineTimeBarPlayedNotHighlightedColorId = -1L
|
internal var inlineTimeBarPlayedNotHighlightedColorId = -1L
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user