From d701a9acb6a45cd29fd356862b78fd4563ed152a Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:23:14 +0900 Subject: [PATCH] feat(YouTube): add `Enable bottom player gestures` patch --- .../gestures/BottomPlayerGesturesPatch.kt | 79 +++++++++++++++++++ .../BottomPlayerGesturesFingerprint.kt | 8 ++ .../youtube/utils/integrations/Constants.kt | 2 + .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 5 ++ 5 files changed, 97 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/BottomPlayerGesturesPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/fingerprints/BottomPlayerGesturesFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/BottomPlayerGesturesPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/BottomPlayerGesturesPatch.kt new file mode 100644 index 000000000..e0c28b19a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/BottomPlayerGesturesPatch.kt @@ -0,0 +1,79 @@ +package app.revanced.patches.youtube.buttomplayer.gestures + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.buttomplayer.gestures.fingerprints.BottomPlayerGesturesFingerprint +import app.revanced.patches.youtube.utils.integrations.Constants.BOTTOM_PLAYER +import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.exception +import app.revanced.util.getWideLiteralInstructionIndex +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch( + name = "Enable bottom player gestures", + description = "Switching to fullscreen by swiping the bottom area of the player.", + dependencies = [SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.25.40", + "18.27.36", + "18.29.38", + "18.30.37", + "18.31.40", + "18.32.39", + "18.33.40", + "18.34.38", + "18.35.36", + "18.36.39", + "18.37.36", + "18.38.44", + "18.39.41", + "18.40.34", + "18.41.39", + "18.42.41", + "18.43.45", + "18.44.41", + "18.45.43" + ] + ) + ] +) +@Suppress("unused") +object BottomPlayerGesturesPatch : BytecodePatch( + setOf(BottomPlayerGesturesFingerprint) +) { + override fun execute(context: BytecodeContext) { + + BottomPlayerGesturesFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getWideLiteralInstructionIndex(45372793) + 3 + val targetRegister = getInstruction(targetIndex).registerA + + addInstructions( + targetIndex + 1, """ + invoke-static {}, $BOTTOM_PLAYER->enableBottomPlayerGestures()Z + move-result v$targetRegister + """ + ) + } + } ?: throw BottomPlayerGesturesFingerprint.exception + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: BOTTOM_PLAYER_SETTINGS", + "SETTINGS: ENABLE_BOTTOM_PLAYER_GESTURES" + ) + ) + + SettingsPatch.updatePatchStatus("Enable bottom player gestures") + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/fingerprints/BottomPlayerGesturesFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/fingerprints/BottomPlayerGesturesFingerprint.kt new file mode 100644 index 000000000..ecce689b7 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/gestures/fingerprints/BottomPlayerGesturesFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.buttomplayer.gestures.fingerprints + +import app.revanced.util.fingerprint.LiteralValueFingerprint + +object BottomPlayerGesturesFingerprint : LiteralValueFingerprint( + returnType = "V", + literalSupplier = { 45372793 } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/integrations/Constants.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/integrations/Constants.kt index 0a391c31c..ca84f07ff 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/integrations/Constants.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/integrations/Constants.kt @@ -7,6 +7,7 @@ object Constants { const val ADS_PATH = "$PATCHES_PATH/ads" const val ALTERNATIVE_THUMBNAILS_PATH = "$PATCHES_PATH/alternativethumbnails" + const val BOTTOM_PLAYER_PATH = "$PATCHES_PATH/bottomplayer" const val COMPONENTS_PATH = "$PATCHES_PATH/components" const val FLYOUT_PANEL_PATH = "$PATCHES_PATH/flyoutpanel" const val FULLSCREEN_PATH = "$PATCHES_PATH/fullscreen" @@ -22,6 +23,7 @@ object Constants { const val VIDEO_PATH = "$PATCHES_PATH/video" const val ALTERNATIVE_THUMBNAILS = "$ALTERNATIVE_THUMBNAILS_PATH/AlternativeThumbnailsPatch;" + const val BOTTOM_PLAYER = "$BOTTOM_PLAYER_PATH/BottomPlayerPatch;" const val FLYOUT_PANEL = "$FLYOUT_PANEL_PATH/FlyoutPanelPatch;" const val FULLSCREEN = "$FULLSCREEN_PATH/FullscreenPatch;" const val GENERAL = "$GENERAL_PATH/GeneralPatch;" diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 3d8ebf0be..998d84c3b 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -135,6 +135,9 @@ Note: Disabling the speed overlay restores the 'Slide to seek' behavior of the o Disable shorts player at app startup The amount of seconds the double press back to exit. Double back timeout + Switching to fullscreen by swiping the bottom area of the player has been disabled. + Switching to fullscreen by swiping the bottom area of the player has been enabled. + Enable bottom player gestures Compact controls overlay is disabled. Compact controls overlay is enabled. Enable compact controls overlay diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 2d45c8d10..97e90cb97 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -51,6 +51,10 @@ + +