From b3491491d1a6a8f3339e08132b2806342c059f20 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 21 Oct 2023 10:44:20 +0900 Subject: [PATCH] feat(YouTube/Ambient mode switch): add `Disable ambient mode in fullscreen` settings --- ...ModePatch.kt => AmbientModeSwitchPatch.kt} | 35 +++++++++++++++---- .../AmbientModeInFullscreenFingerprint.kt | 11 ++++++ .../youtube/settings/host/values/strings.xml | 5 ++- .../youtube/settings/xml/revanced_prefs.xml | 9 +++-- 4 files changed, 47 insertions(+), 13 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/{PowerSaveModePatch.kt => AmbientModeSwitchPatch.kt} (69%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/AmbientModeInFullscreenFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/PowerSaveModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/AmbientModeSwitchPatch.kt similarity index 69% rename from src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/PowerSaveModePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/AmbientModeSwitchPatch.kt index 35ba23a5f..b627e47a5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/PowerSaveModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/AmbientModeSwitchPatch.kt @@ -8,8 +8,11 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.misc.ambientmode.fingerprints.AmbientModeInFullscreenFingerprint import app.revanced.patches.youtube.misc.ambientmode.fingerprints.PowerSaveModeFingerprint import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.bytecode.getWide32LiteralIndex +import app.revanced.util.integrations.Constants.FULLSCREEN import app.revanced.util.integrations.Constants.MISC_PATH import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -17,8 +20,8 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch( - name = "Bypass ambient mode restrictions", - description = "Bypass ambient mode restrictions in battery saver mode.", + name = "Ambient mode switch", + description = "Bypass the restrictions of ambient mode or disable it completely.", dependencies = [SettingsPatch::class], compatiblePackages = [ CompatiblePackage( @@ -44,8 +47,11 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference ] ) @Suppress("unused") -object PowerSaveModePatch : BytecodePatch( - setOf(PowerSaveModeFingerprint) +object AmbientModeSwitchPatch : BytecodePatch( + setOf( + AmbientModeInFullscreenFingerprint, + PowerSaveModeFingerprint + ) ) { override fun execute(context: BytecodeContext) { @@ -65,7 +71,7 @@ object PowerSaveModePatch : BytecodePatch( addInstructions( insertIndex, """ - invoke-static {v$targetRegister}, $MISC_PATH/PowerSaveModePatch;->bypassPowerSaveModeRestrictions(Z)Z + invoke-static {v$targetRegister}, $MISC_PATH/AmbientModePatch;->bypassPowerSaveModeRestrictions(Z)Z move-result v$targetRegister """ ) @@ -75,16 +81,31 @@ object PowerSaveModePatch : BytecodePatch( } } ?: throw PowerSaveModeFingerprint.exception + AmbientModeInFullscreenFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getWide32LiteralIndex(45389368) + 3 + val targetRegister = getInstruction(targetIndex).registerA + + addInstructions( + targetIndex + 1, """ + invoke-static {}, $FULLSCREEN->disableAmbientMode()Z + move-result v$targetRegister + """ + ) + } + } ?: throw AmbientModeInFullscreenFingerprint.exception + /** * Add settings */ SettingsPatch.addPreference( arrayOf( - "SETTINGS: BYPASS_AMBIENT_MODE_RESTRICTIONS" + "PREFERENCE: FULLSCREEN_SETTINGS", + "SETTINGS: AMBIENT_MODE_SWITCH" ) ) - SettingsPatch.updatePatchStatus("Bypass ambient mode restrictions") + SettingsPatch.updatePatchStatus("Ambient mode switch") } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/AmbientModeInFullscreenFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/AmbientModeInFullscreenFingerprint.kt new file mode 100644 index 000000000..ce4f541f5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/AmbientModeInFullscreenFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.misc.ambientmode.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.util.bytecode.isWide32LiteralExists + +object AmbientModeInFullscreenFingerprint : MethodFingerprint( + returnType = "V", + customFingerprint = { methodDef, _ -> + methodDef.isWide32LiteralExists(45389368) + } +) \ 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 85221648b..527bb4c0e 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -63,6 +63,8 @@ Default video quality on Mobile network Default video quality on Wi-Fi network Description + Disables ambient mode in full screen + Disable ambient mode in fullscreen Always disable ambient mode Disable ambient mode Forced auto captions are enabled @@ -115,9 +117,6 @@ Language switch is disabled Language switch is enabled Enable language switch - New comment popup panels is disabled - New comment popup panels is enabled - Enable new comment popup panels New splash animation is disabled New splash animation is enabled Enable new splash animation diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 4b60a4168..26dd196dc 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -113,6 +113,9 @@ PREFERENCE: FULLSCREEN_SETTINGS --> + + @@ -253,9 +256,9 @@ - + SETTINGS: AMBIENT_MODE_SWITCH --> @@ -368,7 +371,7 @@ - +