2023-09-20 05:33:02 +02:00
|
|
|
package app.revanced.patches.youtube.layout.theme
|
|
|
|
|
2023-10-14 01:00:26 +02:00
|
|
|
import app.revanced.extensions.exception
|
|
|
|
import app.revanced.extensions.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
|
|
|
|
import app.revanced.patcher.patch.options.types.StringPatchOption.Companion.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",
|
|
|
|
description = "Applies a custom theme.",
|
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-10-14 13:27:27 +02:00
|
|
|
"18.38.44"
|
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
|
|
|
|
|
|
|
internal val darkThemeBackgroundColor by stringPatchOption(
|
|
|
|
key = "darkThemeBackgroundColor",
|
|
|
|
default = "@android:color/black",
|
2023-10-12 02:15:41 +02:00
|
|
|
title = "Dark theme background color",
|
2023-09-20 05:33:02 +02:00
|
|
|
description = "The background color of the dark theme. Can be a hex color or a resource reference.",
|
|
|
|
)
|
|
|
|
|
|
|
|
internal val lightThemeBackgroundColor by stringPatchOption(
|
|
|
|
key = "lightThemeBackgroundColor",
|
|
|
|
default = "@android:color/white",
|
2023-10-12 02:15:41 +02:00
|
|
|
title = "Light theme background color",
|
2023-09-20 05:33:02 +02:00
|
|
|
description = "The background color of the light theme. Can be a hex color or a resource reference.",
|
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|