From f3726fefb9a80cccbf12f3ec455d1720b385782e Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 24 Oct 2023 23:34:23 +0300 Subject: [PATCH] fix(YouTube - ReturnYouTubeDislike): Fix RYD prefetching home feed Shorts (#3195) --- .../layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt | 4 ++-- .../youtube/video/information/VideoInformationPatch.kt | 2 +- .../video/playerresponse/PlayerResponseMethodHookPatch.kt | 3 ++- .../fingerprint/PlayerParameterBuilderFingerprint.kt | 2 +- .../revanced/patches/youtube/video/videoid/VideoIdPatch.kt | 5 ++++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt index 4ec359ee..311c958f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt @@ -58,7 +58,7 @@ object ReturnYouTubeDislikePatch : BytecodePatch( VideoIdPatch.hookVideoId("$INTEGRATIONS_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") // Hook the player response video id, to start loading RYD sooner in the background. - VideoIdPatch.hookPlayerResponseVideoId("$INTEGRATIONS_CLASS_DESCRIPTOR->preloadVideoId(Ljava/lang/String;)V") + VideoIdPatch.hookPlayerResponseVideoId("$INTEGRATIONS_CLASS_DESCRIPTOR->preloadVideoId(Ljava/lang/String;Z)V") // endregion @@ -184,7 +184,7 @@ object ReturnYouTubeDislikePatch : BytecodePatch( LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) // Player response video id is needed to search for the video ids in Shorts litho components. - VideoIdPatch.hookPlayerResponseVideoId("$FILTER_CLASS_DESCRIPTOR->newPlayerResponseVideoId(Ljava/lang/String;)V") + VideoIdPatch.hookPlayerResponseVideoId("$FILTER_CLASS_DESCRIPTOR->newPlayerResponseVideoId(Ljava/lang/String;Z)V") // endregion diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt index 4d5ac379..becfb4df 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt @@ -114,7 +114,7 @@ object VideoInformationPatch : BytecodePatch( VideoIdPatch.hookVideoId(videoIdMethodDescriptor) VideoIdPatch.hookBackgroundPlayVideoId(videoIdMethodDescriptor) VideoIdPatch.hookPlayerResponseVideoId( - "$INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerResponseVideoId(Ljava/lang/String;)V") + "$INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerResponseVideoId(Ljava/lang/String;Z)V") /* * Set the video time method diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt index a08531bb..d1e43c67 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt @@ -19,6 +19,7 @@ object PlayerResponseMethodHookPatch : Closeable, MutableSet by mutableSetOf() { private const val VIDEO_ID_PARAMETER = 1 + private const val VIDEO_IS_OPENING_OR_PLAYING_PARAMETER = 11 private const val PROTO_BUFFER_PARAMETER_PARAMETER = 3 private lateinit var playerResponseMethod: MutableMethod @@ -30,7 +31,7 @@ object PlayerResponseMethodHookPatch : override fun close() { fun hookVideoId(hook: Hook) = playerResponseMethod.addInstruction( - 0, "invoke-static {p$VIDEO_ID_PARAMETER}, $hook" + 0, "invoke-static {p$VIDEO_ID_PARAMETER, p$VIDEO_IS_OPENING_OR_PLAYING_PARAMETER}, $hook" ) fun hookProtoBufferParameter(hook: Hook) = playerResponseMethod.addInstructions( diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/fingerprint/PlayerParameterBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/fingerprint/PlayerParameterBuilderFingerprint.kt index 9e577e0b..1004e8bb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/fingerprint/PlayerParameterBuilderFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/fingerprint/PlayerParameterBuilderFingerprint.kt @@ -18,7 +18,7 @@ object PlayerParameterBuilderFingerprint : MethodFingerprint( "Ljava/lang/String;", "Ljava/lang/String;", "L", - "Z", + "Z", // Appears to indicate if the video id is being opened or is currently playing. "Z", "Z" ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt index 6149f33e..30a1646b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt @@ -103,6 +103,9 @@ object VideoIdPatch : BytecodePatch( * Hooks the video id of every video when loaded. * Supports all videos and functions in all situations. * + * First parameter is the video id. + * Second parameter is if the video is being opened or is currently playing. + * * Hook is always called off the main thread. * * This hook is called as soon as the player response is parsed, @@ -117,7 +120,7 @@ object VideoIdPatch : BytecodePatch( * * Be aware, this can be called multiple times for the same video id. * - * @param methodDescriptor which method to call. Params have to be `Ljava/lang/String;` + * @param methodDescriptor which method to call. Params must be `Ljava/lang/String;Z` */ fun hookPlayerResponseVideoId(methodDescriptor: String) { PlayerResponseMethodHookPatch += PlayerResponseMethodHookPatch.Hook.VideoId(