From 1ce0625a432b271566cb21d0f0a6e6d82df3ca31 Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Mon, 14 Nov 2022 00:27:59 +0100 Subject: [PATCH] feat(twitch): `block-audio-ads` patch (#1041) Co-authored-by: oSumAtrIX --- .../annotations/AudioAdsCompatibility.kt | 10 ++++++ .../AudioAdsPresenterPlayFingerprint.kt | 16 ++++++++++ .../twitch/ad/audio/patch/AudioAdsPatch.kt | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/twitch/ad/audio/annotations/AudioAdsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitch/ad/audio/fingerprints/AudioAdsPresenterPlayFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitch/ad/audio/patch/AudioAdsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/twitch/ad/audio/annotations/AudioAdsCompatibility.kt b/src/main/kotlin/app/revanced/patches/twitch/ad/audio/annotations/AudioAdsCompatibility.kt new file mode 100644 index 000000000..0e39cb8d3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/ad/audio/annotations/AudioAdsCompatibility.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.twitch.ad.audio.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("tv.twitch.android.app")]) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class AudioAdsCompatibility + diff --git a/src/main/kotlin/app/revanced/patches/twitch/ad/audio/fingerprints/AudioAdsPresenterPlayFingerprint.kt b/src/main/kotlin/app/revanced/patches/twitch/ad/audio/fingerprints/AudioAdsPresenterPlayFingerprint.kt new file mode 100644 index 000000000..1cd867f42 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/ad/audio/fingerprints/AudioAdsPresenterPlayFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.twitch.ad.audio.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.twitch.ad.audio.annotations.AudioAdsCompatibility + +@Name("audio-ads-presenter-play-fingerprint") +@AudioAdsCompatibility +@Version("0.0.1") +object AudioAdsPresenterPlayFingerprint : MethodFingerprint( + customFingerprint = { method -> + method.definingClass.endsWith("AudioAdsPlayerPresenter;") && method.name == "playAd" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/twitch/ad/audio/patch/AudioAdsPatch.kt b/src/main/kotlin/app/revanced/patches/twitch/ad/audio/patch/AudioAdsPatch.kt new file mode 100644 index 000000000..ac680f5af --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitch/ad/audio/patch/AudioAdsPatch.kt @@ -0,0 +1,31 @@ +package app.revanced.patches.twitch.ad.audio.patch + +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.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.twitch.ad.audio.annotations.AudioAdsCompatibility +import app.revanced.patches.twitch.ad.audio.fingerprints.AudioAdsPresenterPlayFingerprint + +@Patch +@Name("block-audio-ads") +@Description("Blocks audio ads in streams and VODs.") +@AudioAdsCompatibility +@Version("0.0.1") +class AudioAdsPatch : BytecodePatch( + listOf(AudioAdsPresenterPlayFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + // Block playAds call + with(AudioAdsPresenterPlayFingerprint.result!!) { + mutableMethod.addInstruction(0, "return-void") + } + + return PatchResultSuccess() + } +}