Skip to content

Commit

Permalink
feat(youtube/custom-seekbar-color): apply custom seekbar color to shorts
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Jul 23, 2023
1 parent d1f2fc6 commit ddbf533
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

object ControlsOverlayStyleFingerprint : MethodFingerprint(
opcodes = listOf(Opcode.IGET_BOOLEAN),
strings = listOf("supportsNextPrevious", "Missing required properties:")
opcodes = listOf(Opcode.CONST_HIGH16),
strings = listOf("YOUTUBE", "PREROLL", "POSTROLL"),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("/ControlsOverlayStyle;")
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.revanced.patches.youtube.seekbar.seekbarcolor.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.InlineTimeBarColorizedBarPlayedColorDark
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.InlineTimeBarPlayedNotHighlightedColor
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.AccessFlags

object PlayerSeekbarColorFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ ->
methodDef.isWideLiteralExists(InlineTimeBarColorizedBarPlayedColorDark)
&& methodDef.isWideLiteralExists(InlineTimeBarPlayedNotHighlightedColor)
}
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.revanced.patches.youtube.seekbar.seekbarcolor.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelTimeBarPlayedColor
import app.revanced.util.bytecode.isWideLiteralExists
import org.jf.dexlib2.AccessFlags

object ShortsSeekbarColorFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ ->
methodDef.isWideLiteralExists(ReelTimeBarPlayedColor)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
Expand All @@ -16,18 +16,20 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.seekbar.seekbarcolor.fingerprints.ControlsOverlayStyleFingerprint
import app.revanced.patches.youtube.seekbar.seekbarcolor.fingerprints.ProgressColorFingerprint
import app.revanced.patches.youtube.seekbar.seekbarcolor.fingerprints.SeekbarColorFingerprint
import app.revanced.patches.youtube.seekbar.seekbarcolor.fingerprints.PlayerSeekbarColorFingerprint
import app.revanced.patches.youtube.seekbar.seekbarcolor.fingerprints.ShortsSeekbarColorFingerprint
import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility
import app.revanced.patches.youtube.utils.litho.patch.LithoThemePatch
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.InlineTimeBarColorizedBarPlayedColorDark
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.InlineTimeBarPlayedNotHighlightedColor
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelTimeBarPlayedColor
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch.Companion.contexts
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.util.integrations.Constants.SEEKBAR
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.w3c.dom.Element

@Patch
Expand All @@ -45,29 +47,36 @@ import org.w3c.dom.Element
class SeekbarColorPatch : BytecodePatch(
listOf(
ControlsOverlayStyleFingerprint,
SeekbarColorFingerprint
PlayerSeekbarColorFingerprint,
ShortsSeekbarColorFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
SeekbarColorFingerprint.result?.let {
it.mutableMethod.apply {
hook(getWideLiteralIndex(InlineTimeBarColorizedBarPlayedColorDark) + 2)
hook(getWideLiteralIndex(InlineTimeBarPlayedNotHighlightedColor) + 2)
}
} ?: return SeekbarColorFingerprint.toErrorResult()
PlayerSeekbarColorFingerprint.result?.mutableMethod?.apply {
hook(getWideLiteralIndex(InlineTimeBarColorizedBarPlayedColorDark) + 2)
hook(getWideLiteralIndex(InlineTimeBarPlayedNotHighlightedColor) + 2)
} ?: return PlayerSeekbarColorFingerprint.toErrorResult()

ControlsOverlayStyleFingerprint.result?.let { parentResult ->
ProgressColorFingerprint.also {
it.resolve(
context,
parentResult.classDef
)
}.result?.mutableMethod?.addInstructions(
0, """
invoke-static {p1}, $SEEKBAR->getSeekbarClickedColorValue(I)I
move-result p1
ShortsSeekbarColorFingerprint.result?.mutableMethod?.apply {
hook(getWideLiteralIndex(ReelTimeBarPlayedColor) + 2)
} ?: return ShortsSeekbarColorFingerprint.toErrorResult()

ControlsOverlayStyleFingerprint.result?.let {
with(
context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.startIndex + 1, true)
.getMethod() as MutableMethod
) {
val colorRegister = getInstruction<TwoRegisterInstruction>(0).registerA

addInstructions(
0, """
invoke-static {v$colorRegister}, $SEEKBAR->getSeekbarClickedColorValue(I)I
move-result v$colorRegister
"""
) ?: return ProgressColorFingerprint.toErrorResult()
)
}
} ?: return ControlsOverlayStyleFingerprint.toErrorResult()

LithoThemePatch.injectCall("$SEEKBAR->getLithoColor(I)I")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SharedResourceIdPatch : ResourcePatch {
var ReelPlayerPausedStateButton: Long = -1
var ReelRightDislikeIcon: Long = -1
var ReelRightLikeIcon: Long = -1
var ReelTimeBarPlayedColor: Long = -1
var RelatedChipCloudMargin: Long = -1
var RightComment: Long = -1
var ScrimOverlay: Long = -1
Expand Down Expand Up @@ -137,6 +138,7 @@ class SharedResourceIdPatch : ResourcePatch {
ReelPlayerPausedStateButton = find(ID, "reel_player_paused_state_buttons")
ReelRightDislikeIcon = find(DRAWABLE, "reel_right_dislike_icon")
ReelRightLikeIcon = find(DRAWABLE, "reel_right_like_icon")
ReelTimeBarPlayedColor = find(COLOR, "reel_time_bar_played_color")
RelatedChipCloudMargin = find(LAYOUT, "related_chip_cloud_reduced_margins")
RightComment = find(DRAWABLE, "ic_right_comment_32c")
ScrimOverlay = find(ID, "scrim_overlay")
Expand Down

0 comments on commit ddbf533

Please sign in to comment.