From 2622b008ab78b15aa3c28a13b38e63041f29c9ea Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Sat, 26 Aug 2023 05:12:30 +0500 Subject: [PATCH] feat(YouTube): Add `Custom player overlay opacity` patch (#2721) This gets rid of the `Hide player overlay` patch. Co-authored-by: oSumAtrIX --- .../PlayerOverlayPatchCompatibility.kt} | 4 +-- .../CreatePlayerOverviewFingerprint.kt | 6 ++--- .../patch/CustomPlayerOverlayOpacityPatch.kt} | 27 ++++++++++--------- ...ustomPlayerOverlayOpacityResourcePatch.kt} | 27 ++++++++++++------- 4 files changed, 36 insertions(+), 28 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/layout/{hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt => player/overlay/annotations/PlayerOverlayPatchCompatibility.kt} (57%) rename src/main/kotlin/app/revanced/patches/youtube/layout/{hide => }/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt (66%) rename src/main/kotlin/app/revanced/patches/youtube/layout/{hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt => player/overlay/bytecode/patch/CustomPlayerOverlayOpacityPatch.kt} (52%) rename src/main/kotlin/app/revanced/patches/youtube/layout/{hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt => player/overlay/resource/patch/CustomPlayerOverlayOpacityResourcePatch.kt} (50%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/annotations/PlayerOverlayPatchCompatibility.kt similarity index 57% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/annotations/PlayerOverlayPatchCompatibility.kt index 9ca55f523..71d89ce7e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/annotations/HidePlayerOverlayPatchCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/annotations/PlayerOverlayPatchCompatibility.kt @@ -1,8 +1,8 @@ -package app.revanced.patches.youtube.layout.hide.player.overlay.annotations +package app.revanced.patches.youtube.layout.player.overlay.annotations import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Package @Compatibility([Package("com.google.android.youtube")]) @Target(AnnotationTarget.CLASS) -internal annotation class HidePlayerOverlayPatchCompatibility +internal annotation class PlayerOverlayPatchCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt similarity index 66% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt index 785577eac..ec617403e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt @@ -1,9 +1,9 @@ -package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints +package app.revanced.patches.youtube.layout.player.overlay.bytecode.fingerprints import app.revanced.extensions.containsConstantInstructionValue import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch +import app.revanced.patches.youtube.layout.player.overlay.resource.patch.CustomPlayerOverlayOpacityResourcePatch import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode @@ -17,6 +17,6 @@ object CreatePlayerOverviewFingerprint : MethodFingerprint( Opcode.CHECK_CAST ), customFingerprint = { methodDef, _ -> - methodDef.containsConstantInstructionValue(HidePlayerOverlayResourcePatch.scrimOverlayId) + methodDef.containsConstantInstructionValue(CustomPlayerOverlayOpacityResourcePatch.scrimOverlayId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/bytecode/patch/CustomPlayerOverlayOpacityPatch.kt similarity index 52% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/bytecode/patch/CustomPlayerOverlayOpacityPatch.kt index f9582806c..cbb46b92a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/bytecode/patch/CustomPlayerOverlayOpacityPatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.patch +package app.revanced.patches.youtube.layout.player.overlay.bytecode.patch import app.revanced.extensions.indexOfFirstConstantInstructionValue import app.revanced.extensions.exception @@ -10,35 +10,36 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility -import app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints.CreatePlayerOverviewFingerprint -import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch +import app.revanced.patches.youtube.layout.player.overlay.annotations.PlayerOverlayPatchCompatibility +import app.revanced.patches.youtube.layout.player.overlay.bytecode.fingerprints.CreatePlayerOverviewFingerprint +import app.revanced.patches.youtube.layout.player.overlay.resource.patch.CustomPlayerOverlayOpacityResourcePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch -@Name("Hide player overlay") -@Description("Hides the dark background overlay from the player when player controls are visible.") -@DependsOn([HidePlayerOverlayResourcePatch::class]) -@HidePlayerOverlayPatchCompatibility -class HidePlayerOverlayPatch : BytecodePatch(listOf(CreatePlayerOverviewFingerprint)) { +@Name("Custom player overlay opacity") +@Description("Change the opacity of the player background, when player controls are visible.") +@DependsOn([CustomPlayerOverlayOpacityResourcePatch::class]) +@PlayerOverlayPatchCompatibility +class CustomPlayerOverlayOpacityPatch : BytecodePatch(listOf(CreatePlayerOverviewFingerprint)) { override fun execute(context: BytecodeContext) { CreatePlayerOverviewFingerprint.result?.let { result -> result.mutableMethod.apply { val viewRegisterIndex = - indexOfFirstConstantInstructionValue(HidePlayerOverlayResourcePatch.scrimOverlayId) + 3 - val viewRegister = getInstruction(viewRegisterIndex).registerA + indexOfFirstConstantInstructionValue(CustomPlayerOverlayOpacityResourcePatch.scrimOverlayId) + 3 + val viewRegister = + getInstruction(viewRegisterIndex).registerA val insertIndex = viewRegisterIndex + 1 addInstruction( insertIndex, "invoke-static { v$viewRegister }, " + - "$INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" + "$INTEGRATIONS_CLASS_DESCRIPTOR->changeOpacity(Landroid/widget/ImageView;)V" ) } } ?: throw CreatePlayerOverviewFingerprint.exception } private companion object { - const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" + const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/CustomPlayerOverlayOpacityPatch;" } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/resource/patch/CustomPlayerOverlayOpacityResourcePatch.kt similarity index 50% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/resource/patch/CustomPlayerOverlayOpacityResourcePatch.kt index cc794c4dc..e868a8e20 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/resource/patch/CustomPlayerOverlayOpacityResourcePatch.kt @@ -1,22 +1,29 @@ -package app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch +package app.revanced.patches.youtube.layout.player.overlay.resource.patch import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch +import app.revanced.patches.shared.settings.preference.impl.InputType import app.revanced.patches.shared.settings.preference.impl.StringResource -import app.revanced.patches.shared.settings.preference.impl.SwitchPreference +import app.revanced.patches.shared.settings.preference.impl.TextPreference import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) -class HidePlayerOverlayResourcePatch : ResourcePatch { +class CustomPlayerOverlayOpacityResourcePatch : ResourcePatch { override fun execute(context: ResourceContext) { SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( - SwitchPreference( - "revanced_hide_player_overlay", - StringResource("revanced_hide_player_overlay_title", "Hide background overlay in player"), - StringResource("revanced_hide_player_overlay_summary_on", "Background overlay is hidden"), - StringResource("revanced_hide_player_overlay_summary_off", "Background overlay is shown") + TextPreference( + "revanced_player_overlay_opacity", + StringResource( + "revanced_player_overlay_opacity_title", + "Player overlay opacity" + ), + StringResource( + "revanced_player_overlay_opacity_summary", + "Opacity value between 0-100, where 0 is transparent" + ), + InputType.NUMBER ) ) @@ -26,6 +33,6 @@ class HidePlayerOverlayResourcePatch : ResourcePatch { } internal companion object { - var scrimOverlayId: Long = -1 + var scrimOverlayId = -1L } -} \ No newline at end of file +}