From c6c23ff0d9a18e3ef3d4b9b28ffa562a2eceb58b Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 16 May 2023 10:31:35 +0400 Subject: [PATCH] fix(youtube/sponsorblock): fix toast shown when scrubbing thru a paused video (#2152) Co-authored-by: oSumAtrIX --- .../annotation/PlayerTypeHookCompatibility.kt | 9 ---- ...ingerprint.kt => PlayerTypeFingerprint.kt} | 14 +++--- .../fingerprint/VideoStateFingerprint.kt | 24 ++++++++++ .../playertype/patch/PlayerTypeHookPatch.kt | 47 +++++++++++++++---- 4 files changed, 69 insertions(+), 25 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/{UpdatePlayerTypeFingerprint.kt => PlayerTypeFingerprint.kt} (73%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/annotation/PlayerTypeHookCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/annotation/PlayerTypeHookCompatibility.kt index 4a3244cddd..ad87649184 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/annotation/PlayerTypeHookCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/annotation/PlayerTypeHookCompatibility.kt @@ -6,15 +6,6 @@ import app.revanced.patcher.annotation.Package @Compatibility( [Package( "com.google.android.youtube", arrayOf( - "17.49.37", - "18.03.36", - "18.03.42", - "18.04.35", - "18.04.41", - "18.05.32", - "18.05.35", - "18.05.40", - "18.08.37", "18.15.40", "18.16.37" ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/UpdatePlayerTypeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/PlayerTypeFingerprint.kt similarity index 73% rename from src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/UpdatePlayerTypeFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/PlayerTypeFingerprint.kt index 0eb8e9a11d..0b56538dd1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/UpdatePlayerTypeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/PlayerTypeFingerprint.kt @@ -1,15 +1,14 @@ package app.revanced.patches.youtube.misc.playertype.fingerprint import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -@FuzzyPatternScanMethod(2) -object UpdatePlayerTypeFingerprint : MethodFingerprint( - "V", - AccessFlags.PUBLIC or AccessFlags.FINAL, +object PlayerTypeFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L"), opcodes = listOf( Opcode.INVOKE_VIRTUAL, Opcode.IGET_OBJECT, @@ -29,5 +28,8 @@ object UpdatePlayerTypeFingerprint : MethodFingerprint( Opcode.INVOKE_STATIC, Opcode.INVOKE_VIRTUAL, Opcode.RETURN_VOID - ) + ), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("YouTubePlayerOverlaysLayout;") + } ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt new file mode 100644 index 0000000000..3250f17c03 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt @@ -0,0 +1,24 @@ +package app.revanced.patches.youtube.misc.playertype.fingerprint + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object VideoStateFingerprint : MethodFingerprint( + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + returnType = "V", + parameters = listOf("L"), + opcodes = listOf( + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.CONST_4, + Opcode.IF_EQZ, + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, // obfuscated parameter field name + ), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("YouTubeControlsOverlay;") + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt index 75e722072e..999356376a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt @@ -1,34 +1,61 @@ package app.revanced.patches.youtube.misc.playertype.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.addInstruction +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.playertype.annotation.PlayerTypeHookCompatibility -import app.revanced.patches.youtube.misc.playertype.fingerprint.UpdatePlayerTypeFingerprint +import app.revanced.patches.youtube.misc.playertype.fingerprint.PlayerTypeFingerprint +import app.revanced.patches.youtube.misc.playertype.fingerprint.VideoStateFingerprint +import org.jf.dexlib2.iface.instruction.ReferenceInstruction @Name("player-type-hook") -@Description("Hook to get the current player type of WatchWhileActivity") +@Description("Hook to get the current player type and video playback state.") @PlayerTypeHookCompatibility @Version("0.0.1") @DependsOn([IntegrationsPatch::class]) class PlayerTypeHookPatch : BytecodePatch( - listOf( - UpdatePlayerTypeFingerprint - ) + listOf(PlayerTypeFingerprint, VideoStateFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - // hook YouTubePlayerOverlaysLayout.updatePlayerLayout() - UpdatePlayerTypeFingerprint.result!!.mutableMethod.addInstruction( - 0, - "invoke-static { p1 }, Lapp/revanced/integrations/patches/PlayerTypeHookPatch;->YouTubePlayerOverlaysLayout_updatePlayerTypeHookEX(Ljava/lang/Object;)V" - ) + + PlayerTypeFingerprint.result?.let { + it.mutableMethod.apply { + addInstruction( + 0, + "invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" + ) + } + } ?: return PlayerTypeFingerprint.toErrorResult() + + VideoStateFingerprint.result?.let { + it.mutableMethod.apply { + val endIndex = it.scanResult.patternScanResult!!.endIndex + val videoStateFieldName = instruction(endIndex).reference + addInstructions( + 0, """ + iget-object v0, p1, $videoStateFieldName # copy VideoState parameter field + invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->setVideoState(Ljava/lang/Enum;)V + """ + ) + } + } ?: return VideoStateFingerprint.toErrorResult() + return PatchResultSuccess() } + + companion object { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/patches/PlayerTypeHookPatch;" + } + }