mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 13:17:46 +02:00
feat(YouTube - Seekbar components): Add option to use custom seekbar accent color (Close https://github.com/inotia00/ReVanced_Extended/issues/2738)
This commit is contained in:
@ -1,12 +1,30 @@
|
||||
package app.revanced.patches.youtube.player.seekbar
|
||||
|
||||
import app.revanced.patches.youtube.utils.resourceid.reelTimeBarPlayedColor
|
||||
import app.revanced.patches.youtube.utils.resourceid.ytStaticBrandRed
|
||||
import app.revanced.patches.youtube.utils.resourceid.ytYoutubeMagenta
|
||||
import app.revanced.util.containsLiteralInstruction
|
||||
import app.revanced.util.fingerprint.legacyFingerprint
|
||||
import app.revanced.util.or
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import kotlin.collections.listOf
|
||||
|
||||
internal val shortsSeekbarColorFingerprint = legacyFingerprint(
|
||||
name = "shortsSeekbarColorFingerprint",
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||
literals = listOf(reelTimeBarPlayedColor),
|
||||
)
|
||||
|
||||
internal val controlsOverlayStyleFingerprint = legacyFingerprint(
|
||||
name = "controlsOverlayStyleFingerprint",
|
||||
opcodes = listOf(Opcode.CONST_HIGH16),
|
||||
strings = listOf("YOUTUBE", "PREROLL", "POSTROLL"),
|
||||
customFingerprint = { method, _ ->
|
||||
method.definingClass.endsWith("/ControlsOverlayStyle;")
|
||||
}
|
||||
)
|
||||
|
||||
internal const val PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG = 45617850L
|
||||
|
||||
@ -17,6 +35,21 @@ internal val playerSeekbarGradientConfigFingerprint = legacyFingerprint(
|
||||
literals = listOf(PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG),
|
||||
)
|
||||
|
||||
internal val playerSeekbarHandleColorFingerprint = legacyFingerprint(
|
||||
name = "playerSeekbarHandleColorFingerprint",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||
parameters = listOf("Landroid/content/Context;"),
|
||||
literals = listOf(ytStaticBrandRed),
|
||||
)
|
||||
|
||||
internal val watchHistoryMenuUseProgressDrawableFingerprint = legacyFingerprint(
|
||||
name = "watchHistoryMenuUseProgressDrawableFingerprint",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
returnType = "V",
|
||||
parameters = listOf("L"),
|
||||
literals = listOf(-1712394514),
|
||||
)
|
||||
|
||||
internal val lithoLinearGradientFingerprint = legacyFingerprint(
|
||||
name = "lithoLinearGradientFingerprint",
|
||||
accessFlags = AccessFlags.STATIC.value,
|
||||
@ -25,11 +58,13 @@ internal val lithoLinearGradientFingerprint = legacyFingerprint(
|
||||
)
|
||||
|
||||
/**
|
||||
* YouTube 19.25 - 19.47
|
||||
* YouTube 19.49+
|
||||
*/
|
||||
internal val playerLinearGradientLegacyFingerprint = legacyFingerprint(
|
||||
name = "playerLinearGradientLegacyFingerprint",
|
||||
returnType = "V",
|
||||
internal val playerLinearGradientFingerprint = legacyFingerprint(
|
||||
name = "playerLinearGradientFingerprint",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
parameters = listOf("I", "I", "I", "I", "Landroid/content/Context;", "I"),
|
||||
returnType = "Landroid/graphics/LinearGradient;",
|
||||
opcodes = listOf(
|
||||
Opcode.FILLED_NEW_ARRAY,
|
||||
Opcode.MOVE_RESULT_OBJECT
|
||||
@ -38,13 +73,11 @@ internal val playerLinearGradientLegacyFingerprint = legacyFingerprint(
|
||||
)
|
||||
|
||||
/**
|
||||
* YouTube 19.49+
|
||||
* YouTube 19.25 - 19.47
|
||||
*/
|
||||
internal val playerLinearGradientFingerprint = legacyFingerprint(
|
||||
name = "playerLinearGradientFingerprint",
|
||||
returnType = "Landroid/graphics/LinearGradient;",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
parameters = listOf("I", "I", "I", "I", "Landroid/content/Context;", "I"),
|
||||
internal val playerLinearGradientLegacyFingerprint = legacyFingerprint(
|
||||
name = "playerLinearGradientLegacyFingerprint",
|
||||
returnType = "V",
|
||||
opcodes = listOf(
|
||||
Opcode.FILLED_NEW_ARRAY,
|
||||
Opcode.MOVE_RESULT_OBJECT
|
||||
@ -67,15 +100,6 @@ internal val launchScreenLayoutTypeFingerprint = legacyFingerprint(
|
||||
}
|
||||
)
|
||||
|
||||
internal val controlsOverlayStyleFingerprint = legacyFingerprint(
|
||||
name = "controlsOverlayStyleFingerprint",
|
||||
opcodes = listOf(Opcode.CONST_HIGH16),
|
||||
strings = listOf("YOUTUBE", "PREROLL", "POSTROLL"),
|
||||
customFingerprint = { method, _ ->
|
||||
method.definingClass.endsWith("/ControlsOverlayStyle;")
|
||||
}
|
||||
)
|
||||
|
||||
internal val seekbarTappingFingerprint = legacyFingerprint(
|
||||
name = "seekbarTappingFingerprint",
|
||||
returnType = "Z",
|
||||
@ -108,13 +132,6 @@ internal val seekbarThumbnailsQualityFingerprint = legacyFingerprint(
|
||||
literals = listOf(45399684L),
|
||||
)
|
||||
|
||||
internal val shortsSeekbarColorFingerprint = legacyFingerprint(
|
||||
name = "shortsSeekbarColorFingerprint",
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||
literals = listOf(reelTimeBarPlayedColor),
|
||||
)
|
||||
|
||||
internal val thumbnailPreviewConfigFingerprint = legacyFingerprint(
|
||||
name = "thumbnailPreviewConfigFingerprint",
|
||||
returnType = "Z",
|
||||
|
@ -24,6 +24,7 @@ import app.revanced.patches.youtube.utils.playerButtonsResourcesFingerprint
|
||||
import app.revanced.patches.youtube.utils.playerButtonsVisibilityFingerprint
|
||||
import app.revanced.patches.youtube.utils.playerSeekbarColorFingerprint
|
||||
import app.revanced.patches.youtube.utils.playservice.is_19_25_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_19_34_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_19_46_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_19_49_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
|
||||
@ -31,6 +32,7 @@ import app.revanced.patches.youtube.utils.resourceid.inlineTimeBarColorizedBarPl
|
||||
import app.revanced.patches.youtube.utils.resourceid.inlineTimeBarPlayedNotHighlightedColor
|
||||
import app.revanced.patches.youtube.utils.resourceid.reelTimeBarPlayedColor
|
||||
import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.utils.resourceid.ytStaticBrandRed
|
||||
import app.revanced.patches.youtube.utils.seekbarFingerprint
|
||||
import app.revanced.patches.youtube.utils.seekbarOnDrawFingerprint
|
||||
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
|
||||
@ -215,14 +217,18 @@ val seekbarComponentsPatch = bytecodePatch(
|
||||
|
||||
// region patch for seekbar color
|
||||
|
||||
fun MutableMethod.addColorChangeInstructions(literal: Long) {
|
||||
val insertIndex = indexOfFirstLiteralInstructionOrThrow(literal) + 2
|
||||
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
|
||||
fun MutableMethod.addColorChangeInstructions(
|
||||
literal: Long,
|
||||
methodName: String = "getVideoPlayerSeekbarColor"
|
||||
) {
|
||||
val index = indexOfFirstLiteralInstructionOrThrow(literal) + 2
|
||||
val insertIndex = indexOfFirstInstructionOrThrow(index, Opcode.MOVE_RESULT)
|
||||
val register = getInstruction<OneRegisterInstruction>(insertIndex).registerA
|
||||
|
||||
addInstructions(
|
||||
insertIndex + 1, """
|
||||
invoke-static {v$insertRegister}, $EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I
|
||||
move-result v$insertRegister
|
||||
invoke-static {v$register}, $EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->$methodName(I)I
|
||||
move-result v$register
|
||||
"""
|
||||
)
|
||||
}
|
||||
@ -254,34 +260,67 @@ val seekbarComponentsPatch = bytecodePatch(
|
||||
addDrawableColorHook("$EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->getLithoColor(I)I")
|
||||
|
||||
if (is_19_25_or_greater) {
|
||||
lithoLinearGradientFingerprint.methodOrThrow().addInstruction(
|
||||
0,
|
||||
"invoke-static/range { p4 .. p5 }, $EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->setLinearGradient([I[F)V"
|
||||
playerSeekbarGradientConfigFingerprint.injectLiteralInstructionBooleanCall(
|
||||
PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG,
|
||||
"$EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->playerSeekbarGradientEnabled(Z)Z"
|
||||
)
|
||||
|
||||
if (!is_19_49_or_greater) {
|
||||
playerLinearGradientLegacyFingerprint.matchOrThrow().let {
|
||||
it.method.apply {
|
||||
val index = it.patternMatch!!.endIndex
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
|
||||
addInstructions(
|
||||
index + 1,
|
||||
"""
|
||||
invoke-static { v$register }, $EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->getLinearGradient([I)[I
|
||||
move-result-object v$register
|
||||
"""
|
||||
)
|
||||
playerSeekbarHandleColorFingerprint.methodOrThrow().apply {
|
||||
addColorChangeInstructions(ytStaticBrandRed, "getVideoPlayerSeekbarColorAccent")
|
||||
}
|
||||
// If hiding feed seekbar thumbnails, then turn off the cairo gradient
|
||||
// of the watch history menu items as they use the same gradient as the
|
||||
// player and there is no easy way to distinguish which to use a transparent color.
|
||||
if (is_19_34_or_greater) {
|
||||
watchHistoryMenuUseProgressDrawableFingerprint.methodOrThrow().apply {
|
||||
val progressIndex = indexOfFirstInstructionOrThrow {
|
||||
val reference = getReference<MethodReference>()
|
||||
reference?.definingClass == "Landroid/widget/ProgressBar;" &&
|
||||
reference.name == "setMax"
|
||||
}
|
||||
val index = indexOfFirstInstructionOrThrow(progressIndex, Opcode.MOVE_RESULT)
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
addInstructions(
|
||||
index + 1,
|
||||
"""
|
||||
invoke-static { v$register }, $EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->showWatchHistoryProgressDrawable(Z)Z
|
||||
move-result v$register
|
||||
"""
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// TODO: add 19.49 support
|
||||
playerSeekbarGradientConfigFingerprint.injectLiteralInstructionBooleanCall(
|
||||
PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG,
|
||||
"$EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->playerSeekbarGradientEnabled(Z)Z"
|
||||
)
|
||||
}
|
||||
|
||||
lithoLinearGradientFingerprint.methodOrThrow().addInstructions(
|
||||
0,
|
||||
"""
|
||||
invoke-static/range { p4 .. p5 }, $EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->getLithoLinearGradient([I[F)[I
|
||||
move-result-object p4
|
||||
"""
|
||||
)
|
||||
|
||||
val playerFingerprint =
|
||||
if (is_19_49_or_greater) {
|
||||
playerLinearGradientFingerprint
|
||||
} else {
|
||||
playerLinearGradientLegacyFingerprint
|
||||
}
|
||||
|
||||
playerFingerprint.matchOrThrow().let {
|
||||
it.method.apply {
|
||||
val index = it.patternMatch!!.endIndex
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
|
||||
addInstructions(
|
||||
index + 1,
|
||||
"""
|
||||
invoke-static { v$register }, $EXTENSION_SEEKBAR_COLOR_CLASS_DESCRIPTOR->getPlayerLinearGradient([I)[I
|
||||
move-result-object v$register
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
settingArray += "SETTINGS: CUSTOM_SEEKBAR_COLOR_ACCENT"
|
||||
|
||||
if (!restoreOldSplashAnimationIncluded) {
|
||||
// Don't use the lotte splash screen layout if using custom seekbar.
|
||||
@ -327,7 +366,6 @@ val seekbarComponentsPatch = bytecodePatch(
|
||||
"setSplashAnimationDrawableTheme(Landroid/graphics/drawable/AnimatedVectorDrawable;)V"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val context = getContext()
|
||||
|
@ -241,6 +241,8 @@ var ytOutlineXWhite = -1L
|
||||
private set
|
||||
var ytPremiumWordMarkHeader = -1L
|
||||
private set
|
||||
var ytStaticBrandRed = -1L
|
||||
private set
|
||||
var ytWordMarkHeader = -1L
|
||||
private set
|
||||
var ytYoutubeMagenta = -1L
|
||||
@ -704,6 +706,10 @@ internal val sharedResourceIdPatch = resourcePatch(
|
||||
ATTR,
|
||||
"ytPremiumWordmarkHeader"
|
||||
]
|
||||
ytStaticBrandRed = resourceMappings[
|
||||
ATTR,
|
||||
"ytStaticBrandRed",
|
||||
]
|
||||
ytWordMarkHeader = resourceMappings[
|
||||
ATTR,
|
||||
"ytWordmarkHeader"
|
||||
|
Reference in New Issue
Block a user