diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/LoadAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/LoadAdsFingerprint.kt index e3409c0fc..a93be1465 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/LoadAdsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/LoadAdsFingerprint.kt @@ -5,14 +5,15 @@ import app.revanced.patcher.annotation.Version import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patches.youtube.ad.video.annotations.VideoAdsCompatibility +import org.jf.dexlib2.Opcode @Name("load-ads-fingerprint") @VideoAdsCompatibility @Version("0.0.1") object LoadAdsFingerprint : MethodFingerprint( - strings = listOf("Unexpected playerAd type: "), + opcodes = listOf(Opcode.INVOKE_INTERFACE_RANGE), customFingerprint = { method -> - method.parameterTypes.size > 0 && method.parameterTypes.first() == "Ljava/lang/String;" + method.parameterTypes.size > 0 && method.parameterTypes.first().endsWith("InstreamAdBreak;") } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt index 7e2aea490..cd4ad5fc5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt @@ -41,19 +41,20 @@ class VideoAdsPatch : BytecodePatch( ) ) - LoadAdsFingerprint.result!!.mutableMethod.let { method -> - method.addInstructions( - 0, - """ - invoke-static { }, Lapp/revanced/integrations/patches/VideoAdsPatch;->shouldShowAds()Z - move-result v1 - if-nez v1, :show_video_ads - new-instance v3, Ljava/util/ArrayList; - invoke-direct { v3 }, Ljava/util/ArrayList;->()V - return-object v3 - """, - listOf(ExternalLabel("show_video_ads", method.instruction(0))) - ) + with(LoadAdsFingerprint.result!!) { + val insertIndex = scanResult.patternScanResult!!.startIndex + with(mutableMethod) { + addInstructions( + insertIndex, + """ + invoke-static { }, Lapp/revanced/integrations/patches/VideoAdsPatch;->shouldShowAds()Z + move-result v4 + if-nez v4, :show_video_ads + return-object v3 + """, + listOf(ExternalLabel("show_video_ads", instruction(insertIndex))) + ) + } } return PatchResultSuccess()