From 2a5514a6b3df076d5bc2cdc4459df30bca18f396 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 25 Oct 2023 01:46:47 +0200 Subject: [PATCH] feat(YouTube): Add `Disable fullscreen ambient mode` patch --- .../DisableFullscreenAmbientModePatch.kt | 66 +++++++++++++++++++ .../InitializeAmbientModeFingerprint.kt | 13 ++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/fingerprints/InitializeAmbientModeFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt new file mode 100644 index 000000000..f9caf813e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt @@ -0,0 +1,66 @@ +package app.revanced.patches.youtube.layout.hide.fullscreenambientmode + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.settings.preference.impl.StringResource +import app.revanced.patches.shared.settings.preference.impl.SwitchPreference +import app.revanced.patches.youtube.layout.hide.fullscreenambientmode.fingerprints.InitializeAmbientModeFingerprint +import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.SettingsPatch + +@Patch( + name = "Disable fullscreen ambient mode", + description = "Disables the ambient mode when in fullscreen.", + dependencies = [IntegrationsPatch::class, SettingsPatch::class, IntegrationsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", [ + "18.37.36", + "18.38.44" + ] + ) + ] +) +@Suppress("unused") +object DisableFullscreenAmbientModePatch : BytecodePatch( + setOf(InitializeAmbientModeFingerprint) +) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/patches/DisableFullscreenAmbientModePatch;" + + override fun execute(context: BytecodeContext) { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_disable_fullscreen_ambient_mode", + StringResource( + "revanced_disable_fullscreen_ambient_mode_title", + "Disable ambient mode in fullscreen" + ), + StringResource( + "revanced_disable_fullscreen_ambient_mode_summary_on", + "Ambient mode disabled" + ), + StringResource( + "revanced_disable_fullscreen_ambient_mode_summary_off", + "Ambient mode enabled" + ), + ) + ) + + InitializeAmbientModeFingerprint.result?.let { + it.mutableMethod.apply { + val moveIsEnabledIndex = it.scanResult.patternScanResult!!.endIndex + + addInstruction( + moveIsEnabledIndex, + "invoke-static { }, " + + "$INTEGRATIONS_CLASS_DESCRIPTOR->enableFullScreenAmbientMode()Z" + ) + } + } ?: throw InitializeAmbientModeFingerprint.exception + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/fingerprints/InitializeAmbientModeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/fingerprints/InitializeAmbientModeFingerprint.kt new file mode 100644 index 000000000..0bd78d8de --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/fingerprints/InitializeAmbientModeFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.layout.hide.fullscreenambientmode.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.util.patch.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object InitializeAmbientModeFingerprint : LiteralValueFingerprint( + returnType = "V", + accessFlags = AccessFlags.CONSTRUCTOR or AccessFlags.PUBLIC, + opcodes = listOf(Opcode.MOVE_RESULT), + literalSupplier = { 45389368 } +) \ No newline at end of file