diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/SeekbarColorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/SeekbarColorFingerprint.kt
new file mode 100644
index 000000000..7b1eccc40
--- /dev/null
+++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/SeekbarColorFingerprint.kt
@@ -0,0 +1,15 @@
+package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints
+
+import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
+import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
+import org.jf.dexlib2.Opcode
+import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
+
+object SeekbarColorFingerprint : MethodFingerprint(
+ customFingerprint = { methodDef ->
+ methodDef.implementation?.instructions?.any {
+ it.opcode.ordinal == Opcode.CONST.ordinal &&
+ (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.timeBarPlayedDarkLabelId
+ } == true
+ }
+)
\ No newline at end of file
diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/patch/SeekbarColorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/patch/SeekbarColorPatch.kt
index b74e7dcc8..5bd621b07 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/patch/SeekbarColorPatch.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/patch/SeekbarColorPatch.kt
@@ -1,96 +1,86 @@
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.patch
-import app.revanced.extensions.findMutableMethodOf
+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
import app.revanced.patcher.extensions.addInstructions
+import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
+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
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.patch.mapping.ResourceMappingPatch
+import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint
+import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints.SeekbarColorFingerprint
+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.SEEKBAR
-import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
-import org.jf.dexlib2.iface.instruction.formats.Instruction31i
+import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
@Patch
@Name("custom-seekbar-color")
-@Description("Change seekbar color in dark mode.")
+@Description("Change seekbar color.")
@DependsOn(
[
- ResourceMappingPatch::class,
- SettingsPatch::class
+ SettingsPatch::class,
+ SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
-class SeekbarColorPatch : BytecodePatch() {
-
- // list of resource names to get the id of
- private val resourceIds = arrayOf(
- "inline_time_bar_colorized_bar_played_color_dark"
- ).map { name ->
- ResourceMappingPatch.resourceMappings.single { it.name == name }.id
- }
- private var patchSuccessArray = Array(resourceIds.size) {false}
-
+class SeekbarColorPatch : BytecodePatch(
+ listOf(
+ ControlsOverlayStyleFingerprint,
+ SeekbarColorFingerprint
+ )
+) {
override fun execute(context: BytecodeContext): PatchResult {
- context.classes.forEach { classDef ->
- classDef.methods.forEach { method ->
- with(method.implementation) {
- this?.instructions?.forEachIndexed { index, instruction ->
- when (instruction.opcode) {
- Opcode.CONST -> {
- when ((instruction as Instruction31i).wideLiteral) {
- resourceIds[0] -> { // seekbar color
- val registerIndex = index + 2
+ SeekbarColorFingerprint.result?.mutableMethod?.let { method ->
+ with (method.implementation!!.instructions) {
+ val insertIndex = this.indexOfFirst {
+ (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.timeBarPlayedDarkLabelId
+ } + 2
- val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method)
+ val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA
- val viewRegister = (instructions.elementAt(registerIndex) as OneRegisterInstruction).registerA
-
- mutableMethod.addInstructions(
- registerIndex + 1, """
- invoke-static {v$viewRegister}, $SEEKBAR->enableCustomSeekbarColor(I)I
- move-result v$viewRegister
- """
- )
-
- patchSuccessArray[0] = true
- }
- }
- }
- else -> return@forEachIndexed
- }
- }
- }
- }
- }
-
- val errorIndex: Int = patchSuccessArray.indexOf(false)
-
- if (errorIndex == -1) {
- /*
- * Add settings
- */
- SettingsPatch.addPreference(
- arrayOf(
- "PREFERENCE: SEEKBAR_SETTINGS",
- "SETTINGS: CUSTOM_SEEKBAR_COLOR"
+ method.addInstructions(
+ insertIndex + 1, """
+ invoke-static {v$insertRegister}, $SEEKBAR->enableCustomSeekbarColorDarkMode(I)I
+ move-result v$insertRegister
+ """
)
+ }
+ } ?: return SeekbarColorFingerprint.toErrorResult()
+
+ val controlsOverlayStyleClassDef = ControlsOverlayStyleFingerprint.result?.classDef?: return ControlsOverlayStyleFingerprint.toErrorResult()
+
+ val progressColorFingerprint =
+ object : MethodFingerprint(returnType = "V", parameters = listOf("I"), customFingerprint = { it.name == "e" }) {}
+ progressColorFingerprint.resolve(context, controlsOverlayStyleClassDef)
+ progressColorFingerprint.result?.mutableMethod?.addInstructions(
+ 0, """
+ invoke-static {p1}, $SEEKBAR->enableCustomSeekbarColor(I)I
+ move-result p1
+ """
+ )?: return progressColorFingerprint.toErrorResult()
+
+ /*
+ * Add settings
+ */
+ SettingsPatch.addPreference(
+ arrayOf(
+ "PREFERENCE: SEEKBAR_SETTINGS",
+ "SETTINGS: CUSTOM_SEEKBAR_COLOR"
)
+ )
- SettingsPatch.updatePatchStatus("custom-seekbar-color")
+ SettingsPatch.updatePatchStatus("custom-seekbar-color")
- return PatchResultSuccess()
- } else
- return PatchResultError("Instruction not found: $errorIndex")
+ return PatchResultSuccess()
}
}
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 191e519a9..38cbc84a4 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
@@ -48,6 +48,7 @@ class SharedResourceIdPatch : ResourcePatch {
var relatedChipCloudMarginLabelId: Long = -1
var rightCommentLabelId: Long = -1
var scrubbingLabelId: Long = -1
+ var timeBarPlayedDarkLabelId: Long = -1
var timeStampsContainerLabelId: Long = -1
var tooltipLabelId: Long = -1
var videoQualityFragmentLabelId: Long = -1
@@ -89,6 +90,7 @@ class SharedResourceIdPatch : ResourcePatch {
relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins")
rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c")
scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing")
+ timeBarPlayedDarkLabelId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark")
timeStampsContainerLabelId = find(ID, "timestamps_container")
tooltipLabelId = find(LAYOUT, "tooltip_content_view")
videoQualityFragmentLabelId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")
diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml
index f8f6ec11e..b774deea1 100644
--- a/src/main/resources/youtube/settings/host/values/strings.xml
+++ b/src/main/resources/youtube/settings/host/values/strings.xml
@@ -93,7 +93,7 @@ Is it ready to submit?"
Bypass ambient mode restrictions
Comments
Time Stamp copied to clipboard
- Type the hex code of the seekbar color to use in dark mode
+ Type the hex code of the seekbar color
Custom seekbar color value
Default video quality Cellular
Default video quality Wi-Fi
@@ -127,7 +127,7 @@ Is it ready to submit?"
Always auto repeat
Custom seekbar color is disabled
Custom seekbar color is enabled
- Enable custom seekbar color in dark mode
+ Enable custom seekbar color
Custom video speed is disabled
Custom video speed is enabled
Enable custom video speed