From 1f6fe3da4284fd768057ef068c7ddf88d3a11049 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 20 Jul 2023 21:28:22 +0400 Subject: [PATCH] fix(YouTube - Theme): apply custom seekbar color to shorts (#2670) --- ...nt.kt => PlayerSeekbarColorFingerprint.kt} | 2 +- .../ShortsSeekbarColorFingerprint.kt | 11 +++++ .../patch/SeekbarColorBytecodePatch.kt | 40 +++++++++---------- .../resource/SeekbarColorResourcePatch.kt | 24 ++++++----- 4 files changed, 46 insertions(+), 31 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/{CreateDarkThemeSeekbarFingerprint.kt => PlayerSeekbarColorFingerprint.kt} (92%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/ShortsSeekbarColorFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/PlayerSeekbarColorFingerprint.kt similarity index 92% rename from src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/PlayerSeekbarColorFingerprint.kt index 9c8b32ffe..0c325dd86 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/PlayerSeekbarColorFingerprint.kt @@ -6,7 +6,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch import org.jf.dexlib2.AccessFlags -object CreateDarkThemeSeekbarFingerprint : MethodFingerprint( +object PlayerSeekbarColorFingerprint : MethodFingerprint( accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, customFingerprint = { method, _ -> method.containsConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/ShortsSeekbarColorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/ShortsSeekbarColorFingerprint.kt new file mode 100644 index 000000000..eea70852a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/ShortsSeekbarColorFingerprint.kt @@ -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, +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt index ad5773576..6735d097d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt @@ -14,8 +14,9 @@ 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.PlayerSeekbarColorFingerprint 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.theme.bytecode.patch.LithoColorHookPatch import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch.Companion.lithoColorOverrideHook @@ -28,30 +29,29 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @SeekbarColorCompatibility @Version("0.0.1") class SeekbarColorBytecodePatch : BytecodePatch( - listOf(CreateDarkThemeSeekbarFingerprint, SetSeekbarClickedColorFingerprint) + listOf(PlayerSeekbarColorFingerprint, ShortsSeekbarColorFingerprint, SetSeekbarClickedColorFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - CreateDarkThemeSeekbarFingerprint.result?.mutableMethod?.apply { - var registerIndex = indexOfFirstConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) + 2 - var colorRegister = (getInstruction(registerIndex) as OneRegisterInstruction).registerA + fun MutableMethod.addColorChangeInstructions(resourceId: Long) { + var registerIndex = indexOfFirstConstantInstructionValue(resourceId) + 2 + var colorRegister = getInstruction(registerIndex).registerA addInstructions( registerIndex + 1, """ - invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I - move-result v$colorRegister - """ + invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I + move-result v$colorRegister + """ ) - - registerIndex = indexOfFirstConstantInstructionValue(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId) + 2 - colorRegister = (getInstruction(registerIndex) as OneRegisterInstruction).registerA - addInstructions( - registerIndex + 1, - """ - invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I - move-result v$colorRegister - """ - ) - } ?: return CreateDarkThemeSeekbarFingerprint.toErrorResult() + } + + PlayerSeekbarColorFingerprint.result?.mutableMethod?.apply { + addColorChangeInstructions(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) + addColorChangeInstructions(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId) + } ?: return PlayerSeekbarColorFingerprint.toErrorResult() + + ShortsSeekbarColorFingerprint.result?.mutableMethod?.apply { + addColorChangeInstructions(SeekbarColorResourcePatch.reelTimeBarPlayedColorId) + } ?: return ShortsSeekbarColorFingerprint.toErrorResult() SetSeekbarClickedColorFingerprint.result?.let { result -> result.mutableMethod.let { @@ -62,7 +62,7 @@ class SeekbarColorBytecodePatch : BytecodePatch( .getMethod() as MutableMethod method.apply { - val colorRegister = (method.getInstruction(0) as TwoRegisterInstruction).registerA + val colorRegister = getInstruction(0).registerA addInstructions( 0, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarColorResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarColorResourcePatch.kt index a6bc89a84..c12016565 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarColorResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarColorResourcePatch.kt @@ -9,17 +9,20 @@ 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) + override fun execute(context: ResourceContext): PatchResult { + fun findColorResource(resourceName: String): Long { + return ResourceMappingPatch.resourceMappings + .find { it.type == "color" && it.name == resourceName }?.id + ?: throw PatchResultError("Could not find color resource: $resourceName") + } + + 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 context.xmlEditor["res/drawable/resume_playback_progressbar_drawable.xml"].use { editor -> @@ -39,6 +42,7 @@ class SeekbarColorResourcePatch : ResourcePatch { } companion object { + internal var reelTimeBarPlayedColorId = -1L internal var inlineTimeBarColorizedBarPlayedColorDarkId = -1L internal var inlineTimeBarPlayedNotHighlightedColorId = -1L }