2023-09-20 05:33:02 +02:00
|
|
|
package app.revanced.patches.youtube.layout.theme
|
|
|
|
|
2023-12-02 22:35:13 +01:00
|
|
|
import app.revanced.util.exception
|
|
|
|
import app.revanced.util.indexOfFirstWideLiteralInstructionValue
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
2023-10-14 01:00:26 +02:00
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
|
|
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
|
|
|
import app.revanced.patcher.patch.annotation.Patch
|
2023-10-22 23:31:50 +02:00
|
|
|
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
|
2023-10-14 01:00:26 +02:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patches.youtube.layout.seekbar.SeekbarColorBytecodePatch
|
2023-10-14 01:00:26 +02:00
|
|
|
import app.revanced.patches.youtube.layout.theme.fingerprints.UseGradientLoadingScreenFingerprint
|
|
|
|
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
|
|
|
|
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
2023-09-20 05:33:02 +02:00
|
|
|
|
|
|
|
@Patch(
|
|
|
|
name = "Theme",
|
2024-01-01 16:30:04 +01:00
|
|
|
description = "Adds options for theming and applies a custom background theme (dark background theme defaults to amoled black).",
|
2023-10-14 01:00:26 +02:00
|
|
|
dependencies = [
|
|
|
|
LithoColorHookPatch::class,
|
|
|
|
SeekbarColorBytecodePatch::class,
|
|
|
|
ThemeResourcePatch::class,
|
|
|
|
IntegrationsPatch::class,
|
|
|
|
SettingsPatch::class
|
|
|
|
],
|
2023-09-20 05:33:02 +02:00
|
|
|
compatiblePackages = [
|
2023-10-14 01:00:26 +02:00
|
|
|
CompatiblePackage(
|
|
|
|
"com.google.android.youtube",
|
|
|
|
[
|
|
|
|
"18.37.36",
|
2023-11-12 16:43:11 +01:00
|
|
|
"18.38.44",
|
2023-11-12 17:01:49 +01:00
|
|
|
"18.43.45",
|
|
|
|
"18.44.41",
|
2023-12-02 00:07:29 +01:00
|
|
|
"18.45.41",
|
|
|
|
"18.45.43"
|
2023-10-14 01:00:26 +02:00
|
|
|
]
|
|
|
|
)
|
2023-09-20 05:33:02 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
@Suppress("unused")
|
2023-10-14 01:00:26 +02:00
|
|
|
object ThemeBytecodePatch : BytecodePatch(
|
|
|
|
setOf(UseGradientLoadingScreenFingerprint)
|
|
|
|
) {
|
2023-09-20 05:33:02 +02:00
|
|
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
2023-10-14 01:00:26 +02:00
|
|
|
"Lapp/revanced/integrations/patches/theme/ThemePatch;"
|
|
|
|
|
|
|
|
internal const val GRADIENT_LOADING_SCREEN_AB_CONSTANT = 45412406L
|
2023-09-20 05:33:02 +02:00
|
|
|
|
2023-10-24 10:43:15 +02:00
|
|
|
private const val AMOLED_BLACK_COLOR = "@android:color/black"
|
|
|
|
private const val WHITE_COLOR = "@android:color/white"
|
2023-10-22 23:31:50 +02:00
|
|
|
|
2023-09-20 05:33:02 +02:00
|
|
|
internal val darkThemeBackgroundColor by stringPatchOption(
|
|
|
|
key = "darkThemeBackgroundColor",
|
2023-10-22 23:31:50 +02:00
|
|
|
default = AMOLED_BLACK_COLOR,
|
2023-10-22 23:35:28 +02:00
|
|
|
values = mapOf(
|
|
|
|
"Amoled black" to AMOLED_BLACK_COLOR,
|
|
|
|
"Material You" to "@android:color/system_neutral1_900",
|
2023-12-27 05:41:52 +01:00
|
|
|
"Classic (old YouTube)" to "#FF212121",
|
2023-10-22 23:35:28 +02:00
|
|
|
"Catppuccin (Mocha)" to "#FF181825",
|
|
|
|
"Dark pink" to "#FF290025",
|
|
|
|
"Dark blue" to "#FF001029",
|
|
|
|
"Dark green" to "#FF002905",
|
|
|
|
"Dark yellow" to "#FF282900",
|
|
|
|
"Dark orange" to "#FF291800",
|
|
|
|
"Dark red" to "#FF290000"
|
|
|
|
),
|
2023-10-12 02:15:41 +02:00
|
|
|
title = "Dark theme background color",
|
2023-10-22 23:46:41 +02:00
|
|
|
description = "Can be a hex color (#AARRGGBB) or a color resource reference.",
|
2023-09-20 05:33:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
internal val lightThemeBackgroundColor by stringPatchOption(
|
|
|
|
key = "lightThemeBackgroundColor",
|
2023-10-22 23:31:50 +02:00
|
|
|
default = WHITE_COLOR,
|
2023-10-22 23:35:28 +02:00
|
|
|
values = mapOf(
|
|
|
|
"White" to WHITE_COLOR,
|
|
|
|
"Material You" to "@android:color/system_neutral1_50",
|
|
|
|
"Catppuccin (Latte)" to "#FFE6E9EF",
|
|
|
|
"Light pink" to "#FFFCCFF3",
|
|
|
|
"Light blue" to "#FFD1E0FF",
|
|
|
|
"Light green" to "#FFCCFFCC",
|
|
|
|
"Light yellow" to "#FFFDFFCC",
|
|
|
|
"Light orange" to "#FFFFE6CC",
|
|
|
|
"Light red" to "#FFFFD6D6"
|
|
|
|
),
|
2023-10-12 02:15:41 +02:00
|
|
|
title = "Light theme background color",
|
2023-11-06 03:38:49 +01:00
|
|
|
description = "Can be a hex color (#AARRGGBB) or a color resource reference.",
|
2023-09-20 05:33:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
override fun execute(context: BytecodeContext) {
|
2023-10-14 01:00:26 +02:00
|
|
|
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
|
|
|
|
SwitchPreference(
|
|
|
|
"revanced_gradient_loading_screen",
|
|
|
|
StringResource("revanced_gradient_loading_screen_title", "Enable gradient loading screen"),
|
|
|
|
StringResource(
|
|
|
|
"revanced_gradient_loading_screen_summary_on",
|
|
|
|
"Loading screen will have a gradient background"
|
|
|
|
),
|
|
|
|
StringResource(
|
|
|
|
"revanced_gradient_loading_screen_summary_off",
|
|
|
|
"Loading screen will have a solid background"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
UseGradientLoadingScreenFingerprint.result?.mutableMethod?.apply {
|
|
|
|
val isEnabledIndex = indexOfFirstWideLiteralInstructionValue(GRADIENT_LOADING_SCREEN_AB_CONSTANT) + 3
|
|
|
|
val isEnabledRegister = getInstruction<OneRegisterInstruction>(isEnabledIndex - 1).registerA
|
|
|
|
|
|
|
|
addInstructions(
|
|
|
|
isEnabledIndex,
|
|
|
|
"""
|
|
|
|
invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->gradientLoadingScreenEnabled()Z
|
|
|
|
move-result v$isEnabledRegister
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
} ?: throw UseGradientLoadingScreenFingerprint.exception
|
|
|
|
|
2023-09-20 05:33:02 +02:00
|
|
|
LithoColorHookPatch.lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getValue")
|
|
|
|
}
|
|
|
|
}
|