feat(youtube/custom-seekbar-color): change the color of the last watched progress bar https://github.com/inotia00/ReVanced_Extended/issues/748

This commit is contained in:
inotia00 2023-05-06 01:43:25 +09:00
parent 6c742b4e99
commit ae49cd421a
13 changed files with 169 additions and 81 deletions

View File

@ -119,5 +119,17 @@ class PatchOptions : ResourcePatch {
description = "The background color of the dark theme. Can be a hex color or a resource reference." description = "The background color of the dark theme. Can be a hex color or a resource reference."
) )
) )
/**
* Resumed progressbar color in playlists and history
*/
internal var resumedProgressBarColor: String? by option(
PatchOption.StringOption(
key = "resumedProgressBarColor",
default = "#ffff0000",
title = "Resumed progressbar color",
description = "Resumed progressbar color in playlists and history. Can be a hex color or a resource reference."
)
)
} }
} }

View File

@ -10,8 +10,8 @@ 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
import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.etc.theme.bytecode.patch.GeneralThemeBytecodePatch.Companion.isMonetPatchIncluded import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch
import app.revanced.patches.youtube.layout.etc.theme.resource.patch.GeneralThemePatch import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch.Companion.isMonetPatchIncluded
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme
import app.revanced.util.resources.ResourceUtils.copyXmlNode import app.revanced.util.resources.ResourceUtils.copyXmlNode

View File

@ -1,45 +0,0 @@
package app.revanced.patches.youtube.layout.etc.theme.bytecode.patch
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.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.etc.theme.bytecode.fingerprints.LithoThemeFingerprint
import app.revanced.util.integrations.Constants.UTILS_PATH
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
@Name("general-theme")
@YouTubeCompatibility
@Version("0.0.1")
class GeneralThemeBytecodePatch : BytecodePatch(
listOf(
LithoThemeFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LithoThemeFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.endIndex - 1
val register = (implementation!!.instructions[insertIndex] as Instruction35c).registerD
addInstructions(
insertIndex, """
invoke-static { v$register }, $UTILS_PATH/LithoThemePatch;->applyLithoTheme(I)I
move-result v$register
"""
)
}
} ?: return LithoThemeFingerprint.toErrorResult()
return PatchResultSuccess()
}
internal companion object {
var isMonetPatchIncluded: Boolean = false
}
}

View File

