feat(YouTube Music - Player components): Add settings Player background primary color and Player background secondary color (Close https://github.com/inotia00/ReVanced_Extended/issues/2119)

This commit is contained in:
inotia00
2025-02-10 17:38:02 +09:00
parent 4531187418
commit 8218c93f17
5 changed files with 120 additions and 48 deletions

View File

@ -37,6 +37,7 @@ import app.revanced.patches.music.utils.resourceid.topEnd
import app.revanced.patches.music.utils.resourceid.topStart
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.ResourceUtils.updatePatchStatus
import app.revanced.patches.music.utils.settings.addPreferenceWithIntent
import app.revanced.patches.music.utils.settings.addSwitchPreference
import app.revanced.patches.music.utils.settings.settingsPatch
import app.revanced.patches.music.utils.videotype.videoTypeHookPatch
@ -48,6 +49,7 @@ import app.revanced.util.addStaticFieldToExtension
import app.revanced.util.adoptChild
import app.revanced.util.cloneMutable
import app.revanced.util.doRecursively
import app.revanced.util.findInstructionIndicesReversed
import app.revanced.util.findMethodOrThrow
import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall
import app.revanced.util.fingerprint.injectLiteralInstructionViewCall
@ -391,7 +393,7 @@ val playerComponentsPatch = bytecodePatch(
// endregion
// region patch for color match player and black player background
// region patch for color match player, change player background and enable zen mode (6.35+)
val (
colorMathPlayerMethodParameter,
@ -406,17 +408,19 @@ val playerComponentsPatch = bytecodePatch(
// black player background
val invokeDirectIndex = indexOfFirstInstructionOrThrow(Opcode.INVOKE_DIRECT)
val targetMethod = getWalkerMethod(invokeDirectIndex)
val insertIndex = targetMethod.indexOfFirstInstructionOrThrow(Opcode.IF_NE)
targetMethod.addInstructions(
insertIndex, """
invoke-static {p1}, $PLAYER_CLASS_DESCRIPTOR->changePlayerBackgroundColor(I)I
move-result p1
invoke-static {p2}, $PLAYER_CLASS_DESCRIPTOR->changePlayerBackgroundColor(I)I
move-result p2
"""
)
getWalkerMethod(invokeDirectIndex).apply {
val index = indexOfFirstInstructionOrThrow(Opcode.FILLED_NEW_ARRAY)
val register = getInstruction<OneRegisterInstruction>(index + 1).registerA
addInstructions(
index + 2, """
invoke-static {v$register}, $PLAYER_CLASS_DESCRIPTOR->changePlayerBackgroundColor([I)[I
move-result-object v$register
"""
)
}
Triple(
parameters,
getInstruction<ReferenceInstruction>(invokeVirtualIndex).reference,
@ -438,7 +442,6 @@ val playerComponentsPatch = bytecodePatch(
}.forEach { method ->
method.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 3
val invokeDirectIndex =
indexOfFirstInstructionReversedOrThrow(Opcode.INVOKE_DIRECT)
val invokeDirectReference =
@ -472,6 +475,16 @@ val playerComponentsPatch = bytecodePatch(
"revanced_change_player_background_color",
"false"
)
addPreferenceWithIntent(
CategoryType.PLAYER,
"revanced_custom_player_background_color_primary",
"revanced_change_player_background_color"
)
addPreferenceWithIntent(
CategoryType.PLAYER,
"revanced_custom_player_background_color_secondary",
"revanced_change_player_background_color"
)
// endregion
@ -708,7 +721,7 @@ val playerComponentsPatch = bytecodePatch(
// endregion
// region patch for enable zen mode
// region patch for enable zen mode (~ 6.34)
// this method is used for old player background (deprecated since YT Music v6.34.51)
zenModeFingerprint.matchOrNull(miniPlayerConstructorFingerprint)?.let {
@ -728,20 +741,6 @@ val playerComponentsPatch = bytecodePatch(
}
} // no exception
switchToggleColorFingerprint.methodOrThrow(miniPlayerConstructorFingerprint).apply {
val invokeDirectIndex = indexOfFirstInstructionOrThrow(Opcode.INVOKE_DIRECT)
val walkerMethod = getWalkerMethod(invokeDirectIndex)
walkerMethod.addInstructions(
0, """
invoke-static {p1}, $PLAYER_CLASS_DESCRIPTOR->enableZenMode(I)I
move-result p1
invoke-static {p2}, $PLAYER_CLASS_DESCRIPTOR->enableZenMode(I)I
move-result p2
"""
)
}
addSwitchPreference(
CategoryType.PLAYER,
"revanced_enable_zen_mode",