From f9c8842c9e35d536fefa332e1e2a1fe7686e1177 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:24:06 -0400 Subject: [PATCH 01/11] fix: Create new merged patch by renaming `Hide player buttons` --- .../player/HidePlayerOverlayButtonsPatch.kt | 74 +++++++++++++++++++ ... HidePlayerOverlayButtonsResourcePatch.kt} | 4 +- ...rolsPreviousNextOverlayTouchFingerprint.kt | 8 +- .../player/hide/HidePlayerButtonsPatch.kt | 67 +---------------- .../resources/addresources/values/strings.xml | 2 +- 5 files changed, 84 insertions(+), 71 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt rename src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/{hide/HidePlayerButtonsResourcePatch.kt => HidePlayerOverlayButtonsResourcePatch.kt} (84%) rename src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/{hide => }/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt (63%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt new file mode 100644 index 0000000000..c843b172d5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt @@ -0,0 +1,74 @@ +package app.revanced.patches.youtube.layout.buttons.player + +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.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.all.misc.resources.AddResourcesPatch +import app.revanced.patches.shared.misc.settings.preference.SwitchPreference +import app.revanced.patches.youtube.layout.buttons.player.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint +import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.SettingsPatch +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow +import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference + +@Patch( + name = "Hide player overlay buttons", + description = "Adds options to hide the player cast button, autoplay button, caption button, next/previous buttons", + dependencies = [ + IntegrationsPatch::class, + SettingsPatch::class, + AddResourcesPatch::class, + HidePlayerOverlayButtonsResourcePatch::class, + ], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.38.44", + "18.49.37", + "19.16.39", + "19.25.37", + "19.34.42", + ] + ) + ] +) +@Suppress("unused") +object HidePlayerOverlayButtonsPatch : BytecodePatch( + setOf(PlayerControlsPreviousNextOverlayTouchFingerprint) +) { + override fun execute(context: BytecodeContext) { + AddResourcesPatch(this::class) + + SettingsPatch.PreferenceScreen.PLAYER.addPreferences( + SwitchPreference("revanced_hide_player_buttons") + ) + + PlayerControlsPreviousNextOverlayTouchFingerprint.resultOrThrow().mutableMethod.apply { + val resourceIndex = indexOfFirstWideLiteralInstructionValueOrThrow( + HidePlayerOverlayButtonsResourcePatch.playerControlPreviousButtonTouchArea + ) + + val insertIndex = indexOfFirstInstructionOrThrow(resourceIndex) { + opcode == Opcode.INVOKE_STATIC + && getReference()?.parameterTypes?.firstOrNull() == "Landroid/view/View;" + } + + val viewRegister = getInstruction(insertIndex).registerC + + addInstruction( + insertIndex, + "invoke-static { v$viewRegister }, Lapp/revanced/integrations/youtube/patches/HidePlayerButtonsPatch;" + + "->hidePreviousNextButtons(Landroid/view/View;)V" + ) + } + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsResourcePatch.kt similarity index 84% rename from src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsResourcePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsResourcePatch.kt index 7bd23b17a1..eb27a43372 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsResourcePatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.buttons.player.hide +package app.revanced.patches.youtube.layout.buttons.player import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.ResourcePatch @@ -6,7 +6,7 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch @Patch(dependencies = [ResourceMappingPatch::class]) -internal object HidePlayerButtonsResourcePatch : ResourcePatch() { +internal object HidePlayerOverlayButtonsResourcePatch : ResourcePatch() { var playerControlPreviousButtonTouchArea = -1L var playerControlNextButtonTouchArea = -1L diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt similarity index 63% rename from src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt index 131bf47130..b310145875 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt @@ -1,8 +1,8 @@ -package app.revanced.patches.youtube.layout.buttons.player.hide.fingerprints +package app.revanced.patches.youtube.layout.buttons.player.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint -import app.revanced.patches.youtube.layout.buttons.player.hide.HidePlayerButtonsResourcePatch +import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsResourcePatch import app.revanced.util.containsWideLiteralInstructionValue import com.android.tools.smali.dexlib2.AccessFlags @@ -12,9 +12,9 @@ internal object PlayerControlsPreviousNextOverlayTouchFingerprint : MethodFinger strings = listOf("1.0x"), customFingerprint = { methodDef, _ -> methodDef.containsWideLiteralInstructionValue( - HidePlayerButtonsResourcePatch.playerControlPreviousButtonTouchArea + HidePlayerOverlayButtonsResourcePatch.playerControlPreviousButtonTouchArea ) && methodDef.containsWideLiteralInstructionValue( - HidePlayerButtonsResourcePatch.playerControlNextButtonTouchArea + HidePlayerOverlayButtonsResourcePatch.playerControlNextButtonTouchArea ) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt index 9581f8f8ac..4a3e5bb356 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt @@ -1,74 +1,13 @@ package app.revanced.patches.youtube.layout.buttons.player.hide 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.annotation.CompatiblePackage -import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.all.misc.resources.AddResourcesPatch -import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.layout.buttons.player.hide.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint -import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.SettingsPatch -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow -import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow -import app.revanced.util.resultOrThrow -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch -@Patch( - name = "Hide player buttons", - description = "Adds an option to hide the previous and next buttons in the video player.", - dependencies = [ - IntegrationsPatch::class, - SettingsPatch::class, - AddResourcesPatch::class, - HidePlayerButtonsResourcePatch::class, - ], - compatiblePackages = [ - CompatiblePackage( - "com.google.android.youtube", - [ - "18.38.44", - "18.49.37", - "19.16.39", - "19.25.37", - "19.34.42", - ] - ) - ] -) -@Suppress("unused") +@Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") object HidePlayerButtonsPatch : BytecodePatch( - setOf(PlayerControlsPreviousNextOverlayTouchFingerprint) + dependencies = setOf(HidePlayerOverlayButtonsPatch::class), ) { override fun execute(context: BytecodeContext) { - AddResourcesPatch(this::class) - - SettingsPatch.PreferenceScreen.PLAYER.addPreferences( - SwitchPreference("revanced_hide_player_buttons") - ) - - PlayerControlsPreviousNextOverlayTouchFingerprint.resultOrThrow().mutableMethod.apply { - val resourceIndex = indexOfFirstWideLiteralInstructionValueOrThrow( - HidePlayerButtonsResourcePatch.playerControlPreviousButtonTouchArea - ) - - val insertIndex = indexOfFirstInstructionOrThrow(resourceIndex) { - opcode == Opcode.INVOKE_STATIC - && getReference()?.parameterTypes?.firstOrNull() == "Landroid/view/View;" - } - - val viewRegister = getInstruction(insertIndex).registerC - - addInstruction( - insertIndex, - "invoke-static { v$viewRegister }, Lapp/revanced/integrations/youtube/patches/HidePlayerButtonsPatch;" + - "->hidePreviousNextButtons(Landroid/view/View;)V" - ) - } } } diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index d08ae90ea1..213e64ff6b 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -518,7 +518,7 @@ This is because Crowdin requires temporarily flattening this file and removing t Watch in VR menu is hidden Watch in VR menu is shown - + Hide previous & next video buttons Buttons are hidden Buttons are shown From 7b1abee6997759ab464b9c8a445d8d4bc189bacd Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:28:09 -0400 Subject: [PATCH 02/11] fix: Merge `Hide cast button patch` --- .../buttons/cast/HideCastButtonPatch.kt | 47 +++---------------- .../player/HidePlayerOverlayButtonsPatch.kt | 30 +++++++++++- .../resources/addresources/values/strings.xml | 8 ++-- 3 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt index aaec98701c..405f09ec73 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt @@ -1,47 +1,14 @@ package app.revanced.patches.youtube.layout.buttons.cast import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions 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.all.misc.resources.AddResourcesPatch -import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.SettingsPatch +import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch -@Patch( - name = "Hide cast button", - description = "Adds an option to hide the cast button in the video player.", - dependencies = [ - IntegrationsPatch::class, - SettingsPatch::class, - AddResourcesPatch::class, - ], - compatiblePackages = [ - CompatiblePackage("com.google.android.youtube"), - ], -) -object HideCastButtonPatch : BytecodePatch(emptySet()) { +@Suppress("unused") +@Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") +object HideCastButtonPatch : BytecodePatch( + dependencies = setOf(HidePlayerOverlayButtonsPatch::class), +) { override fun execute(context: BytecodeContext) { - AddResourcesPatch(this::class) - - SettingsPatch.PreferenceScreen.PLAYER.addPreferences( - SwitchPreference("revanced_hide_cast_button") - ) - - val buttonClass = context.findClass("MediaRouteButton") - ?: throw PatchException("MediaRouteButton class not found.") - - buttonClass.mutableClass.methods.find { it.name == "setVisibility" }?.apply { - addInstructions( - 0, - """ - invoke-static {p1}, Lapp/revanced/integrations/youtube/patches/HideCastButtonPatch;->getCastButtonOverrideV2(I)I - move-result p1 - """, - ) - } ?: throw PatchException("setVisibility method not found.") } -} +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt index c843b172d5..d4937ed087 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt @@ -2,8 +2,10 @@ package app.revanced.patches.youtube.layout.buttons.player import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +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.PatchException import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.all.misc.resources.AddResourcesPatch @@ -45,6 +47,10 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference object HidePlayerOverlayButtonsPatch : BytecodePatch( setOf(PlayerControlsPreviousNextOverlayTouchFingerprint) ) { + + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/youtube/patches/HidePlayerButtonsPatch;" + override fun execute(context: BytecodeContext) { AddResourcesPatch(this::class) @@ -52,6 +58,8 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( SwitchPreference("revanced_hide_player_buttons") ) + // region hide player next/previous button + PlayerControlsPreviousNextOverlayTouchFingerprint.resultOrThrow().mutableMethod.apply { val resourceIndex = indexOfFirstWideLiteralInstructionValueOrThrow( HidePlayerOverlayButtonsResourcePatch.playerControlPreviousButtonTouchArea @@ -66,9 +74,29 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( addInstruction( insertIndex, - "invoke-static { v$viewRegister }, Lapp/revanced/integrations/youtube/patches/HidePlayerButtonsPatch;" + + "invoke-static { v$viewRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR" + "->hidePreviousNextButtons(Landroid/view/View;)V" ) } + + // endregion + + // region hide cast button + + val buttonClass = context.findClass("MediaRouteButton") + ?: throw PatchException("MediaRouteButton class not found.") + + buttonClass.mutableClass.methods.find { it.name == "setVisibility" }?.apply { + addInstructions( + 0, + """ + invoke-static { p1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->getCastButtonOverrideV2(I)I + move-result p1 + """, + ) + } ?: throw PatchException("setVisibility method not found.") + + + // endregion } } diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index 213e64ff6b..b93e946e32 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -441,11 +441,6 @@ This is because Crowdin requires temporarily flattening this file and removing t Captions button is hidden Captions button is shown - - Hide cast button - Cast button is hidden - Cast button is shown - Navigation buttons Hide or change buttons in the navigation bar @@ -522,6 +517,9 @@ This is because Crowdin requires temporarily flattening this file and removing t Hide previous & next video buttons Buttons are hidden Buttons are shown + Hide cast button + Cast button is hidden + Cast button is shown Hide album cards From 50d6af5bc5442a56e15052cab8f42e357f5ddf88 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:34:44 -0400 Subject: [PATCH 03/11] fix: rename integrations class --- .../layout/buttons/player/HidePlayerOverlayButtonsPatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt index d4937ed087..a77aab8d40 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt @@ -49,7 +49,7 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( ) { private const val INTEGRATIONS_CLASS_DESCRIPTOR = - "Lapp/revanced/integrations/youtube/patches/HidePlayerButtonsPatch;" + "Lapp/revanced/integrations/youtube/patches/HidePlayerOverlayButtonsPatch;" override fun execute(context: BytecodeContext) { AddResourcesPatch(this::class) From fb9fadb8fa4c12bf3c39e68df84c68df47b78fce Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:36:35 -0400 Subject: [PATCH 04/11] fix: Merge `Hide captions button` --- .../layout/autocaptions/AutoCaptionsPatch.kt | 2 +- .../captions/HideCaptionsButtonPatch.kt | 53 ++----------------- .../player/HidePlayerOverlayButtonsPatch.kt | 20 ++++++- .../SubtitleButtonControllerFingerprint.kt | 2 +- .../resources/addresources/values/strings.xml | 10 ++-- 5 files changed, 28 insertions(+), 59 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/{layout/autocaptions => shared}/fingerprints/SubtitleButtonControllerFingerprint.kt (91%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt index f5ea004743..3d82a1e412 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt @@ -9,10 +9,10 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.all.misc.resources.AddResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.layout.autocaptions.fingerprints.StartVideoInformerFingerprint -import app.revanced.patches.youtube.layout.autocaptions.fingerprints.SubtitleButtonControllerFingerprint import app.revanced.patches.youtube.layout.autocaptions.fingerprints.SubtitleTrackFingerprint import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch +import app.revanced.patches.youtube.shared.fingerprints.SubtitleButtonControllerFingerprint import app.revanced.util.exception diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt index bf41baa3be..eb1e61d712 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt @@ -1,61 +1,14 @@ package app.revanced.patches.youtube.layout.buttons.captions 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.all.misc.resources.AddResourcesPatch -import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.layout.autocaptions.fingerprints.SubtitleButtonControllerFingerprint -import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.SettingsPatch -import com.android.tools.smali.dexlib2.Opcode +import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch -@Patch( - name = "Hide captions button", - description = "Adds an option to hide the captions button in the video player.", - dependencies = [ - IntegrationsPatch::class, - SettingsPatch::class, - AddResourcesPatch::class - ], - compatiblePackages = [ - CompatiblePackage( - "com.google.android.youtube", - [ - "18.38.44", - "18.49.37", - "19.16.39", - "19.25.37", - "19.34.42", - ] - ) - ] -) @Suppress("unused") +@Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") object HideCaptionsButtonPatch : BytecodePatch( - setOf(SubtitleButtonControllerFingerprint) + dependencies = setOf(HidePlayerOverlayButtonsPatch::class), ) { override fun execute(context: BytecodeContext) { - AddResourcesPatch(this::class) - - SettingsPatch.PreferenceScreen.PLAYER.addPreferences( - SwitchPreference("revanced_hide_captions_button") - ) - - val subtitleButtonControllerMethod = SubtitleButtonControllerFingerprint.result!!.mutableMethod - - // Due to previously applied patches, scanResult index cannot be used in this context - val insertIndex = subtitleButtonControllerMethod.implementation!!.instructions.indexOfFirst { - it.opcode == Opcode.IGET_BOOLEAN - } + 1 - - subtitleButtonControllerMethod.addInstruction( - insertIndex, - """ - invoke-static {v0}, Lapp/revanced/integrations/youtube/patches/HideCaptionsButtonPatch;->hideCaptionsButton(Landroid/widget/ImageView;)V - """ - ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt index a77aab8d40..bccb32c5bc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt @@ -10,9 +10,11 @@ import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.all.misc.resources.AddResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference +import app.revanced.patches.youtube.layout.buttons.captions.HideCaptionsButtonPatch import app.revanced.patches.youtube.layout.buttons.player.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch +import app.revanced.patches.youtube.shared.fingerprints.SubtitleButtonControllerFingerprint import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow @@ -45,7 +47,10 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference ) @Suppress("unused") object HidePlayerOverlayButtonsPatch : BytecodePatch( - setOf(PlayerControlsPreviousNextOverlayTouchFingerprint) + setOf( + PlayerControlsPreviousNextOverlayTouchFingerprint, + SubtitleButtonControllerFingerprint + ) ) { private const val INTEGRATIONS_CLASS_DESCRIPTOR = @@ -96,6 +101,19 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( ) } ?: throw PatchException("setVisibility method not found.") + // endregion + + // region hide captions button + + SubtitleButtonControllerFingerprint.resultOrThrow().mutableMethod.apply { + // Due to previously applied patches, scanResult index cannot be used in this context + val insertIndex = indexOfFirstInstructionOrThrow(Opcode.IGET_BOOLEAN) + 1 + + addInstruction( + insertIndex, + "invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideCaptionsButton(Landroid/widget/ImageView;)V" + ) + } // endregion } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/fingerprints/SubtitleButtonControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shared/fingerprints/SubtitleButtonControllerFingerprint.kt similarity index 91% rename from src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/fingerprints/SubtitleButtonControllerFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/shared/fingerprints/SubtitleButtonControllerFingerprint.kt index 6379cb6707..e840e446b3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/fingerprints/SubtitleButtonControllerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shared/fingerprints/SubtitleButtonControllerFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.autocaptions.fingerprints +package app.revanced.patches.youtube.shared.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index b93e946e32..819bae2e6e 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -435,12 +435,6 @@ This is because Crowdin requires temporarily flattening this file and removing t Autoplay button is hidden Autoplay button is shown - - - Hide captions button - Captions button is hidden - Captions button is shown - Navigation buttons Hide or change buttons in the navigation bar @@ -520,6 +514,10 @@ This is because Crowdin requires temporarily flattening this file and removing t Hide cast button Cast button is hidden Cast button is shown + + Hide captions button + Captions button is hidden + Captions button is shown Hide album cards From de4ae2f9604c08defd08297b2260f5ae4c596ff2 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:40:18 -0400 Subject: [PATCH 05/11] fix typo --- .../layout/buttons/player/HidePlayerOverlayButtonsPatch.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt index bccb32c5bc..0c330c1705 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt @@ -10,7 +10,6 @@ import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.all.misc.resources.AddResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.layout.buttons.captions.HideCaptionsButtonPatch import app.revanced.patches.youtube.layout.buttons.player.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch @@ -60,7 +59,9 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( AddResourcesPatch(this::class) SettingsPatch.PreferenceScreen.PLAYER.addPreferences( - SwitchPreference("revanced_hide_player_buttons") + SwitchPreference("revanced_hide_player_buttons"), + SwitchPreference("revanced_hide_cast_button"), + SwitchPreference("revanced_hide_autoplay_button"), ) // region hide player next/previous button From bda7f477f0ca09fd8a6e8f49334a307183ea3cf7 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:42:51 -0400 Subject: [PATCH 06/11] fix: Merge `Hide autoplay button` --- .../autoplay/HideAutoplayButtonPatch.kt | 78 +------------------ .../player/HidePlayerOverlayButtonsPatch.kt | 36 ++++++++- .../resources/addresources/values/strings.xml | 8 +- 3 files changed, 42 insertions(+), 80 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt index 161a3a2b3c..fbcd703dcc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt @@ -1,84 +1,14 @@ package app.revanced.patches.youtube.layout.buttons.autoplay import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels -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.patcher.util.smali.ExternalLabel -import app.revanced.patches.all.misc.resources.AddResourcesPatch -import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch -import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.SettingsPatch -import app.revanced.patches.youtube.shared.fingerprints.LayoutConstructorFingerprint -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow -import app.revanced.util.indexOfIdResourceOrThrow -import app.revanced.util.resultOrThrow -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch -@Patch( - name = "Hide autoplay button", - description = "Adds an option to hide the autoplay button in the video player.", - dependencies = [ - IntegrationsPatch::class, - SettingsPatch::class, - ResourceMappingPatch::class, - AddResourcesPatch::class, - ], - compatiblePackages = [ - CompatiblePackage( - "com.google.android.youtube", - [ - "18.38.44", - "18.49.37", - "19.16.39", - "19.25.37", - "19.34.42", - ], - ), - ], -) @Suppress("unused") +@Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") object HideAutoplayButtonPatch : BytecodePatch( - setOf(LayoutConstructorFingerprint), + dependencies = setOf(HidePlayerOverlayButtonsPatch::class), ) { - - private const val INTEGRATIONS_CLASS_DESCRIPTOR = - "Lapp/revanced/integrations/youtube/patches/HideAutoplayButtonPatch;" - override fun execute(context: BytecodeContext) { - AddResourcesPatch(this::class) - - SettingsPatch.PreferenceScreen.PLAYER.addPreferences( - SwitchPreference("revanced_hide_autoplay_button"), - ) - - LayoutConstructorFingerprint.resultOrThrow().mutableMethod.apply { - val constIndex = indexOfIdResourceOrThrow("autonav_toggle") - val constRegister = getInstruction(constIndex).registerA - - // Add a conditional branch around the code that inflates and adds the auto repeat button. - val gotoIndex = indexOfFirstInstructionOrThrow(constIndex) { - val parameterTypes = getReference()?.parameterTypes - opcode == Opcode.INVOKE_VIRTUAL && - parameterTypes?.size == 2 && - parameterTypes.first() == "Landroid/view/ViewStub;" - } + 1 - - addInstructionsWithLabels( - constIndex, - """ - invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideAutoPlayButton()Z - move-result v$constRegister - if-nez v$constRegister, :hidden - """, - ExternalLabel("hidden", getInstruction(gotoIndex)), - ) - } } -} +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt index 0c330c1705..f03fa27184 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt @@ -3,23 +3,29 @@ package app.revanced.patches.youtube.layout.buttons.player import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels 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.patcher.util.smali.ExternalLabel import app.revanced.patches.all.misc.resources.AddResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference +import app.revanced.patches.youtube.layout.buttons.autoplay.HideAutoplayButtonPatch import app.revanced.patches.youtube.layout.buttons.player.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch +import app.revanced.patches.youtube.shared.fingerprints.LayoutConstructorFingerprint import app.revanced.patches.youtube.shared.fingerprints.SubtitleButtonControllerFingerprint import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow +import app.revanced.util.indexOfIdResourceOrThrow import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch( @@ -48,7 +54,8 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference object HidePlayerOverlayButtonsPatch : BytecodePatch( setOf( PlayerControlsPreviousNextOverlayTouchFingerprint, - SubtitleButtonControllerFingerprint + SubtitleButtonControllerFingerprint, + LayoutConstructorFingerprint ) ) { @@ -117,5 +124,32 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( } // endregion + + // region hide auto play button + + LayoutConstructorFingerprint.resultOrThrow().mutableMethod.apply { + val constIndex = indexOfIdResourceOrThrow("autonav_toggle") + val constRegister = getInstruction(constIndex).registerA + + // Add a conditional branch around the code that inflates and adds the auto repeat button. + val gotoIndex = indexOfFirstInstructionOrThrow(constIndex) { + val parameterTypes = getReference()?.parameterTypes + opcode == Opcode.INVOKE_VIRTUAL && + parameterTypes?.size == 2 && + parameterTypes.first() == "Landroid/view/ViewStub;" + } + 1 + + addInstructionsWithLabels( + constIndex, + """ + invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideAutoPlayButton()Z + move-result v$constRegister + if-nez v$constRegister, :hidden + """, + ExternalLabel("hidden", getInstruction(gotoIndex)), + ) + } + + // endregion } } diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index 819bae2e6e..b4fe8d03f4 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -430,11 +430,6 @@ This is because Crowdin requires temporarily flattening this file and removing t Save to playlist button is hidden Save to playlist button is shown - - Hide autoplay button - Autoplay button is hidden - Autoplay button is shown - Navigation buttons Hide or change buttons in the navigation bar @@ -518,6 +513,9 @@ This is because Crowdin requires temporarily flattening this file and removing t Hide captions button Captions button is hidden Captions button is shown + Hide autoplay button + Autoplay button is hidden + Autoplay button is shown Hide album cards From 916601096de73963a3ead4cb9176871310f15191 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:51:17 -0400 Subject: [PATCH 07/11] refactor: Adjust package name --- api/revanced-patches.api | 6 ++++++ .../layout/buttons/autoplay/HideAutoplayButtonPatch.kt | 2 +- .../layout/buttons/captions/HideCaptionsButtonPatch.kt | 2 +- .../youtube/layout/buttons/cast/HideCastButtonPatch.kt | 2 +- .../{player => overlay}/HidePlayerOverlayButtonsPatch.kt | 6 +++--- .../HidePlayerOverlayButtonsResourcePatch.kt | 2 +- .../PlayerControlsPreviousNextOverlayTouchFingerprint.kt | 4 ++-- .../layout/buttons/player/hide/HidePlayerButtonsPatch.kt | 4 ++-- src/main/resources/addresources/values/strings.xml | 2 +- 9 files changed, 18 insertions(+), 12 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/layout/buttons/{player => overlay}/HidePlayerOverlayButtonsPatch.kt (95%) rename src/main/kotlin/app/revanced/patches/youtube/layout/buttons/{player => overlay}/HidePlayerOverlayButtonsResourcePatch.kt (93%) rename src/main/kotlin/app/revanced/patches/youtube/layout/buttons/{player => overlay}/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt (81%) diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 152dc8346f..0b4976b98e 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1670,6 +1670,12 @@ public final class app/revanced/patches/youtube/layout/buttons/navigation/Naviga public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt index fbcd703dcc..a322b755d1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt @@ -2,7 +2,7 @@ package app.revanced.patches.youtube.layout.buttons.autoplay import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch +import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch @Suppress("unused") @Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt index eb1e61d712..200f8e5ffa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/HideCaptionsButtonPatch.kt @@ -2,7 +2,7 @@ package app.revanced.patches.youtube.layout.buttons.captions import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch +import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch @Suppress("unused") @Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt index 405f09ec73..7a8aec8d14 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/cast/HideCastButtonPatch.kt @@ -2,7 +2,7 @@ package app.revanced.patches.youtube.layout.buttons.cast import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch +import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch @Suppress("unused") @Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt similarity index 95% rename from src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt index f03fa27184..cea5b8916b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.buttons.player +package app.revanced.patches.youtube.layout.buttons.overlay import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction @@ -12,8 +12,7 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.all.misc.resources.AddResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference -import app.revanced.patches.youtube.layout.buttons.autoplay.HideAutoplayButtonPatch -import app.revanced.patches.youtube.layout.buttons.player.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint +import app.revanced.patches.youtube.layout.buttons.overlay.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch import app.revanced.patches.youtube.shared.fingerprints.LayoutConstructorFingerprint @@ -68,6 +67,7 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( SettingsPatch.PreferenceScreen.PLAYER.addPreferences( SwitchPreference("revanced_hide_player_buttons"), SwitchPreference("revanced_hide_cast_button"), + SwitchPreference("revanced_hide_captions_button"), SwitchPreference("revanced_hide_autoplay_button"), ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsResourcePatch.kt similarity index 93% rename from src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsResourcePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsResourcePatch.kt index eb27a43372..4b997d7891 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/HidePlayerOverlayButtonsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsResourcePatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.layout.buttons.player +package app.revanced.patches.youtube.layout.buttons.overlay import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.ResourcePatch diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt similarity index 81% rename from src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt index b310145875..46270b516e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/fingerprints/PlayerControlsPreviousNextOverlayTouchFingerprint.kt @@ -1,8 +1,8 @@ -package app.revanced.patches.youtube.layout.buttons.player.fingerprints +package app.revanced.patches.youtube.layout.buttons.overlay.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint -import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsResourcePatch +import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsResourcePatch import app.revanced.util.containsWideLiteralInstructionValue import com.android.tools.smali.dexlib2.AccessFlags diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt index 4a3e5bb356..e8707a39b9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch.kt @@ -2,7 +2,7 @@ package app.revanced.patches.youtube.layout.buttons.player.hide import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patches.youtube.layout.buttons.player.HidePlayerOverlayButtonsPatch +import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch @Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.") object HidePlayerButtonsPatch : BytecodePatch( @@ -10,4 +10,4 @@ object HidePlayerButtonsPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { } -} +} \ No newline at end of file diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index b4fe8d03f4..7c5fae0b67 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -502,7 +502,7 @@ This is because Crowdin requires temporarily flattening this file and removing t Watch in VR menu is hidden Watch in VR menu is shown - + Hide previous & next video buttons Buttons are hidden Buttons are shown From 6f4c722cea1bc5dff5b48c7910eb20b714ab22d4 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 00:56:25 -0400 Subject: [PATCH 08/11] fix: Use more descriptive key for hide previous/next --- .../layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt | 2 +- src/main/resources/addresources/values/strings.xml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt index cea5b8916b..aac2aa59a2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt @@ -65,7 +65,7 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( AddResourcesPatch(this::class) SettingsPatch.PreferenceScreen.PLAYER.addPreferences( - SwitchPreference("revanced_hide_player_buttons"), + SwitchPreference("revanced_hide_player_previous_next_buttons"), SwitchPreference("revanced_hide_cast_button"), SwitchPreference("revanced_hide_captions_button"), SwitchPreference("revanced_hide_autoplay_button"), diff --git a/src/main/resources/addresources/values/strings.xml b/src/main/resources/addresources/values/strings.xml index 7c5fae0b67..fab3feb621 100644 --- a/src/main/resources/addresources/values/strings.xml +++ b/src/main/resources/addresources/values/strings.xml @@ -503,9 +503,9 @@ This is because Crowdin requires temporarily flattening this file and removing t Watch in VR menu is shown - Hide previous & next video buttons - Buttons are hidden - Buttons are shown + Hide previous & next video buttons + Buttons are hidden + Buttons are shown Hide cast button Cast button is hidden Cast button is shown From aa79e5c2b8b99fcf083cbf258068c7f5235fbd1c Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 01:15:59 -0400 Subject: [PATCH 09/11] fix: Use new patch --- .../revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt index 5ecd694f8d..e8f72052cf 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt @@ -2,7 +2,7 @@ package app.revanced.patches.youtube.misc.gms import app.revanced.patches.shared.fingerprints.CastContextFetchFingerprint import app.revanced.patches.shared.misc.gms.BaseGmsCoreSupportPatch -import app.revanced.patches.youtube.layout.buttons.cast.HideCastButtonPatch +import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch import app.revanced.patches.youtube.misc.fix.playback.SpoofVideoStreamsPatch import app.revanced.patches.youtube.misc.gms.Constants.REVANCED_YOUTUBE_PACKAGE_NAME import app.revanced.patches.youtube.misc.gms.Constants.YOUTUBE_PACKAGE_NAME @@ -22,7 +22,7 @@ object GmsCoreSupportPatch : BaseGmsCoreSupportPatch( mainActivityOnCreateFingerprint = MainActivityOnCreateFingerprint, integrationsPatchDependency = IntegrationsPatch::class, dependencies = setOf( - HideCastButtonPatch::class, + HidePlayerOverlayButtonsPatch::class, // Hide non functional cast button. SpoofVideoStreamsPatch::class, ), gmsCoreSupportResourcePatch = GmsCoreSupportResourcePatch, From 56cc65a9de0b3b11a5293ccbb2afe1259d1f680f Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 22 Oct 2024 04:46:39 -0400 Subject: [PATCH 10/11] refactor: Use a fingerprint --- .../overlay/HidePlayerOverlayButtonsPatch.kt | 22 ++++++++----------- .../MediaRouteButtonFingerprint.kt | 10 +++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/fingerprints/MediaRouteButtonFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt index aac2aa59a2..ab17e042d7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt @@ -6,12 +6,12 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels 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.patcher.util.smali.ExternalLabel import app.revanced.patches.all.misc.resources.AddResourcesPatch import app.revanced.patches.shared.misc.settings.preference.SwitchPreference +import app.revanced.patches.youtube.layout.buttons.overlay.fingerprints.MediaRouteButtonFingerprint import app.revanced.patches.youtube.layout.buttons.overlay.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch @@ -53,6 +53,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference object HidePlayerOverlayButtonsPatch : BytecodePatch( setOf( PlayerControlsPreviousNextOverlayTouchFingerprint, + MediaRouteButtonFingerprint, SubtitleButtonControllerFingerprint, LayoutConstructorFingerprint ) @@ -96,18 +97,13 @@ object HidePlayerOverlayButtonsPatch : BytecodePatch( // region hide cast button - val buttonClass = context.findClass("MediaRouteButton") - ?: throw PatchException("MediaRouteButton class not found.") - - buttonClass.mutableClass.methods.find { it.name == "setVisibility" }?.apply { - addInstructions( - 0, - """ - invoke-static { p1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->getCastButtonOverrideV2(I)I - move-result p1 - """, - ) - } ?: throw PatchException("setVisibility method not found.") + MediaRouteButtonFingerprint.resultOrThrow().mutableMethod.addInstructions( + 0, + """ + invoke-static { p1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->getCastButtonOverrideV2(I)I + move-result p1 + """ + ) // endregion diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/fingerprints/MediaRouteButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/fingerprints/MediaRouteButtonFingerprint.kt new file mode 100644 index 0000000000..69e2815452 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/fingerprints/MediaRouteButtonFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.youtube.layout.buttons.overlay.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object MediaRouteButtonFingerprint : MethodFingerprint ( + parameters = listOf("I"), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/MediaRouteButton;") && methodDef.name == "setVisibility" + } +) \ No newline at end of file From a98c95c5fdf4c5987c6548a58ffa19d3d173fa1e Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 23 Oct 2024 00:30:15 +0200 Subject: [PATCH 11/11] Apply suggestions from code review --- .../layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt index ab17e042d7..1cc48c63f1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt @@ -29,7 +29,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch( name = "Hide player overlay buttons", - description = "Adds options to hide the player cast button, autoplay button, caption button, next/previous buttons", + description = "Adds options to hide the player cast, autoplay, caption button and next/ previous buttons.", dependencies = [ IntegrationsPatch::class, SettingsPatch::class,