diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt index e1d56ba86..ef2d40605 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt @@ -7,15 +7,21 @@ 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.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.player.suggestedvideooverlay.fingerprints.CoreContainerBuilderFingerprint +import app.revanced.patches.youtube.player.suggestedvideooverlay.fingerprints.TouchAreaOnClickListenerFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CoreContainer import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch( name = "Hide suggested video overlay", @@ -58,7 +64,10 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction ) @Suppress("unused") object SuggestedVideoOverlayPatch : BytecodePatch( - setOf(CoreContainerBuilderFingerprint) + setOf( + CoreContainerBuilderFingerprint, + TouchAreaOnClickListenerFingerprint + ) ) { override fun execute(context: BytecodeContext) { @@ -81,6 +90,22 @@ object SuggestedVideoOverlayPatch : BytecodePatch( } } ?: throw CoreContainerBuilderFingerprint.exception + TouchAreaOnClickListenerFingerprint.result?.let { + it.mutableMethod.apply { + val insertMethod = it.mutableClass.methods.find { method -> method.parameters == listOf("Landroid/view/View${'$'}OnClickListener;") } + + insertMethod?.apply { + val setOnClickListenerIndex = getOnClickListenerIndex() + val setOnClickListenerRegister = getInstruction(setOnClickListenerIndex).registerC + + addInstruction( + setOnClickListenerIndex + 1, + "invoke-static {v$setOnClickListenerRegister}, $PLAYER->hideSuggestedVideoOverlayAutoPlay(Landroid/view/View;)V" + ) + } ?: throw PatchException("Failed to find setOnClickListener method") + } + } ?: throw TouchAreaOnClickListenerFingerprint.exception + /** * Add settings */ @@ -95,4 +120,12 @@ object SuggestedVideoOverlayPatch : BytecodePatch( SettingsPatch.updatePatchStatus("Hide suggested video overlay") } + + private fun MutableMethod.getOnClickListenerIndex(): Int { + return implementation!!.instructions.indexOfFirst { instruction -> + if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return@indexOfFirst false + + return@indexOfFirst ((instruction as Instruction35c).reference as MethodReference).name == "setOnClickListener" + } + } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreContainerBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreContainerBuilderFingerprint.kt index 0d931db40..63bd7fd95 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreContainerBuilderFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/CoreContainerBuilderFingerprint.kt @@ -4,10 +4,16 @@ import app.revanced.patcher.extensions.or import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CoreContainer import app.revanced.util.fingerprint.LiteralValueFingerprint import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode object CoreContainerBuilderFingerprint : LiteralValueFingerprint( returnType = "Landroid/view/View;", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("Landroid/content/Context;"), + opcodes = listOf( + Opcode.INVOKE_DIRECT, + Opcode.INVOKE_VIRTUAL, + Opcode.CONST + ), literalSupplier = { CoreContainer } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/TouchAreaOnClickListenerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/TouchAreaOnClickListenerFingerprint.kt new file mode 100644 index 000000000..162b1b2f3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/fingerprints/TouchAreaOnClickListenerFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.player.suggestedvideooverlay.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TouchArea +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +object TouchAreaOnClickListenerFingerprint : LiteralValueFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + literalSupplier = { TouchArea } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index 004a5f8fd..3c0193489 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -80,6 +80,7 @@ object SharedResourceIdPatch : ResourcePatch() { var TabsBarTextTabView: Long = -1 var ToolTipContentView: Long = -1 var TotalTime: Long = -1 + var TouchArea: Long = -1 var VideoQualityBottomSheet: Long = -1 var VideoZoomIndicatorLayout: Long = -1 var YoutubeControlsOverlay: Long = -1 @@ -164,6 +165,7 @@ object SharedResourceIdPatch : ResourcePatch() { TabsBarTextTabView = find(ID, "tabs_bar_text_tab_view") ToolTipContentView = find(LAYOUT, "tooltip_content_view") TotalTime = find(STRING, "total_time") + TouchArea = find(ID, "touch_area") VideoQualityBottomSheet = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title") VideoZoomIndicatorLayout = find(ID, "video_zoom_indicator_layout") YoutubeControlsOverlay = find(ID, "youtube_controls_overlay") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index b9cebb325..d7f3d0899 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -646,9 +646,9 @@ Known issue: Official headers in search results will be hidden." Suggested actions shown. Suggested actions hidden. Hide suggested actions - "Hides suggested video overlay to play next. - -Known issue: Autoplay does not work." + When you finished a video, another play automatically + Auto play the next video + Hides suggested video overlay to play next. Hide suggested video overlay "Identifies the suggestions shelf through the browse id. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 444efec34..2db5eb550 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -629,7 +629,8 @@ SETTINGS: HIDE_FILMSTRIP_OVERLAY --> + + SETTINGS: HIDE_SUGGESTED_VIDEO_OVERLAY -->