From 9eb15b2e34ae17b8590c84596ecea2184d7312e6 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 8 May 2023 04:54:11 +0900 Subject: [PATCH] feat(youtube/custom-seekbar-color): change chapter seekbar color when quickly touching and seeking --- .../fingerprints/SeekbarColorFingerprint.kt | 2 +- .../patch/SeekbarColorBytecodePatch.kt | 45 ++++++++++++++----- .../resourceid/patch/SharedResourceIdPatch.kt | 6 ++- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt index f8d397a8a..ca7272fed 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt @@ -9,7 +9,7 @@ object SeekbarColorFingerprint : MethodFingerprint( customFingerprint = { methodDef -> methodDef.implementation?.instructions?.any { it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.timeBarPlayedDarkLabelId + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.inlineTimeBarColorizedBarPlayedColorDarkId } == true } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt index 7c3a40046..680eac7fa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt @@ -6,11 +6,13 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction 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.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints.* @@ -40,30 +42,36 @@ class SeekbarColorBytecodePatch : BytecodePatch( override fun execute(context: BytecodeContext): PatchResult { SeekbarColorFingerprint.result?.mutableMethod?.let { method -> with (method.implementation!!.instructions) { - val insertIndex = this.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.timeBarPlayedDarkLabelId - } + 2 + val insertIndex = arrayOf( + SharedResourceIdPatch.inlineTimeBarColorizedBarPlayedColorDarkId, + SharedResourceIdPatch.inlineTimeBarPlayedNotHighlightedColorId + ).map { id -> + this.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == id + } + 2 + } - val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA - - method.addInstructions( - insertIndex + 1, """ - invoke-static {v$insertRegister}, $SEEKBAR->enableCustomSeekbarColorDarkMode(I)I - move-result v$insertRegister - """ - ) + method.hook(insertIndex[0]) + method.hook(insertIndex[1]) } } ?: return SeekbarColorFingerprint.toErrorResult() ControlsOverlayStyleFingerprint.result?.let { parentResult -> ProgressColorFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.addInstructions( 0, """ - invoke-static {p1}, $SEEKBAR->enableCustomSeekbarColor(I)I + invoke-static {p1}, $SEEKBAR->getSeekbarClickedColorValue(I)I move-result p1 """ ) ?: return ProgressColorFingerprint.toErrorResult() } ?: return ControlsOverlayStyleFingerprint.toErrorResult() + + /** + * Context called when playing a video in the PlayStore + * If this context is not overridden, Exception occurs when reading a value from SharedPreference (ROOT Build) + * + * TODO: merging into abstract integrations patch + */ ControlsOverlayParentFingerprint.result?.let { parentResult -> ControlsOverlayFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.addInstruction( 0, @@ -75,4 +83,17 @@ class SeekbarColorBytecodePatch : BytecodePatch( return PatchResultSuccess() } + + private companion object { + fun MutableMethod.hook(insertIndex: Int) { + val insertRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA + + addInstructions( + insertIndex + 1, """ + invoke-static {v$insertRegister}, $SEEKBAR->overrideSeekbarColor(I)I + move-result v$insertRegister + """ + ) + } + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index 1d2067907..41f2cd511 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -34,6 +34,8 @@ class SharedResourceIdPatch : ResourcePatch { var filterBarHeightLabelId: Long = -1 var floatyBarTopMarginLabelId: Long = -1 var imageOnlyTabId: Long = -1 + var inlineTimeBarColorizedBarPlayedColorDarkId: Long = -1 + var inlineTimeBarPlayedNotHighlightedColorId: Long = -1 var layoutCircle: Long = -1 var layoutIcon: Long = -1 var layoutVideo: Long = -1 @@ -50,7 +52,6 @@ class SharedResourceIdPatch : ResourcePatch { var searchSuggestionEntryLabelId: Long = -1 var scrubbingLabelId: Long = -1 var slimMetadataToggleButtonLabelId: Long = -1 - var timeBarPlayedDarkLabelId: Long = -1 var tooltipLabelId: Long = -1 var videoQualityFragmentLabelId: Long = -1 } @@ -77,6 +78,8 @@ class SharedResourceIdPatch : ResourcePatch { filterBarHeightLabelId = find(DIMEN, "filter_bar_height") floatyBarTopMarginLabelId = find(DIMEN, "floaty_bar_button_top_margin") imageOnlyTabId = find(LAYOUT, "image_only_tab") + inlineTimeBarColorizedBarPlayedColorDarkId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark") + inlineTimeBarPlayedNotHighlightedColorId = find(COLOR, "inline_time_bar_played_not_highlighted_color") layoutCircle = find(LAYOUT, "endscreen_element_layout_circle") layoutIcon = find(LAYOUT, "endscreen_element_layout_icon") layoutVideo = find(LAYOUT, "endscreen_element_layout_video") @@ -93,7 +96,6 @@ class SharedResourceIdPatch : ResourcePatch { searchSuggestionEntryLabelId = find(LAYOUT, "search_suggestion_entry") scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing") slimMetadataToggleButtonLabelId = find(COLOR, "slim_metadata_toggle_button") - timeBarPlayedDarkLabelId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark") tooltipLabelId = find(LAYOUT, "tooltip_content_view") videoQualityFragmentLabelId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")