@ -1,21 +1,24 @@
package app.revanced.patches.youtube.layout.etc.theme.resource.patch package app.revanced.patches.youtube.layout.etc.theme.patch
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.ResourceContext import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patches.youtube.layout.etc.theme.bytecode.patch.GeneralThemeBytecodePatch import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.youtube.misc.litho.patch.LithoThemePatch
import app.revanced.util.integrations.Constants
import org.w3c.dom.Element import org.w3c.dom.Element
@Name("general-theme-resource-patch") @Name("general-theme-patch")
@DependsOn([GeneralThemeBytecodePatch::class]) @DependsOn([LithoThemePatch::class])
@Version("0.0.1") @Version("0.0.1")
class GeneralThemePatch : ResourcePatch { class GeneralThemePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult { override fun execute(context: ResourceContext): PatchResult {
LithoThemePatch.injectCall("${Constants.UTILS_PATH}/LithoThemePatch;->applyLithoTheme(I)I")
// edit the resource files to change the splash screen color // edit the resource files to change the splash screen color
val attrsPath = "res/values/attrs.xml" val attrsPath = "res/values/attrs.xml"
val stylesPaths: List<String> = listOf( val stylesPaths: List<String> = listOf(
@ -88,4 +91,7 @@ class GeneralThemePatch : ResourcePatch {
return PatchResultSuccess() return PatchResultSuccess()
} }
internal companion object {
var isMonetPatchIncluded: Boolean = false
}
} }

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.etc.theme.resource.patch package app.revanced.patches.youtube.layout.etc.theme.patch
import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
@ -11,7 +11,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.patch.options.PatchOptions import app.revanced.patches.shared.patch.options.PatchOptions
import app.revanced.patches.youtube.layout.etc.theme.bytecode.patch.GeneralThemeBytecodePatch.Companion.isMonetPatchIncluded import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch.Companion.isMonetPatchIncluded
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme
import org.w3c.dom.Element import org.w3c.dom.Element

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.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

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.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

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch

View File

@ -1,7 +1,6 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.patch package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.patch
import app.revanced.extensions.toErrorResult import app.revanced.extensions.toErrorResult
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
@ -12,29 +11,26 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint
import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints.* import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints.*
import app.revanced.patches.youtube.misc.litho.patch.LithoThemePatch
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH
import app.revanced.util.integrations.Constants.SEEKBAR import app.revanced.util.integrations.Constants.SEEKBAR
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
@Patch @Name("custom-seekbar-color-bytecode-patch")
@Name("custom-seekbar-color")
@Description("Change seekbar color.")
@DependsOn( @DependsOn(
[ [
SettingsPatch::class, LithoThemePatch::class,
SharedResourceIdPatch::class SharedResourceIdPatch::class
] ]
) )
@YouTubeCompatibility @YouTubeCompatibility
@Version("0.0.1") @Version("0.0.1")
class SeekbarColorPatch : BytecodePatch( class SeekbarColorBytecodePatch : BytecodePatch(
listOf( listOf(
ControlsOverlayParentFingerprint, ControlsOverlayParentFingerprint,
ControlsOverlayStyleFingerprint, ControlsOverlayStyleFingerprint,
@ -75,17 +71,7 @@ class SeekbarColorPatch : BytecodePatch(
) ?: return ControlsOverlayFingerprint.toErrorResult() ) ?: return ControlsOverlayFingerprint.toErrorResult()
} ?: return ControlsOverlayParentFingerprint.toErrorResult() } ?: return ControlsOverlayParentFingerprint.toErrorResult()
/* LithoThemePatch.injectCall("$SEEKBAR->resumedProgressBarColor(I)I")
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: SEEKBAR_SETTINGS",
"SETTINGS: CUSTOM_SEEKBAR_COLOR"
)
)
SettingsPatch.updatePatchStatus("custom-seekbar-color")
return PatchResultSuccess() return PatchResultSuccess()
} }

View File

@ -0,0 +1,64 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.resource.patch
import app.revanced.extensions.doRecursively
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
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.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.patch.options.PatchOptions
import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.patch.SeekbarColorBytecodePatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import org.w3c.dom.Element
@Patch
@Name("custom-seekbar-color")
@Description("Change seekbar color and progressbar color.")
@DependsOn(
[
PatchOptions::class,
SeekbarColorBytecodePatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class ThemePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
context.xmlEditor[RESOURCE_FILE_PATH].use {
it.file.doRecursively {
arrayOf("color").forEach replacement@{ replacement ->
if (it !is Element) return@replacement
it.getAttributeNode("android:$replacement")?.let { attribute ->
if (attribute.textContent.startsWith("@color/"))
attribute.textContent = PatchOptions.resumedProgressBarColor!!
}
}
}
}
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: SEEKBAR_SETTINGS",
"SETTINGS: CUSTOM_SEEKBAR_COLOR"
)
)
SettingsPatch.updatePatchStatus("custom-seekbar-color")
return PatchResultSuccess()
}
private companion object {
const val RESOURCE_FILE_PATH = "res/drawable/resume_playback_progressbar_drawable.xml"
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.etc.theme.bytecode.fingerprints package app.revanced.patches.youtube.misc.litho.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
@ -12,7 +12,7 @@ object LithoThemeFingerprint : MethodFingerprint(
opcodes = listOf( opcodes = listOf(
Opcode.IF_NEZ, Opcode.IF_NEZ,
Opcode.IGET_OBJECT, Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL, Opcode.INVOKE_VIRTUAL, // Paint.setColor: inject point
Opcode.RETURN_VOID Opcode.RETURN_VOID
), ),
customFingerprint = { it.name == "onBoundsChange" } customFingerprint = { it.name == "onBoundsChange" }

View File

@ -0,0 +1,65 @@
package app.revanced.patches.youtube.misc.litho.patch
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.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.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.litho.fingerprints.LithoThemeFingerprint
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.iface.reference.MethodReference
@Name("litho-theme-hook")
@YouTubeCompatibility
@Version("0.0.1")
class LithoThemePatch : BytecodePatch(
listOf(
LithoThemeFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LithoThemeFingerprint.result?.mutableMethod?.let {
with (it.implementation!!.instructions) {
for (index in size - 1 downTo 0) {
val invokeInstruction = this[index] as? ReferenceInstruction ?: continue
if ((invokeInstruction.reference as MethodReference).name != "setColor") continue
insertIndex = index
insertRegister = (this[index] as Instruction35c).registerD
insertMethod = it
break
}
}
} ?: return LithoThemeFingerprint.toErrorResult()
return PatchResultSuccess()
}
companion object {
private var offset = 0
private var insertIndex: Int = 0
private var insertRegister: Int = 0
private lateinit var insertMethod: MutableMethod
fun injectCall(
methodDescriptor: String
) {
insertMethod.addInstructions(
insertIndex + offset, """
invoke-static {v$insertRegister}, $methodDescriptor
move-result v$insertRegister
"""
)
offset += 2
}
}
}