From 40e27610334041133ac8e537271afd96f32c3b74 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 8 May 2023 04:17:04 +0900 Subject: [PATCH] feat(youtube/patch-options): all patch options are now moved to the appropriate patch --- .../shared/patch/options/PatchOptions.kt | 135 ------------------ .../patch/packagename/PackageNamePatch.kt | 47 ++++++ .../name/patch/CustomBrandingNamePatch.kt | 24 ++-- .../patch/DoubleTapLengthPatch.kt | 43 +++--- .../layout/etc/theme/patch/ThemePatch.kt | 42 +++--- .../resource/patch/SeekbarColorPatch.kt | 22 +-- .../bytecode/patch/MicroGBytecodePatch.kt | 6 +- .../misc/microg/resource/patch/MicroGPatch.kt | 6 +- .../SpeedArrayGeneratorFingerprint.kt | 2 +- .../fingerprints/SpeedLimiterFingerprint.kt | 2 +- .../VideoSpeedEntriesFingerprint.kt | 2 +- .../patch/CustomVideoSpeedBytecodePatch.kt | 88 +++++++++--- .../resource/patch/CustomVideoSpeedPatch.kt | 71 --------- 13 files changed, 191 insertions(+), 299 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt create mode 100644 src/main/kotlin/app/revanced/patches/shared/patch/packagename/PackageNamePatch.kt rename src/main/kotlin/app/revanced/patches/youtube/video/customspeed/{bytecode => }/fingerprints/SpeedArrayGeneratorFingerprint.kt (80%) rename src/main/kotlin/app/revanced/patches/youtube/video/customspeed/{bytecode => }/fingerprints/SpeedLimiterFingerprint.kt (88%) rename src/main/kotlin/app/revanced/patches/youtube/video/customspeed/{bytecode => }/fingerprints/VideoSpeedEntriesFingerprint.kt (80%) rename src/main/kotlin/app/revanced/patches/youtube/video/customspeed/{bytecode => }/patch/CustomVideoSpeedBytecodePatch.kt (70%) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.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 deleted file mode 100644 index 4530a92e0..000000000 --- a/src/main/kotlin/app/revanced/patches/shared/patch/options/PatchOptions.kt +++ /dev/null @@ -1,135 +0,0 @@ -package app.revanced.patches.shared.patch.options - -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.Patch -import app.revanced.patcher.patch.* -import app.revanced.patches.shared.annotation.RVXCompatibility - -@Patch -@Name("patch-options") -@Description("Create an options.toml file.") -@RVXCompatibility -@Version("0.0.1") -class PatchOptions : ResourcePatch { - override fun execute(context: ResourceContext): PatchResult { - return PatchResultSuccess() - } - - /* - * Custom Branding Name - */ - - companion object : OptionsContainer() { - - /** - * Custom Branding Name (YouTube) - */ - internal var YouTubeAppName: String? by option( - PatchOption.StringOption( - key = "YouTubeAppName", - default = "ReVanced Extended", - title = "Application Name of YouTube", - description = "The name of the YouTube it will show on your home screen." - ) - ) - - /** - * Custom Package Name (YouTube) - */ - internal var YouTubePackageName: String? by option( - PatchOption.StringOption( - key = "YouTubePackageName", - default = "app.rvx.android.youtube", - title = "Package Name of YouTube", - description = "The package name of the YouTube. (NON-ROOT user only)" - ) - ) - - /** - * Custom Branding Full Name (YouTube Music) - */ - internal var MusicAppNameFull: String? by option( - PatchOption.StringOption( - key = "MusicAppNameFull", - default = "ReVanced Music Extended", - title = "Application Name of YouTube Music", - description = "The name of the YouTube Music it will show on your notification panel." - ) - ) - - /** - * Custom Branding Short Name (YouTube Music) - */ - internal var MusicAppNameShort: String? by option( - PatchOption.StringOption( - key = "MusicAppNameShort", - default = "YTM Extended", - title = "Application Name of YouTube Music", - description = "The name of the YouTube Music it will show on your home screen." - ) - ) - - /** - * Custom Package Name (YouTube Music) - */ - internal var MusicPackageName: String? by option( - PatchOption.StringOption( - key = "MusicPackageName", - default = "app.rvx.android.apps.youtube.music", - title = "Package Name of YouTube Music", - description = "The package name of the YouTube Music. (NON-ROOT user only)" - ) - ) - - /** - * Custom Double-tap to seek Values - */ - internal var CustomDoubleTapLengthArrays: String? by option( - PatchOption.StringOption( - key = "CustomDoubleTapLengthArrays", - default = "3, 5, 10, 15, 20, 30, 60, 120, 180", - title = "Double-tap to seek Values", - description = "A list of custom double-tap to seek lengths. Be sure to separate them with commas (,)." - ) - ) - - /** - * Custom Speed Values - */ - internal var CustomSpeedArrays: String? by option( - PatchOption.StringOption( - key = "CustomSpeedArrays", - default = "0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 3.0, 5.0", - title = "Custom Speed Values", - description = "A list of custom video speeds. Be sure to separate them with commas (,)." - ) - ) - - /** - * Theme - */ - internal var darkThemeBackgroundColor: String? by option( - PatchOption.StringOption( - key = "darkThemeBackgroundColor", - default = "@android:color/black", - title = "Background color for the dark theme", - 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/shared/patch/packagename/PackageNamePatch.kt b/src/main/kotlin/app/revanced/patches/shared/patch/packagename/PackageNamePatch.kt new file mode 100644 index 000000000..710c1753b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/patch/packagename/PackageNamePatch.kt @@ -0,0 +1,47 @@ +package app.revanced.patches.shared.patch.packagename + +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.Patch +import app.revanced.patcher.patch.* +import app.revanced.patches.shared.annotation.RVXCompatibility + +@Patch +@Name("custom-package-name") +@Description("Specifies the package name for YouTube and YT Music in the MicroG build.") +@RVXCompatibility +@Version("0.0.1") +class PackageNamePatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + return PatchResultSuccess() + } + + companion object : OptionsContainer() { + + /** + * Custom Package Name (YouTube) + */ + internal var YouTubePackageName: String? by option( + PatchOption.StringOption( + key = "YouTubePackageName", + default = "app.rvx.android.youtube", + title = "Package Name of YouTube", + description = "The package name of the YouTube. (NON-ROOT user only)" + ) + ) + + /** + * Custom Package Name (YouTube Music) + */ + internal var MusicPackageName: String? by option( + PatchOption.StringOption( + key = "MusicPackageName", + default = "app.rvx.android.apps.youtube.music", + title = "Package Name of YouTube Music", + description = "The package name of the YouTube Music. (NON-ROOT user only)" + ) + ) + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/branding/name/patch/CustomBrandingNamePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/branding/name/patch/CustomBrandingNamePatch.kt index cc1e09662..d784bb469 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/branding/name/patch/CustomBrandingNamePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/branding/name/patch/CustomBrandingNamePatch.kt @@ -5,25 +5,17 @@ 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.* 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.misc.settings.resource.patch.SettingsPatch import app.revanced.util.resources.ResourceHelper.updatePatchStatusLabel import org.w3c.dom.Element @Patch @Name("custom-branding-name") -@DependsOn( - [ - PatchOptions::class, - SettingsPatch::class - ] -) +@DependsOn([SettingsPatch::class]) @Description("Changes the YouTube launcher name to your choice (defaults to ReVanced Extended).") @YouTubeCompatibility @Version("0.0.1") @@ -32,7 +24,7 @@ class CustomBrandingNamePatch : ResourcePatch { // App name val resourceFileNames = arrayOf("strings.xml") - val appName = PatchOptions.YouTubeAppName + val appName = YouTubeAppName context.forEach { if (!it.name.startsWithAny(*resourceFileNames)) return@forEach @@ -58,4 +50,14 @@ class CustomBrandingNamePatch : ResourcePatch { return PatchResultSuccess() } + companion object : OptionsContainer() { + var YouTubeAppName: String? by option( + PatchOption.StringOption( + key = "YouTubeAppName", + default = "ReVanced Extended", + title = "Application Name of YouTube", + description = "The name of the YouTube it will show on your home screen." + ) + ) + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/doubletaplength/patch/DoubleTapLengthPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/doubletaplength/patch/DoubleTapLengthPatch.kt index 0363d3174..3b02d835e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/doubletaplength/patch/DoubleTapLengthPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/doubletaplength/patch/DoubleTapLengthPatch.kt @@ -4,33 +4,27 @@ 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.PatchResultError -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.OptionsContainer +import app.revanced.patcher.patch.* 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.misc.settings.resource.patch.SettingsPatch import app.revanced.util.resources.ResourceHelper.addEntryValues import app.revanced.util.resources.ResourceUtils import app.revanced.util.resources.ResourceUtils.copyResources -import app.revanced.util.resources.ResourceUtils.copyXmlNode @Patch @Name("custom-double-tap-length") @Description("Add 'double-tap to seek' value.") -@DependsOn( - [ - PatchOptions::class, - SettingsPatch::class - ] -) +@DependsOn([SettingsPatch::class]) @YouTubeCompatibility @Version("0.0.1") class DoubleTapLengthPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { + val arrayPath = "res/values-v21/arrays.xml" + val entriesName = "double_tap_length_entries" + val entryValueName = "double_tap_length_values" /** * Copy arrays @@ -43,15 +37,15 @@ class DoubleTapLengthPatch : ResourcePatch { ) ) - val speed = PatchOptions.CustomDoubleTapLengthArrays + val length = DoubleTapLengthArrays ?: return PatchResultError("Invalid double-tap length array.") - val splits = speed.replace(" ","").split(",") - if (splits.isEmpty()) throw IllegalArgumentException("Invalid speed elements") - val speedElements = splits.map { it } + val splits = length.replace(" ","").split(",") + if (splits.isEmpty()) throw IllegalArgumentException("Invalid double-tap length elements") + val lengthElements = splits.map { it } for (index in 0 until splits.count()) { - context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRY_VALUE_NAME) - context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRIES_NAME) + context.addEntryValues(arrayPath, lengthElements[index], entryValueName) + context.addEntryValues(arrayPath, lengthElements[index], entriesName) } SettingsPatch.updatePatchStatus("custom-double-tap-length") @@ -59,9 +53,14 @@ class DoubleTapLengthPatch : ResourcePatch { return PatchResultSuccess() } - private companion object { - private const val TARGET_ARRAY_PATH = "res/values-v21/arrays.xml" - private const val TARGET_ENTRIES_NAME = "double_tap_length_entries" - private const val TARGET_ENTRY_VALUE_NAME = "double_tap_length_values" + companion object : OptionsContainer() { + var DoubleTapLengthArrays: String? by option( + PatchOption.StringOption( + key = "DoubleTapLengthArrays", + default = "3, 5, 10, 15, 20, 30, 60, 120, 180", + title = "Double-tap to seek Values", + description = "A list of custom double-tap to seek lengths. Be sure to separate them with commas (,)." + ) + ) } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/ThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/ThemePatch.kt index 5a953b9da..25a041abd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/ThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/etc/theme/patch/ThemePatch.kt @@ -4,13 +4,10 @@ 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.* 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.patch.GeneralThemePatch.Companion.isMonetPatchIncluded import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme @@ -22,7 +19,6 @@ import org.w3c.dom.Element @DependsOn( [ GeneralThemePatch::class, - PatchOptions::class, SettingsPatch::class ] ) @@ -31,9 +27,7 @@ import org.w3c.dom.Element class ThemePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - arrayOf("values", "values-v31").forEach { - context.setTheme(it) - } + arrayOf("values", "values-v31").forEach { context.setTheme(it) } val currentTheme = if (isMonetPatchIncluded) "mix" else "amoled" @@ -41,22 +35,32 @@ class ThemePatch : ResourcePatch { return PatchResultSuccess() } - private companion object { - private fun ResourceContext.setTheme(valuesPath: String) { - this.xmlEditor["res/$valuesPath/colors.xml"].use { editor -> - val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element - for (i in 0 until resourcesNode.childNodes.length) { - val node = resourcesNode.childNodes.item(i) as? Element ?: continue + private fun ResourceContext.setTheme(valuesPath: String) { + this.xmlEditor["res/$valuesPath/colors.xml"].use { editor -> + val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element - node.textContent = when (node.getAttribute("name")) { - "yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3", - "yt_black4", "yt_status_bar_background_dark", "material_grey_850" -> PatchOptions.darkThemeBackgroundColor!! + for (i in 0 until resourcesNode.childNodes.length) { + val node = resourcesNode.childNodes.item(i) as? Element ?: continue - else -> continue - } + node.textContent = when (node.getAttribute("name")) { + "yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3", + "yt_black4", "yt_status_bar_background_dark", "material_grey_850" -> darkThemeBackgroundColor + + else -> continue } } } } + + companion object : OptionsContainer() { + var darkThemeBackgroundColor: String? by option( + PatchOption.StringOption( + key = "darkThemeBackgroundColor", + default = "@android:color/black", + title = "Background color for the dark theme", + description = "The background color of the dark theme. Can be a hex color or a resource reference." + ) + ) + } } 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 index da4337428..2da402916 100644 --- 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 @@ -5,13 +5,10 @@ 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.* 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 @@ -21,7 +18,6 @@ import org.w3c.dom.Element @Description("Change seekbar color and progressbar color.") @DependsOn( [ - PatchOptions::class, SeekbarColorBytecodePatch::class, SettingsPatch::class ] @@ -31,14 +27,14 @@ import org.w3c.dom.Element class ThemePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - context.xmlEditor[RESOURCE_FILE_PATH].use { + context.xmlEditor["res/drawable/resume_playback_progressbar_drawable.xml"].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!! + attribute.textContent = resumedProgressBarColor } } } @@ -58,7 +54,15 @@ class ThemePatch : ResourcePatch { return PatchResultSuccess() } - private companion object { - const val RESOURCE_FILE_PATH = "res/drawable/resume_playback_progressbar_drawable.xml" + + companion object : OptionsContainer() { + 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/misc/microg/bytecode/patch/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/bytecode/patch/MicroGBytecodePatch.kt index 1f08b9154..46b85db11 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/bytecode/patch/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/bytecode/patch/MicroGBytecodePatch.kt @@ -8,7 +8,7 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.shared.patch.options.PatchOptions +import app.revanced.patches.shared.patch.packagename.PackageNamePatch import app.revanced.patches.youtube.misc.clientspoof.patch.ClientSpoofPatch import app.revanced.patches.youtube.misc.microg.bytecode.fingerprints.* import app.revanced.patches.youtube.misc.microg.shared.Constants.PACKAGE_NAME @@ -19,7 +19,7 @@ import app.revanced.util.microg.MicroGBytecodeHelper @DependsOn( [ ClientSpoofPatch::class, - PatchOptions::class + PackageNamePatch::class ] ) @YouTubeCompatibility @@ -36,7 +36,7 @@ class MicroGBytecodePatch : BytecodePatch( ) { override fun execute(context: BytecodeContext): PatchResult { - val packageName = PatchOptions.YouTubePackageName!! + val packageName = PackageNamePatch.YouTubePackageName!! // apply common microG patch MicroGBytecodeHelper.patchBytecode( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/resource/patch/MicroGPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/resource/patch/MicroGPatch.kt index a400c2e0f..78e37fbcc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/resource/patch/MicroGPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/resource/patch/MicroGPatch.kt @@ -10,7 +10,7 @@ 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.shared.patch.packagename.PackageNamePatch import app.revanced.patches.youtube.misc.microg.bytecode.patch.MicroGBytecodePatch import app.revanced.patches.youtube.misc.microg.shared.Constants.PACKAGE_NAME import app.revanced.patches.youtube.misc.microg.shared.Constants.SPOOFED_PACKAGE_NAME @@ -26,9 +26,9 @@ import app.revanced.util.resources.ResourceHelper.setMicroG @Description("Allows ReVanced to run without root and under a different package name with MicroG.") @DependsOn( [ + PackageNamePatch::class, SettingsPatch::class, MicroGBytecodePatch::class, - PatchOptions::class ] ) @YouTubeCompatibility @@ -36,7 +36,7 @@ import app.revanced.util.resources.ResourceHelper.setMicroG class MicroGPatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - val packageName = PatchOptions.YouTubePackageName!! + val packageName = PackageNamePatch.YouTubePackageName!! /* * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/fingerprints/SpeedArrayGeneratorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/SpeedArrayGeneratorFingerprint.kt similarity index 80% rename from src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/fingerprints/SpeedArrayGeneratorFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/SpeedArrayGeneratorFingerprint.kt index 48fd88602..1f3001d88 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/fingerprints/SpeedArrayGeneratorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/SpeedArrayGeneratorFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.video.customspeed.bytecode.fingerprints +package app.revanced.patches.youtube.video.customspeed.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/video/customspeed/bytecode/fingerprints/SpeedLimiterFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/SpeedLimiterFingerprint.kt similarity index 88% rename from src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/fingerprints/SpeedLimiterFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/SpeedLimiterFingerprint.kt index 3ba4eba29..14d2ab5f8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/fingerprints/SpeedLimiterFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/SpeedLimiterFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.video.customspeed.bytecode.fingerprints +package app.revanced.patches.youtube.video.customspeed.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/video/customspeed/bytecode/fingerprints/VideoSpeedEntriesFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/VideoSpeedEntriesFingerprint.kt similarity index 80% rename from src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/fingerprints/VideoSpeedEntriesFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/VideoSpeedEntriesFingerprint.kt index 74e50f91b..ad52080e9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/fingerprints/VideoSpeedEntriesFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/fingerprints/VideoSpeedEntriesFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.video.customspeed.bytecode.fingerprints +package app.revanced.patches.youtube.video.customspeed.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.Opcode diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/patch/CustomVideoSpeedBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/patch/CustomVideoSpeedBytecodePatch.kt similarity index 70% rename from src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/patch/CustomVideoSpeedBytecodePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/video/customspeed/patch/CustomVideoSpeedBytecodePatch.kt index 877aad973..8538e3649 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/bytecode/patch/CustomVideoSpeedBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/patch/CustomVideoSpeedBytecodePatch.kt @@ -1,22 +1,25 @@ -package app.revanced.patches.youtube.video.customspeed.bytecode.patch +package app.revanced.patches.youtube.video.customspeed.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.extensions.instruction import app.revanced.patcher.extensions.replaceInstruction -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.* import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.annotation.YouTubeCompatibility -import app.revanced.patches.shared.patch.options.PatchOptions -import app.revanced.patches.youtube.video.customspeed.bytecode.fingerprints.* +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch.Companion.contexts +import app.revanced.patches.youtube.video.customspeed.fingerprints.* import app.revanced.util.integrations.Constants.VIDEO_PATH +import app.revanced.util.resources.ResourceHelper.addEntries +import app.revanced.util.resources.ResourceHelper.addEntryValues +import app.revanced.util.resources.ResourceUtils.copyXmlNode import org.jf.dexlib2.builder.instruction.BuilderArrayPayload import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @@ -24,11 +27,13 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.reference.FieldReference import org.jf.dexlib2.iface.reference.MethodReference -@Name("custom-speed-bytecode-patch") -@DependsOn([PatchOptions::class]) +@Patch +@Name("custom-video-speed") +@Description("Adds more video speed options.") +@DependsOn([SettingsPatch::class]) @YouTubeCompatibility @Version("0.0.1") -class CustomVideoSpeedBytecodePatch : BytecodePatch( +class CustomVideoSpeedPatch : BytecodePatch( listOf( SpeedArrayGeneratorFingerprint, SpeedLimiterFingerprint, @@ -36,10 +41,27 @@ class CustomVideoSpeedBytecodePatch : BytecodePatch( ) ) { override fun execute(context: BytecodeContext): PatchResult { - val speed = PatchOptions.CustomSpeedArrays + val arrayPath = "res/values/arrays.xml" + val entriesName = "revanced_custom_video_speed_entry" + val entryValueName = "revanced_custom_video_speed_entry_value" + + val speed = CustomSpeedArrays ?: return PatchResultError("Invalid video speed array.") val splits = speed.replace(" ","").split(",") if (splits.isEmpty()) throw IllegalArgumentException("Invalid speed elements") + + val speedElements = splits.map { it } + for (index in 0 until splits.count()) { + contexts.addEntries( + arrayPath, speedElements[index] + "x", + entriesName + ) + contexts.addEntryValues( + arrayPath, speedElements[index], + entryValueName + ) + } + val videoSpeedsArray = splits.map { it.toFloat().toRawBits() } SpeedArrayGeneratorFingerprint.result?.let { result -> @@ -55,7 +77,7 @@ class CustomVideoSpeedBytecodePatch : BytecodePatch( addInstructions( sizeCallIndex + 2, """ - invoke-static {}, $INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->isCustomVideoSpeedEnabled()Z + invoke-static {}, $VIDEO_PATH/VideoSpeedPatch;->isCustomVideoSpeedEnabled()Z move-result v9 if-eqz v9, :defaultspeed const/4 v$sizeCallResultRegister, 0x0 @@ -67,7 +89,7 @@ class CustomVideoSpeedBytecodePatch : BytecodePatch( val arrayLengthConstDestination = (arrayLengthConst as OneRegisterInstruction).registerA - val videoSpeedsArrayType = "$INTEGRATIONS_VIDEO_SPEED_ENTRIES_CLASS_DESCRIPTOR->videoSpeed:[F" + val videoSpeedsArrayType = "$VIDEO_PATH/VideoSpeedEntries;->videoSpeed:[F" addInstructions( arrayLengthConstIndex + 1, @@ -111,11 +133,11 @@ class CustomVideoSpeedBytecodePatch : BytecodePatch( replaceInstruction( limiterMinConstIndex, - "const/high16 v$limiterMinConstDestination, ${hexFloat(speedLimitMin)}" + "const/high16 v$limiterMinConstDestination, ${hexFloat(0.0f)}" ) replaceInstruction( limiterMaxConstIndex, - "const/high16 v$limiterMaxConstDestination, ${hexFloat(speedLimitMax)}" + "const/high16 v$limiterMaxConstDestination, ${hexFloat(100.0f)}" ) } } ?: return SpeedLimiterFingerprint.toErrorResult() @@ -139,16 +161,36 @@ class CustomVideoSpeedBytecodePatch : BytecodePatch( } } ?: return VideoSpeedEntriesFingerprint.toErrorResult() + + /** + * Copy arrays + */ + contexts.copyXmlNode("youtube/customspeed/host", "values/arrays.xml", "resources") + + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: VIDEO_SETTINGS", + "SETTINGS: CUSTOM_VIDEO_SPEED" + ) + ) + + SettingsPatch.updatePatchStatus("custom-video-speed") + return PatchResultSuccess() } - companion object { - const val INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR = - "$VIDEO_PATH/VideoSpeedPatch;" - const val INTEGRATIONS_VIDEO_SPEED_ENTRIES_CLASS_DESCRIPTOR = - "$VIDEO_PATH/VideoSpeedEntries;" - - const val speedLimitMin = 0.0f - const val speedLimitMax = 100f + companion object : OptionsContainer() { + var CustomSpeedArrays: String? by option( + PatchOption.StringOption( + key = "CustomSpeedArrays", + default = "0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 3.0, 5.0", + title = "Custom Speed Values", + description = "A list of custom video speeds. Be sure to separate them with commas (,)." + ) + ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.kt deleted file mode 100644 index ca1b5a033..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/video/customspeed/resource/patch/CustomVideoSpeedPatch.kt +++ /dev/null @@ -1,71 +0,0 @@ -package app.revanced.patches.youtube.video.customspeed.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.PatchResult -import app.revanced.patcher.patch.PatchResultError -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.misc.settings.resource.patch.SettingsPatch -import app.revanced.patches.youtube.video.customspeed.bytecode.patch.CustomVideoSpeedBytecodePatch -import app.revanced.util.resources.ResourceHelper.addEntries -import app.revanced.util.resources.ResourceHelper.addEntryValues -import app.revanced.util.resources.ResourceUtils.copyXmlNode - -@Patch -@Name("custom-video-speed") -@Description("Adds more video speed options.") -@DependsOn( - [ - CustomVideoSpeedBytecodePatch::class, - PatchOptions::class, - SettingsPatch::class - ] -) -@YouTubeCompatibility -@Version("0.0.1") -class CustomVideoSpeedPatch : ResourcePatch { - override fun execute(context: ResourceContext): PatchResult { - - /* - * Copy arrays - */ - context.copyXmlNode("youtube/customspeed/host", "values/arrays.xml", "resources") - - val speed = PatchOptions.CustomSpeedArrays - ?: return PatchResultError("Invalid video speed array.") - - val splits = speed.replace(" ","").split(",") - if (splits.isEmpty()) throw IllegalArgumentException("Invalid speed elements") - val speedElements = splits.map { it } - for (index in 0 until splits.count()) { - context.addEntries(TARGET_ARRAY_PATH, speedElements[index] + "x", TARGET_ENTRIES_NAME) - context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRY_VALUE_NAME) - } - - /* - * Add settings - */ - SettingsPatch.addPreference( - arrayOf( - "PREFERENCE: VIDEO_SETTINGS", - "SETTINGS: CUSTOM_VIDEO_SPEED" - ) - ) - - SettingsPatch.updatePatchStatus("custom-video-speed") - - return PatchResultSuccess() - } - private companion object { - private const val TARGET_ARRAY_PATH = "res/values/arrays.xml" - private const val TARGET_ENTRIES_NAME = "revanced_custom_video_speed_entry" - private const val TARGET_ENTRY_VALUE_NAME = "revanced_custom_video_speed_entry_value" - } -} \ No newline at end of file