diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt index 6fdfa4b8..7636840f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt @@ -16,11 +16,16 @@ import app.revanced.patches.shared.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.layout.hide.seekbar.annotations.HideSeekbarCompatibility +import app.revanced.patches.youtube.layout.seekbar.bytecode.patch.SeekbarColorBytecodePatch import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @Patch -@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) +@DependsOn([ + IntegrationsPatch::class, + SettingsPatch::class, + SeekbarColorBytecodePatch::class // Used to hide the seekbar in the feed and watch history +]) @Name("hide-seekbar") @Description("Hides the seekbar.") @HideSeekbarCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/annotations/SeekbarColorCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/annotations/SeekbarColorCompatibility.kt new file mode 100644 index 00000000..845bbff9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/annotations/SeekbarColorCompatibility.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.layout.seekbar.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.google.android.youtube")]) +@Target(AnnotationTarget.CLASS) +internal annotation class SeekbarColorCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt new file mode 100644 index 00000000..055a1c59 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch +import app.revanced.util.patch.indexOfFirstConstantInstruction +import org.jf.dexlib2.AccessFlags + +object CreateDarkThemeSeekbarFingerprint : MethodFingerprint( + access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + customFingerprint = { method -> + method.indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) != -1 + && method.indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId) != -1 + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/SetSeekbarClickedColorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/SetSeekbarClickedColorFingerprint.kt similarity index 77% rename from src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/SetSeekbarClickedColorFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/SetSeekbarClickedColorFingerprint.kt index 0237c1ec..abae290d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/SetSeekbarClickedColorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/fingerprints/SetSeekbarClickedColorFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.theme.bytecode.fingerprints +package app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.Opcode diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt new file mode 100644 index 00000000..752f23af --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt @@ -0,0 +1,85 @@ +package app.revanced.patches.youtube.layout.seekbar.bytecode.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction +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.youtube.layout.seekbar.annotations.SeekbarColorCompatibility +import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint +import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.SetSeekbarClickedColorFingerprint +import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch +import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch.Companion.lithoColorOverrideHook +import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import app.revanced.util.patch.indexOfFirstConstantInstruction +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction + +@Description("Hide or set a custom seekbar color") +@DependsOn([IntegrationsPatch::class, LithoColorHookPatch::class, SeekbarColorResourcePatch::class]) +@SeekbarColorCompatibility +@Version("0.0.1") +class SeekbarColorBytecodePatch : BytecodePatch( + listOf(CreateDarkThemeSeekbarFingerprint, SetSeekbarClickedColorFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + CreateDarkThemeSeekbarFingerprint.result?.mutableMethod?.apply { + var registerIndex = indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId) + 2 + var colorRegister = (instruction(registerIndex) as OneRegisterInstruction).registerA + addInstructions( + registerIndex + 1, + """ + invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue(I)I + move-result v$colorRegister + """ + ) + + registerIndex = indexOfFirstConstantInstruction(SeekbarColorResourcePatch.inlineTimeBarPlayedNotHighlightedColorId) + 2 + colorRegister = (instruction(registerIndex) as OneRegisterInstruction).registerA + addInstructions( + registerIndex + 1, + """ + invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue(I)I + move-result v$colorRegister + """ + ) + } ?: return CreateDarkThemeSeekbarFingerprint.toErrorResult() + + SetSeekbarClickedColorFingerprint.result?.let { result -> + result.mutableMethod.let { + val setColorMethodIndex = result.scanResult.patternScanResult!!.startIndex + 1 + val method = context + .toMethodWalker(it) + .nextMethod(setColorMethodIndex, true) + .getMethod() as MutableMethod + + method.apply { + val colorRegister = (method.instruction(0) as TwoRegisterInstruction).registerA + addInstructions( + 0, + """ + invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorOverride(I)I + move-result v$colorRegister + """ + ) + } + } + } ?: return SetSeekbarClickedColorFingerprint.toErrorResult() + + lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getSeekbarColorOverride") + + return PatchResultSuccess() + } + + private companion object { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/SeekbarColorPatch;" + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarColorResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarColorResourcePatch.kt new file mode 100644 index 00000000..a6bc89a8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarColorResourcePatch.kt @@ -0,0 +1,45 @@ +package app.revanced.patches.youtube.layout.seekbar.resource + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.* +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import org.w3c.dom.Element + +@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) +class SeekbarColorResourcePatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + // Edit theme colors via bytecode. + // For that the resource id is used in a bytecode patch to change the color. + + val seekbarErrorMessage = "Could not find seekbar resource" + inlineTimeBarColorizedBarPlayedColorDarkId = ResourceMappingPatch.resourceMappings + .find { it.name == "inline_time_bar_colorized_bar_played_color_dark" }?.id + ?: return PatchResultError(seekbarErrorMessage) + inlineTimeBarPlayedNotHighlightedColorId = ResourceMappingPatch.resourceMappings + .find { it.name == "inline_time_bar_played_not_highlighted_color" }?.id + ?: return PatchResultError(seekbarErrorMessage) + + // Edit the resume playback drawable and replace the progress bar with a custom drawable + context.xmlEditor["res/drawable/resume_playback_progressbar_drawable.xml"].use { editor -> + val layerList = editor.file.getElementsByTagName("layer-list").item(0) as Element + val progressNode = layerList.getElementsByTagName("item").item(1) as Element + if (!progressNode.getAttributeNode("android:id").value.endsWith("progress")) { + return PatchResultError("Could not find progress bar") + } + val scaleNode = progressNode.getElementsByTagName("scale").item(0) as Element + val shapeNode = scaleNode.getElementsByTagName("shape").item(0) as Element + val replacementNode = editor.file.createElement( + "app.revanced.integrations.patches.theme.ProgressBarDrawable") + scaleNode.replaceChild(replacementNode, shapeNode) + } + + return PatchResultSuccess() + } + + companion object { + internal var inlineTimeBarColorizedBarPlayedColorDarkId = -1L + internal var inlineTimeBarPlayedNotHighlightedColorId = -1L + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt deleted file mode 100644 index 98baa9d6..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt +++ /dev/null @@ -1,25 +0,0 @@ -package app.revanced.patches.youtube.layout.theme.bytecode.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint.indexOfInstructionWithSeekbarId -import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.Method -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction - -object CreateDarkThemeSeekbarFingerprint : MethodFingerprint( - access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - customFingerprint = { method -> method.indexOfInstructionWithSeekbarId != -1 }, -) { - /** - * The index of the instruction that loads the resource id of the seekbar. - */ - internal val Method.indexOfInstructionWithSeekbarId - get() = implementation?.let { - it.instructions.indexOfFirst { instruction -> - instruction.opcode == Opcode.CONST && (instruction as WideLiteralInstruction).wideLiteral == ThemeResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/fingerprints/LithoThemeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/LithoThemeFingerprint.kt similarity index 90% rename from src/main/kotlin/app/revanced/patches/youtube/layout/theme/fingerprints/LithoThemeFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/LithoThemeFingerprint.kt index ba6e29cf..ffb29604 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/fingerprints/LithoThemeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/fingerprints/LithoThemeFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.theme.fingerprints +package app.revanced.patches.youtube.layout.theme.bytecode.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/LithoColorHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/LithoColorHookPatch.kt new file mode 100644 index 00000000..0568876e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/LithoColorHookPatch.kt @@ -0,0 +1,47 @@ +package app.revanced.patches.youtube.layout.theme.bytecode.patch + +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.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility +import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.LithoThemeFingerprint + +@Name("litho-color-hook") +@Description("Adds a hook to set color of Litho components.") +@ThemeCompatibility +@Version("0.0.1") +class LithoColorHookPatch : BytecodePatch(listOf(LithoThemeFingerprint)) { + override fun execute(context: BytecodeContext): PatchResult { + LithoThemeFingerprint.result?.let { + insertionIndex = it.scanResult.patternScanResult!!.endIndex - 1 + colorRegister = "p1" + insertionMethod = it.mutableMethod + } ?: return LithoThemeFingerprint.toErrorResult() + + return PatchResultSuccess() + } + companion object { + private var insertionIndex : Int = -1 + private lateinit var colorRegister : String + private lateinit var insertionMethod : MutableMethod + + internal fun lithoColorOverrideHook(targetMethodClass: String, targetMethodName: String) { + insertionMethod.addInstructions( + insertionIndex, + """ + invoke-static {$colorRegister}, $targetMethodClass->$targetMethodName(I)I + move-result $colorRegister + """ + ) + insertionIndex += 2 + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeBytecodePatch.kt index 6ad06005..ee33e866 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeBytecodePatch.kt @@ -1,76 +1,34 @@ package app.revanced.patches.youtube.layout.theme.bytecode.patch -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.data.toMethodWalker -import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.* 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.layout.theme.annotations.ThemeCompatibility -import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint -import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint.indexOfInstructionWithSeekbarId -import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.SetSeekbarClickedColorFingerprint +import app.revanced.patches.youtube.layout.seekbar.bytecode.patch.SeekbarColorBytecodePatch +import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint +import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.SetSeekbarClickedColorFingerprint import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch -import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction @Patch @Name("theme") @Description("Applies a custom theme.") -@DependsOn([ThemeLithoComponentsPatch::class, ThemeResourcePatch::class, IntegrationsPatch::class]) -@ThemeCompatibility +@DependsOn([LithoColorHookPatch::class, SeekbarColorBytecodePatch::class, ThemeResourcePatch::class]) @Version("0.0.1") class ThemeBytecodePatch : BytecodePatch( listOf(CreateDarkThemeSeekbarFingerprint, SetSeekbarClickedColorFingerprint) ) { + override fun execute(context: BytecodeContext): PatchResult { - CreateDarkThemeSeekbarFingerprint.result?.let { - val putColorValueIndex = it.method.indexOfInstructionWithSeekbarId!! + 3 + LithoColorHookPatch.lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getValue") - it.mutableMethod.apply { - val overrideRegister = instruction(putColorValueIndex).registerA - - addInstructions( - putColorValueIndex, - """ - invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue()I - move-result v$overrideRegister - """ - ) - } - } ?: return CreateDarkThemeSeekbarFingerprint.toErrorResult() - - SetSeekbarClickedColorFingerprint.result?.let { result -> - result.mutableMethod.let { - val setColorMethodIndex = result.scanResult.patternScanResult!!.startIndex + 1 - val method = context - .toMethodWalker(it) - .nextMethod(setColorMethodIndex, true) - .getMethod() as MutableMethod - - method.apply { - val colorRegister = method.instruction(0).registerA - addInstructions( - 0, - """ - invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarClickedColorValue(I)I - move-result v$colorRegister - """ - ) - } - } - } ?: return SetSeekbarClickedColorFingerprint.toErrorResult() return PatchResultSuccess() } companion object : OptionsContainer() { - private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemePatch;" + private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemeLithoComponentsPatch;" var darkThemeBackgroundColor: String? by option( PatchOption.StringOption( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeLithoComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeLithoComponentsPatch.kt deleted file mode 100644 index cfcf75ed..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeLithoComponentsPatch.kt +++ /dev/null @@ -1,40 +0,0 @@ -package app.revanced.patches.youtube.layout.theme.bytecode.patch - -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.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility -import app.revanced.patches.youtube.layout.theme.fingerprints.LithoThemeFingerprint - -@Name("theme-litho-components") -@Description("Applies a custom theme to Litho components.") -@ThemeCompatibility -@Version("0.0.1") -class ThemeLithoComponentsPatch : BytecodePatch(listOf(LithoThemeFingerprint)) { - override fun execute(context: BytecodeContext): PatchResult { - LithoThemeFingerprint.result?.let { - it.mutableMethod.apply { - val patchIndex = it.scanResult.patternScanResult!!.endIndex - 1 - - addInstructions( - patchIndex, - """ - invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->getValue(I)I - move-result p1 - """ - ) - } - } ?: return LithoThemeFingerprint.toErrorResult() - return PatchResultSuccess() - } - - private companion object { - private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemeLithoComponentsPatch;" - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt index 2c45e70f..c245970d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt @@ -1,10 +1,7 @@ package app.revanced.patches.youtube.layout.theme.resource import app.revanced.patcher.data.ResourceContext -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultError -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.* import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch import app.revanced.patches.shared.settings.preference.impl.InputType @@ -28,19 +25,11 @@ class ThemeResourcePatch : ResourcePatch { "#FF0000", StringResource( "revanced_seekbar_color_summary", - "The color of the seekbar for the dark theme." + "The color of the seekbar" ) ), ) - // Edit theme colors via bytecode. - // For that the resource id is used in a bytecode patch to change the color. - - inlineTimeBarColorizedBarPlayedColorDarkId = ResourceMappingPatch.resourceMappings - .find { it.name == "inline_time_bar_colorized_bar_played_color_dark" }?.id - ?: return PatchResultError("Could not find seekbar resource") - - val darkThemeBackgroundColor = darkThemeBackgroundColor!! val lightThemeBackgroundColor = lightThemeBackgroundColor!! @@ -72,7 +61,4 @@ class ThemeResourcePatch : ResourcePatch { return PatchResultSuccess() } - internal companion object { - var inlineTimeBarColorizedBarPlayedColorDarkId = -1L - } } diff --git a/src/main/kotlin/app/revanced/util/patch/BytecodeUtils.kt b/src/main/kotlin/app/revanced/util/patch/BytecodeUtils.kt new file mode 100644 index 00000000..d6285732 --- /dev/null +++ b/src/main/kotlin/app/revanced/util/patch/BytecodeUtils.kt @@ -0,0 +1,16 @@ +package app.revanced.util.patch + +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.Method +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +/** + * @return the first constant instruction with the resource id, or -1 if not found. + */ +fun Method.indexOfFirstConstantInstruction(constantValue: Long): Int { + return implementation?.let { + it.instructions.indexOfFirst { instruction -> + instruction.opcode == Opcode.CONST && (instruction as WideLiteralInstruction).wideLiteral == constantValue + } + } ?: -1 +} \ No newline at end of file