@@ -4,15 +4,18 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
44import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
55import app.revanced.patcher.patch.bytecodePatch
66import app.revanced.patches.primevideo.misc.extension.sharedExtensionPatch
7+ import app.revanced.util.*
78import com.android.tools.smali.dexlib2.AccessFlags
9+ import com.android.tools.smali.dexlib2.Opcode
810import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
11+ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
912
1013@Suppress(" unused" )
1114val skipAdsPatch = bytecodePatch(
1215 name = " Skip ads" ,
1316 description = " Automatically skips video stream ads." ,
1417) {
15- compatibleWith(" com.amazon.avod.thirdpartyclient" (" 3.0.412.2947 " ))
18+ compatibleWith(" com.amazon.avod.thirdpartyclient" (" 3.0.430.1747 " ))
1619
1720 dependsOn(sharedExtensionPatch)
1821
@@ -22,24 +25,30 @@ val skipAdsPatch = bytecodePatch(
2225 // Force doTrigger() access to public so we can call it from our extension.
2326 doTriggerFingerprint.method.accessFlags = AccessFlags .PUBLIC .value;
2427
25- val getPlayerIndex = enterServerInsertedAdBreakStateFingerprint.patternMatch!! .startIndex
2628 enterServerInsertedAdBreakStateFingerprint.method.apply {
2729 // Get register that stores VideoPlayer:
2830 // invoke-virtual ->getPrimaryPlayer()
2931 // move-result-object { playerRegister }
30- val playerRegister = getInstruction<OneRegisterInstruction >(getPlayerIndex + 1 ).registerA
32+ val playerIndex = indexOfFirstInstructionOrThrow() {
33+ opcode == Opcode .INVOKE_VIRTUAL && getReference<MethodReference >()?.name == " getPrimaryPlayer"
34+ }
35+ val playerRegister = getInstruction<OneRegisterInstruction >(playerIndex + 1 ).registerA
3136
3237 // Reuse the params from the original method:
3338 // p0 = ServerInsertedAdBreakState
3439 // p1 = AdBreakTrigger
3540 addInstructions(
36- getPlayerIndex + 2 ,
41+ playerIndex + 2 ,
3742 """
3843 invoke-static { p0, p1, v$playerRegister }, Lapp/revanced/extension/primevideo/ads/SkipAdsPatch;->enterServerInsertedAdBreakState(Lcom/amazon/avod/media/ads/internal/state/ServerInsertedAdBreakState;Lcom/amazon/avod/media/ads/internal/state/AdBreakTrigger;Lcom/amazon/avod/media/playback/VideoPlayer;)V
3944 return-void
4045 """
4146 )
4247 }
48+
49+ // Return early from these callbacks to prevent unwanted overlays from ad breaks.
50+ onSeekBehindUnwatchedAdFingerprint.method.returnEarly()
51+ onSeekPastUnwatchedAdFingerprint.method.returnEarly()
4352 }
4453}
4554
0 commit comments