Skip to content

Commit

Permalink
fix(youtube/sponsorblock): fix toast shown when scrubbing thru a paus…
Browse files Browse the repository at this point in the history
…ed video (ReVanced#2152)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
LisoUseInAIKyrios and oSumAtrIX committed May 16, 2023
1 parent 99916ae commit c6c23ff
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -29,5 +28,8 @@ object UpdatePlayerTypeFingerprint : MethodFingerprint(
Opcode.INVOKE_STATIC,
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
)
),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("YouTubePlayerOverlaysLayout;")
}
)
Original file line number Diff line number Diff line change
@@ -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;")
}
)
Original file line number Diff line number Diff line change
@@ -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<ReferenceInstruction>(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;"
}

}

0 comments on commit c6c23ff

Please sign in to comment.