From ae49cd421ab1d21dc09c06f26cb1df90fb1d5b75 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sat, 6 May 2023 01:43:25 +0900 Subject: [PATCH] feat(youtube/custom-seekbar-color): change the color of the last watched progress bar https://github.com/inotia00/ReVanced_Extended/issues/748 --- .../shared/patch/options/PatchOptions.kt | 12 ++++ .../etc/materialyou/patch/MaterialYouPatch.kt | 4 +- .../patch/GeneralThemeBytecodePatch.kt | 45 ------------- .../{resource => }/patch/GeneralThemePatch.kt | 16 +++-- .../theme/{resource => }/patch/ThemePatch.kt | 4 +- .../ControlsOverlayFingerprint.kt | 2 +- .../ControlsOverlayParentFingerprint.kt | 2 +- .../fingerprints/ProgressColorFingerprint.kt | 2 +- .../fingerprints/SeekbarColorFingerprint.kt | 2 +- .../patch/SeekbarColorBytecodePatch.kt} | 28 ++------ .../resource/patch/SeekbarColorPatch.kt | 64 ++++++++++++++++++ .../fingerprints/LithoThemeFingerprint.kt | 4 +- .../misc/litho/patch/LithoThemePatch.kt | 65 +++++++++++++++++++ 13 files changed, 169 insertions(+), 81 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/bytecode/patch/GeneralThemeBytecodePatch.kt rename src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/{resource => }/patch/GeneralThemePatch.kt (89%) rename src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/{resource => }/patch/ThemePatch.kt (92%) rename src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/{ => bytecode}/fingerprints/ControlsOverlayFingerprint.kt (91%) rename src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/{ => bytecode}/fingerprints/ControlsOverlayParentFingerprint.kt (95%) rename src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/{ => bytecode}/fingerprints/ProgressColorFingerprint.kt (93%) rename src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/{ => bytecode}/fingerprints/SeekbarColorFingerprint.kt (96%) rename src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/{patch/SeekbarColorPatch.kt => bytecode/patch/SeekbarColorBytecodePatch.kt} (83%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt rename src/main/kotlin/app/revanced/patches/youtube/{layout/etc/theme/bytecode => misc/litho}/fingerprints/LithoThemeFingerprint.kt (80%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoThemePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt b/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt index 72c08a82f..4530a92e0 100644 --- a/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt +++ b/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt @@ -119,5 +119,17 @@ class PatchOptions : ResourcePatch { description = "The background color of the dark theme. Can be a hex color or a resource reference." ) ) + + /** + * Resumed progressbar color in playlists and history + */ + internal var resumedProgressBarColor: String? by option( + PatchOption.StringOption( + key = "resumedProgressBarColor", + default = "#ffff0000", + title = "Resumed progressbar color", + description = "Resumed progressbar color in playlists and history. Can be a hex color or a resource reference." + ) + ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt index 75db72797..2c155ade1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/materialyou/patch/MaterialYouPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patcher.patch.ResourcePatch 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.youtube.layout.etc.theme.bytecode.patch.GeneralThemeBytecodePatch.Companion.isMonetPatchIncluded -import app.revanced.patches.youtube.layout.etc.theme.resource.patch.GeneralThemePatch +import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch +import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch.Companion.isMonetPatchIncluded import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme import app.revanced.util.resources.ResourceUtils.copyXmlNode diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/bytecode/patch/GeneralThemeBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/bytecode/patch/GeneralThemeBytecodePatch.kt deleted file mode 100644 index 70cf709c7..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/bytecode/patch/GeneralThemeBytecodePatch.kt +++ /dev/null @@ -1,45 +0,0 @@ -package app.revanced.patches.youtube.layout.etc.theme.bytecode.patch - -import app.revanced.extensions.toErrorResult -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.shared.annotation.YouTubeCompatibility -import app.revanced.patches.youtube.layout.etc.theme.bytecode.fingerprints.LithoThemeFingerprint -import app.revanced.util.integrations.Constants.UTILS_PATH -import org.jf.dexlib2.iface.instruction.formats.Instruction35c - -@Name("general-theme") -@YouTubeCompatibility -@Version("0.0.1") -class GeneralThemeBytecodePatch : BytecodePatch( - listOf( - LithoThemeFingerprint - ) -) { - override fun execute(context: BytecodeContext): PatchResult { - - LithoThemeFingerprint.result?.let { - with (it.mutableMethod) { - val insertIndex = it.scanResult.patternScanResult!!.endIndex - 1 - val register = (implementation!!.instructions[insertIndex] as Instruction35c).registerD - - addInstructions( - insertIndex, """ - invoke-static { v$register }, $UTILS_PATH/LithoThemePatch;->applyLithoTheme(I)I - move-result v$register - """ - ) - } - } ?: return LithoThemeFingerprint.toErrorResult() - - return PatchResultSuccess() - } - internal companion object { - var isMonetPatchIncluded: Boolean = false - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/resource/patch/GeneralThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/GeneralThemePatch.kt similarity index 89% rename from src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/resource/patch/GeneralThemePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/GeneralThemePatch.kt index c60ed492f..6008e6bce 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/resource/patch/GeneralThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/GeneralThemePatch.kt @@ -1,21 +1,24 @@ -package app.revanced.patches.youtube.layout.etc.theme.resource.patch +package app.revanced.patches.youtube.layout.etc.theme.patch import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.ResourcePatch -import app.revanced.patches.youtube.layout.etc.theme.bytecode.patch.GeneralThemeBytecodePatch +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.youtube.misc.litho.patch.LithoThemePatch +import app.revanced.util.integrations.Constants import org.w3c.dom.Element -@Name("general-theme-resource-patch") -@DependsOn([GeneralThemeBytecodePatch::class]) +@Name("general-theme-patch") +@DependsOn([LithoThemePatch::class]) @Version("0.0.1") class GeneralThemePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { + LithoThemePatch.injectCall("${Constants.UTILS_PATH}/LithoThemePatch;->applyLithoTheme(I)I") + // edit the resource files to change the splash screen color val attrsPath = "res/values/attrs.xml" val stylesPaths: List = listOf( @@ -88,4 +91,7 @@ class GeneralThemePatch : ResourcePatch { return PatchResultSuccess() } + internal companion object { + var isMonetPatchIncluded: Boolean = false + } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/resource/patch/ThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/ThemePatch.kt similarity index 92% rename from src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/resource/patch/ThemePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/ThemePatch.kt index a6333b8fb..5a953b9da 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/resource/patch/ThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/ThemePatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.etc.theme.resource.patch +package app.revanced.patches.youtube.layout.etc.theme.patch import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name @@ -11,7 +11,7 @@ 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.options.PatchOptions -import app.revanced.patches.youtube.layout.etc.theme.bytecode.patch.GeneralThemeBytecodePatch.Companion.isMonetPatchIncluded +import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch.Companion.isMonetPatchIncluded import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme import org.w3c.dom.Element diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ControlsOverlayFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ControlsOverlayFingerprint.kt similarity index 91% rename from src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ControlsOverlayFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ControlsOverlayFingerprint.kt index 0aae84e08..0f909e2a4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ControlsOverlayFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ControlsOverlayFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints +package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ControlsOverlayParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ControlsOverlayParentFingerprint.kt similarity index 95% rename from src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ControlsOverlayParentFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ControlsOverlayParentFingerprint.kt index e7ee33f7d..96def633a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ControlsOverlayParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ControlsOverlayParentFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints +package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.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/seekbar/seekbarcolor/fingerprints/ProgressColorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ProgressColorFingerprint.kt similarity index 93% rename from src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ProgressColorFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ProgressColorFingerprint.kt index 03a94cd19..72c85a1a9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/ProgressColorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/ProgressColorFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints +package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.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/seekbarcolor/fingerprints/SeekbarColorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt similarity index 96% rename from src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/fingerprints/SeekbarColorFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/fingerprints/SeekbarColorFingerprint.kt index 7b1eccc40..f8d397a8a 100644 --- 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/bytecode/fingerprints/SeekbarColorFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints +package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch 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/bytecode/patch/SeekbarColorBytecodePatch.kt similarity index 83% rename from src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/patch/SeekbarColorPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/bytecode/patch/SeekbarColorBytecodePatch.kt index 592118401..7c3a40046 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/bytecode/patch/SeekbarColorBytecodePatch.kt @@ -1,7 +1,6 @@ -package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.patch +package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.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 @@ -12,29 +11,26 @@ 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.patch.annotations.Patch import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint -import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints.* +import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.fingerprints.* +import app.revanced.patches.youtube.misc.litho.patch.LithoThemePatch 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.INTEGRATIONS_PATH import app.revanced.util.integrations.Constants.SEEKBAR import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -@Patch -@Name("custom-seekbar-color") -@Description("Change seekbar color.") +@Name("custom-seekbar-color-bytecode-patch") @DependsOn( [ - SettingsPatch::class, + LithoThemePatch::class, SharedResourceIdPatch::class ] ) @YouTubeCompatibility @Version("0.0.1") -class SeekbarColorPatch : BytecodePatch( +class SeekbarColorBytecodePatch : BytecodePatch( listOf( ControlsOverlayParentFingerprint, ControlsOverlayStyleFingerprint, @@ -75,17 +71,7 @@ class SeekbarColorPatch : BytecodePatch( ) ?: return ControlsOverlayFingerprint.toErrorResult() } ?: return ControlsOverlayParentFingerprint.toErrorResult() - /* - * Add settings - */ - SettingsPatch.addPreference( - arrayOf( - "PREFERENCE: SEEKBAR_SETTINGS", - "SETTINGS: CUSTOM_SEEKBAR_COLOR" - ) - ) - - SettingsPatch.updatePatchStatus("custom-seekbar-color") + LithoThemePatch.injectCall("$SEEKBAR->resumedProgressBarColor(I)I") return PatchResultSuccess() } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt new file mode 100644 index 000000000..da4337428 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/seekbarcolor/resource/patch/SeekbarColorPatch.kt @@ -0,0 +1,64 @@ +package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.resource.patch + +import app.revanced.extensions.doRecursively +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +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.options.PatchOptions +import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.patch.SeekbarColorBytecodePatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import org.w3c.dom.Element + +@Patch +@Name("custom-seekbar-color") +@Description("Change seekbar color and progressbar color.") +@DependsOn( + [ + PatchOptions::class, + SeekbarColorBytecodePatch::class, + SettingsPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class ThemePatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + + context.xmlEditor[RESOURCE_FILE_PATH].use { + it.file.doRecursively { + arrayOf("color").forEach replacement@{ replacement -> + if (it !is Element) return@replacement + + it.getAttributeNode("android:$replacement")?.let { attribute -> + if (attribute.textContent.startsWith("@color/")) + attribute.textContent = PatchOptions.resumedProgressBarColor!! + } + } + } + } + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: SEEKBAR_SETTINGS", + "SETTINGS: CUSTOM_SEEKBAR_COLOR" + ) + ) + + SettingsPatch.updatePatchStatus("custom-seekbar-color") + + return PatchResultSuccess() + } + private companion object { + const val RESOURCE_FILE_PATH = "res/drawable/resume_playback_progressbar_drawable.xml" + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/bytecode/fingerprints/LithoThemeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/fingerprints/LithoThemeFingerprint.kt similarity index 80% rename from src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/bytecode/fingerprints/LithoThemeFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/misc/litho/fingerprints/LithoThemeFingerprint.kt index d31904706..0525f630c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/bytecode/fingerprints/LithoThemeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/fingerprints/LithoThemeFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.etc.theme.bytecode.fingerprints +package app.revanced.patches.youtube.misc.litho.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint @@ -12,7 +12,7 @@ object LithoThemeFingerprint : MethodFingerprint( opcodes = listOf( Opcode.IF_NEZ, Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL, + Opcode.INVOKE_VIRTUAL, // Paint.setColor: inject point Opcode.RETURN_VOID ), customFingerprint = { it.name == "onBoundsChange" } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoThemePatch.kt new file mode 100644 index 000000000..43397482d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/litho/patch/LithoThemePatch.kt @@ -0,0 +1,65 @@ +package app.revanced.patches.youtube.misc.litho.patch + +import app.revanced.extensions.toErrorResult +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.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.misc.litho.fingerprints.LithoThemeFingerprint +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.formats.Instruction35c +import org.jf.dexlib2.iface.reference.MethodReference + +@Name("litho-theme-hook") +@YouTubeCompatibility +@Version("0.0.1") +class LithoThemePatch : BytecodePatch( + listOf( + LithoThemeFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + LithoThemeFingerprint.result?.mutableMethod?.let { + with (it.implementation!!.instructions) { + for (index in size - 1 downTo 0) { + val invokeInstruction = this[index] as? ReferenceInstruction ?: continue + if ((invokeInstruction.reference as MethodReference).name != "setColor") continue + insertIndex = index + insertRegister = (this[index] as Instruction35c).registerD + insertMethod = it + break + } + } + } ?: return LithoThemeFingerprint.toErrorResult() + + return PatchResultSuccess() + } + + companion object { + private var offset = 0 + + private var insertIndex: Int = 0 + private var insertRegister: Int = 0 + private lateinit var insertMethod: MutableMethod + + + fun injectCall( + methodDescriptor: String + ) { + insertMethod.addInstructions( + insertIndex + offset, """ + invoke-static {v$insertRegister}, $methodDescriptor + move-result v$insertRegister + """ + ) + offset += 2 + } + } +} +