mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-03 08:04:36 +02:00
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:
parent
6c742b4e99
commit
ae49cd421a
@ -119,5 +119,17 @@ class PatchOptions : ResourcePatch {
|
||||
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."
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ 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.youtube.layout.etc.theme.bytecode.patch.GeneralThemeBytecodePatch.Companion.isMonetPatchIncluded
|
||||
import app.revanced.patches.youtube.layout.etc.theme.resource.patch.GeneralThemePatch
|
||||
import app.revanced.patches.youtube.layout.etc.theme.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.util.resources.ResourceHelper.updatePatchStatusTheme
|
||||
import app.revanced.util.resources.ResourceUtils.copyXmlNode
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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.Version
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
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
|
||||
|
||||
@Name("general-theme-resource-patch")
|
||||
@DependsOn([GeneralThemeBytecodePatch::class])
|
||||
@Name("general-theme-patch")
|
||||
@DependsOn([LithoThemePatch::class])
|
||||
@Version("0.0.1")
|
||||
class GeneralThemePatch : ResourcePatch {
|
||||
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
|
||||
val attrsPath = "res/values/attrs.xml"
|
||||
val stylesPaths: List<String> = listOf(
|
||||
@ -88,4 +91,7 @@ class GeneralThemePatch : ResourcePatch {
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
internal companion object {
|
||||
var isMonetPatchIncluded: Boolean = false
|
||||
}
|
||||
}
|
@ -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.Name
|
||||
@ -11,7 +11,7 @@ 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.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.util.resources.ResourceHelper.updatePatchStatusTheme
|
||||
import org.w3c.dom.Element
|
@ -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
|
||||
|
@ -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.fingerprint.method.impl.MethodFingerprint
|
@ -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 org.jf.dexlib2.Opcode
|
@ -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.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
|
@ -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.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
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.PatchResultSuccess
|
||||
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.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.settings.resource.patch.SettingsPatch
|
||||
import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH
|
||||
import app.revanced.util.integrations.Constants.SEEKBAR
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
|
||||
@Patch
|
||||
@Name("custom-seekbar-color")
|
||||
@Description("Change seekbar color.")
|
||||
@Name("custom-seekbar-color-bytecode-patch")
|
||||
@DependsOn(
|
||||
[
|
||||
SettingsPatch::class,
|
||||
LithoThemePatch::class,
|
||||
SharedResourceIdPatch::class
|
||||
]
|
||||
)
|
||||
@YouTubeCompatibility
|
||||
@Version("0.0.1")
|
||||
class SeekbarColorPatch : BytecodePatch(
|
||||
class SeekbarColorBytecodePatch : BytecodePatch(
|
||||
listOf(
|
||||
ControlsOverlayParentFingerprint,
|
||||
ControlsOverlayStyleFingerprint,
|
||||
@ -75,17 +71,7 @@ class SeekbarColorPatch : BytecodePatch(
|
||||
) ?: return ControlsOverlayFingerprint.toErrorResult()
|
||||
} ?: return ControlsOverlayParentFingerprint.toErrorResult()
|
||||
|
||||
/*
|
||||
* Add settings
|
||||
*/
|
||||
SettingsPatch.addPreference(
|
||||
arrayOf(
|
||||
"PREFERENCE: SEEKBAR_SETTINGS",
|
||||
"SETTINGS: CUSTOM_SEEKBAR_COLOR"
|
||||
)
|
||||
)
|
||||
|
||||
SettingsPatch.updatePatchStatus("custom-seekbar-color")
|
||||
LithoThemePatch.injectCall("$SEEKBAR->resumedProgressBarColor(I)I")
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
@ -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.fingerprint.method.impl.MethodFingerprint
|
||||
@ -12,7 +12,7 @@ object LithoThemeFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.IF_NEZ,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.INVOKE_VIRTUAL, // Paint.setColor: inject point
|
||||
Opcode.RETURN_VOID
|
||||
),
|
||||
customFingerprint = { it.name == "onBoundsChange" }
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user