diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/oldseekbarcolor/bytecode/patch/OldSeekbarColorBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/oldseekbarcolor/bytecode/patch/OldSeekbarColorBytecodePatch.kt new file mode 100644 index 000000000..29897e585 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/oldseekbarcolor/bytecode/patch/OldSeekbarColorBytecodePatch.kt @@ -0,0 +1,63 @@ +package app.revanced.patches.youtube.layout.seekbar.oldseekbarcolor.bytecode.patch + +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.patch.annotations.DependsOn +import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.extensions.findMutableMethodOf +import app.revanced.shared.patches.mapping.ResourceMappingPatch +import app.revanced.shared.util.integrations.Constants.SEEKBAR_LAYOUT +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.formats.Instruction31i + +@DependsOn([ResourceMappingPatch::class]) +@Name("old-seekbar-color-bytecode-patch") +@YouTubeCompatibility +@Version("0.0.1") +class OldSeekbarColorBytecodePatch : 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 + } + + 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 insertIndex = index + 1 + + val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method) + + val viewRegister = (instructions.elementAt(index) as Instruction31i).registerA + + mutableMethod.addInstructions( + insertIndex, """ + invoke-static {v$viewRegister}, $SEEKBAR_LAYOUT->enableOldSeekbarColor(I)I + move-result v$viewRegister + """ + ) + } + } + } + else -> return@forEachIndexed + } + } + } + } + } + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/oldseekbarcolor/resource/patch/OldSeekbarColorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/oldseekbarcolor/resource/patch/OldSeekbarColorPatch.kt new file mode 100644 index 000000000..54d37d9d9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/oldseekbarcolor/resource/patch/OldSeekbarColorPatch.kt @@ -0,0 +1,49 @@ +package app.revanced.patches.youtube.layout.seekbar.oldseekbarcolor.resource.patch + +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.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patches.youtube.layout.seekbar.oldseekbarcolor.bytecode.patch.OldSeekbarColorBytecodePatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.util.resources.ResourceHelper + +@Patch +@Name("enable-old-seekbar-color") +@Description("Enable old seekbar color in dark mode.") +@DependsOn( + [ + OldSeekbarColorBytecodePatch::class, + SettingsPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class OldSeekbarColorPatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + + /* + add settings + */ + ResourceHelper.addSettings2( + context, + "PREFERENCE_CATEGORY: REVANCED_SETTINGS", + "PREFERENCE: LAYOUT_SETTINGS", + "PREFERENCE_HEADER: SEEKBAR", + "SETTINGS: ENABLE_OLD_SEEKBAR_COLOR" + ) + + ResourceHelper.patchSuccess( + context, + "enable-old-seekbar-color" + ) + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index aa0c2b062..7ebbedb7e 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -212,6 +212,9 @@ Is it ready to submit?" YouTube Layout will follow your Google Account status Trick the YouTube version to force enable old layout Enable old layout + New seekbar color is used + Old seekbar color is used + Enable old style seekbar color New style quality settings are shown Old style quality settings are shown Enable old style quality layout diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 7c236c774..3f1d7b465 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -237,6 +237,9 @@ + + @@ -384,6 +387,7 @@ +