forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube/Fix suggested video end screen): no longer closes the `su…
…ggested video end screen`, but instead follows the autoplay settings
- Loading branch information
Showing
9 changed files
with
110 additions
and
149 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...p/revanced/patches/youtube/player/suggestedvideoendscreen/SuggestedVideoEndScreenPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package app.revanced.patches.youtube.player.suggestedvideoendscreen | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.util.smali.ExternalLabel | ||
import app.revanced.patches.youtube.player.suggestedvideoendscreen.fingerprints.RemoveOnLayoutChangeListenerFingerprint | ||
import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE | ||
import app.revanced.patches.youtube.utils.settings.SettingsPatch | ||
import app.revanced.util.getTargetIndex | ||
import app.revanced.util.getTargetIndexReversed | ||
import app.revanced.util.getWalkerMethod | ||
import app.revanced.util.patch.BaseBytecodePatch | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction | ||
|
||
@Suppress("unused") | ||
object SuggestedVideoEndScreenPatch : BaseBytecodePatch( | ||
name = "Fix suggested video end screen", | ||
description = "Fixes an issue where the suggested video end screen is shown at the end of a video, regardless of whether autoplay setting is on or off.", | ||
dependencies = setOf(SettingsPatch::class), | ||
compatiblePackages = COMPATIBLE_PACKAGE, | ||
fingerprints = setOf(RemoveOnLayoutChangeListenerFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
|
||
/** | ||
* The reasons why this patch is classified as a patch that fixes a 'bug' are as follows: | ||
* 1. In YouTube v18.29.38, the suggested video end screen was only shown when the autoplay setting was turned on. | ||
* 2. Starting from YouTube v18.35.36, the suggested video end screen is shown regardless of whether autoplay setting was turned on or off. | ||
* | ||
* This patch changes the suggested video end screen to be shown only when the autoplay setting is turned on. | ||
* Automatically closing the suggested video end screen is not appropriate as it will disable the autoplay behavior. | ||
*/ | ||
RemoveOnLayoutChangeListenerFingerprint.resultOrThrow().let { | ||
val walkerIndex = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) | ||
|
||
walkerIndex.apply { | ||
val invokeInterfaceIndex = getTargetIndex(Opcode.INVOKE_INTERFACE) | ||
val iGetObjectIndex = getTargetIndexReversed(invokeInterfaceIndex, Opcode.IGET_OBJECT) | ||
|
||
val invokeInterfaceReference = getInstruction<ReferenceInstruction>(invokeInterfaceIndex).reference | ||
val iGetObjectReference = getInstruction<ReferenceInstruction>(iGetObjectIndex).reference | ||
|
||
addInstructionsWithLabels( | ||
0, | ||
""" | ||
iget-object v0, p0, $iGetObjectReference | ||
# This reference checks whether autoplay is turned on. | ||
invoke-interface {v0}, $invokeInterfaceReference | ||
move-result v0 | ||
# Hide suggested video end screen only when autoplay is turned off. | ||
if-nez v0, :show_suggested_video_end_screen | ||
return-void | ||
""", | ||
ExternalLabel( | ||
"show_suggested_video_end_screen", | ||
getInstruction(0) | ||
) | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Add settings | ||
*/ | ||
SettingsPatch.addPreference( | ||
arrayOf( | ||
"PREFERENCE: PLAYER_SETTINGS", | ||
"SETTINGS: PLAYER_EXPERIMENTAL_FLAGS", | ||
"SETTINGS: HIDE_SUGGESTED_VIDEO_END_SCREEN" | ||
) | ||
) | ||
|
||
SettingsPatch.updatePatchStatus("Fix suggested video end screen") | ||
|
||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...be/player/suggestedvideoendscreen/fingerprints/RemoveOnLayoutChangeListenerFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package app.revanced.patches.youtube.player.suggestedvideoendscreen.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.util.fingerprint.ReferenceFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
/** | ||
* This fingerprint is also compatible with very old YouTube versions. | ||
* Tested on YouTube v16.40.36, v18.29.38, v19.12.41. | ||
*/ | ||
internal object RemoveOnLayoutChangeListenerFingerprint : ReferenceFingerprint( | ||
returnType = "V", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
parameters = emptyList(), | ||
opcodes = listOf( | ||
Opcode.IPUT, | ||
Opcode.INVOKE_VIRTUAL | ||
), | ||
// This is the only reference present in the entire smali. | ||
reference = { "YouTubePlayerOverlaysLayout;->removeOnLayoutChangeListener(Landroid/view/View${'$'}OnLayoutChangeListener;)V" } | ||
) |
95 changes: 0 additions & 95 deletions
95
...n/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
...ches/youtube/player/suggestedvideooverlay/fingerprints/CoreContainerBuilderFingerprint.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
...ches/youtube/player/suggestedvideooverlay/fingerprints/MiniPlayerPlayButtonFingerprint.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
.../youtube/player/suggestedvideooverlay/fingerprints/TouchAreaOnClickListenerFingerprint.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters