From 2cb1923daa4718a6654cbbee52e3d0d3a8d7b2d5 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 21 Oct 2023 05:25:58 +0900 Subject: [PATCH] feat(YouTube): add `Custom player overlay opacity` patch --- .../CustomPlayerOverlayOpacityPatch.kt | 84 +++++++++++++++++++ .../youtube/settings/host/values/strings.xml | 7 +- .../youtube/settings/xml/revanced_prefs.xml | 6 +- 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt new file mode 100644 index 000000000..a37aeab14 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt @@ -0,0 +1,84 @@ +package app.revanced.patches.youtube.player.playeroverlay + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +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.utils.fingerprints.YouTubeControlsOverlayFingerprint +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ScrimOverlay +import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.PLAYER +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction + +@Patch( + name = "Custom player overlay opacity", + description = "Change the opacity of the player background, when player controls are visible.", + dependencies = [ + SettingsPatch::class, + SharedResourceIdPatch::class + ], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.24.37", + "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" + ] + ) + ] +) +@Suppress("unused") +object CustomPlayerOverlayOpacityPatch : BytecodePatch( + setOf(YouTubeControlsOverlayFingerprint) +) { + override fun execute(context: BytecodeContext) { + + YouTubeControlsOverlayFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getWideLiteralIndex(ScrimOverlay) + 3 + val targetParameter = getInstruction(targetIndex).reference + val targetRegister = getInstruction(targetIndex).registerA + + if (!targetParameter.toString().endsWith("Landroid/widget/ImageView;")) + throw PatchException("Method signature parameter did not match: $targetParameter") + + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $PLAYER->changePlayerOpacity(Landroid/widget/ImageView;)V" + ) + } + } ?: throw YouTubeControlsOverlayFingerprint.exception + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: PLAYER_SETTINGS", + "SETTINGS: CUSTOM_PLAYER_OVERLAY_OPACITY" + ) + ) + + SettingsPatch.updatePatchStatus("Custom player overlay opacity") + + } +} \ 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 32efb82ae..8e0e7d167 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -50,8 +50,13 @@ Add or change available playback speeds Edit custom playback speeds Custom speeds can\'t be more than %sx. Reset to default values. + Opacity value between 0-100, where 0 is transparent + Custom player overlay opacity + Player overlay opacity must be between 0-100. Reset to default values. Type the hex code of the seekbar color Custom seekbar color value + Speed value that changes while holding down + Custom speed overlay To open RVX in an external browser, turn on \'Open supported links\' and enable supported web addresses Open default app settings Default playback speed @@ -98,8 +103,6 @@ Custom seekbar color is disabled Custom seekbar color is enabled Enable custom seekbar color - Edit speed that changes while holding down - Edit custom speed overlay Debug logs are disabled Debug logs are enabled Enable debug logging diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 4a27e9033..cf703beec 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -389,6 +389,7 @@ + @@ -491,8 +492,11 @@ PREFERENCE: PLAYER_SETTINGS --> + + + SETTINGS: CUSTOM_SPEED_OVERLAY -->