From b03dee0549933a6589d431a9b1c5c3f0d43f877b Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 23 Jul 2023 01:11:59 +0900 Subject: [PATCH] feat(youtube): add `hide-suggested-video-overlay` patch --- .../patch/HideFilmstripOverlayPatch.kt | 1 + .../CoreConatinerBuilderFingerprint.kt | 17 ++++ .../patch/SuggestedVideoOverlayPatch.kt | 81 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 2 + .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 8 +- 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreConatinerBuilderFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/patch/SuggestedVideoOverlayPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/patch/HideFilmstripOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/patch/HideFilmstripOverlayPatch.kt index 8a6b33b138..4573cde627 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/patch/HideFilmstripOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/patch/HideFilmstripOverlayPatch.kt @@ -116,6 +116,7 @@ class HideFilmstripOverlayPatch : BytecodePatch( SettingsPatch.addPreference( arrayOf( "PREFERENCE: PLAYER_SETTINGS", + "SETTINGS: PLAYER_EXPERIMENTAL_FLAGS", "SETTINGS: HIDE_FILMSTRIP_OVERLAY" ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreConatinerBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreConatinerBuilderFingerprint.kt new file mode 100644 index 0000000000..a8639f0e05 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreConatinerBuilderFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.player.suggestedvideooverlay.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.CoreContainer +import app.revanced.util.bytecode.isWideLiteralExists +import org.jf.dexlib2.AccessFlags + +object CoreConatinerBuilderFingerprint : MethodFingerprint( + returnType = "Landroid/view/View;", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Landroid/content/Context;"), + customFingerprint = { methodDef, _ -> + methodDef.isWideLiteralExists( + CoreContainer + ) + }) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/patch/SuggestedVideoOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/patch/SuggestedVideoOverlayPatch.kt new file mode 100644 index 0000000000..05aefd36c2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/patch/SuggestedVideoOverlayPatch.kt @@ -0,0 +1,81 @@ +package app.revanced.patches.youtube.player.suggestedvideooverlay.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +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.PatchResult +import app.revanced.patcher.patch.PatchResultError +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.youtube.player.suggestedvideooverlay.fingerprints.CoreConatinerBuilderFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.CoreContainer +import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getWideLiteralIndex +import app.revanced.util.integrations.Constants.PLAYER +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch +@Name("Hide suggested video overlay") +@Description("Hide the suggested video overlay to play next.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class SuggestedVideoOverlayPatch : BytecodePatch( + listOf(CoreConatinerBuilderFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + CoreConatinerBuilderFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getWideLiteralIndex(CoreContainer) + 4 + val targetReference = + getInstruction(targetIndex).reference + + if (!targetReference.toString().endsWith("Landroid/view/ViewGroup;")) + return PatchResultError("Reference did not match: $targetReference") + + val targetRegister = + getInstruction(targetIndex).registerA + + addInstruction( + targetIndex, + "invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR" + ) + } + } ?: return CoreConatinerBuilderFingerprint.toErrorResult() + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: PLAYER_SETTINGS", + "SETTINGS: PLAYER_EXPERIMENTAL_FLAGS", + "SETTINGS: HIDE_SUGGESTED_VIDEO_OVERLAY" + ) + ) + + SettingsPatch.updatePatchStatus("hide-suggested-video-overlay") + + return PatchResultSuccess() + } + + private companion object { + const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$PLAYER->hideSuggestedVideoOverlay(Landroid/view/ViewGroup;)V" + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt index 5db6975103..7551fae979 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt @@ -35,6 +35,7 @@ class SharedResourceIdPatch : ResourcePatch { var ChannelListSubMenu: Long = -1 var CompactLink: Long = -1 var ControlsLayoutStub: Long = -1 + var CoreContainer: Long = -1 var DislikeButton: Long = -1 var DonationCompanion: Long = -1 var EasySeekEduContainer: Long = -1 @@ -105,6 +106,7 @@ class SharedResourceIdPatch : ResourcePatch { ChannelListSubMenu = find(LAYOUT, "channel_list_sub_menu") CompactLink = find(LAYOUT, "compact_link") ControlsLayoutStub = find(ID, "controls_layout_stub") + CoreContainer = find(ID, "core_container") DislikeButton = find(ID, "dislike_button") DonationCompanion = find(LAYOUT, "donation_companion") EasySeekEduContainer = find(ID, "easy_seek_edu_container") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 5e1a48e955..5c44b01c13 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -481,6 +481,9 @@ Only available on YouTube v18.24.37+" - Shopping - Watch it Again" Hide suggestions shelf + "Hides suggested video overlay to play next +Known issue: autoplay does not work" + Hide suggested video overlay Ticket shelves are shown Ticket shelves are hidden Hide ticket shelf diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 286c92bb25..8f3fd5a7af 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -307,6 +307,7 @@ + @@ -495,10 +496,15 @@ + + + +