Skip to content

Commit

Permalink
feat(twitch): remove block-embedded-ads patch (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie authored Nov 30, 2022
1 parent d93b480 commit a43d149
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal data class ArrayResource(
resourceCallback?.invoke(item)

this.appendChild(ownerDocument.createElement("item").also { itemNode ->
itemNode.textContent = "@string/${item.name}"
itemNode.textContent = item.value
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ abstract class AbstractSettingsResourcePatch(
* @param arrayResource The array resource to add.
*/
fun addArray(arrayResource: ArrayResource) =
arraysNode!!.addResource(arrayResource) { it.include() }
arraysNode!!.addResource(arrayResource)

/**
* Add a preference to the settings.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package app.revanced.patches.twitch.ad.video.fingerprints


import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

object GetReadyToShowAdFingerprint : MethodFingerprint(
object AdsManagerFingerprint : MethodFingerprint(
customFingerprint = { method ->
method.definingClass.endsWith("/StreamDisplayAdsPresenter;") && method.name == "getReadyToShowAdOrAbort"
method.definingClass.endsWith("AdsManagerImpl;") && method.name == "playAds"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
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.patcher.patch.annotations.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.twitch.ad.shared.util.AbstractAdPatch
import app.revanced.patches.twitch.ad.video.annotations.VideoAdsCompatibility
import app.revanced.patches.twitch.ad.video.fingerprints.AdsManagerFingerprint
import app.revanced.patches.twitch.ad.video.fingerprints.CheckAdEligibilityLambdaFingerprint
import app.revanced.patches.twitch.ad.video.fingerprints.ContentConfigShowAdsFingerprint
import app.revanced.patches.twitch.ad.video.fingerprints.GetReadyToShowAdFingerprint
import app.revanced.patches.twitch.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.twitch.misc.settings.bytecode.patch.SettingsPatch

Expand All @@ -27,63 +27,20 @@ import app.revanced.patches.twitch.misc.settings.bytecode.patch.SettingsPatch
@Description("Blocks video ads in streams and VODs.")
@VideoAdsCompatibility
@Version("0.0.1")
class VideoAdsPatch : AbstractAdPatch(
"Lapp/revanced/twitch/patches/VideoAdsPatch;->shouldBlockVideoAds()Z",
"show_video_ads",
class VideoAdsPatch : BytecodePatch(
listOf(
ContentConfigShowAdsFingerprint,
CheckAdEligibilityLambdaFingerprint,
GetReadyToShowAdFingerprint
AdsManagerFingerprint,
CheckAdEligibilityLambdaFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
/* Amazon ads SDK */
context.blockMethods(
"Lcom/amazon/ads/video/player/AdsManagerImpl;",
"playAds"
)

/* Twitch ads manager */
context.blockMethods(
"Ltv/twitch/android/shared/ads/VideoAdManager;",
"checkAdEligibilityAndRequestAd", "requestAd", "requestAds"
)

/* Various ad presenters */
context.blockMethods(
"Ltv/twitch/android/shared/ads/AdsPlayerPresenter;",
"requestAd", "requestFirstAd", "requestFirstAdIfEligible", "requestMidroll", "requestAdFromMultiAdFormatEvent"
)

context.blockMethods(
"Ltv/twitch/android/shared/ads/AdsVodPlayerPresenter;",
"requestAd", "requestFirstAd",
)

context.blockMethods(
"Ltv/twitch/android/feature/theatre/ads/AdEdgeAllocationPresenter;",
"parseAdAndCheckEligibility", "requestAdsAfterEligibilityCheck", "showAd", "bindMultiAdFormatAllocation"
)

/* A/B ad testing experiments */
context.blockMethods(
"Ltv/twitch/android/provider/experiments/helpers/DisplayAdsExperimentHelper;",
"areDisplayAdsEnabled",
returnMethod = ReturnMethod('Z', "0")
)

context.blockMethods(
"Ltv/twitch/android/shared/ads/tracking/MultiFormatAdsTrackingExperiment;",
"shouldUseMultiAdFormatTracker", "shouldUseVideoAdTracker",
returnMethod = ReturnMethod('Z', "0")
)

context.blockMethods(
"Ltv/twitch/android/shared/ads/MultiformatAdsExperiment;",
"shouldDisableClientSideLivePreroll", "shouldDisableClientSideVodPreroll",
returnMethod = ReturnMethod('Z', "1")
)
private fun createConditionInstructions(register: String = "v0") = """
invoke-static { }, Lapp/revanced/twitch/patches/VideoAdsPatch;->shouldBlockVideoAds()Z
move-result $register
if-eqz $register, :show_video_ads
"""

override fun execute(context: BytecodeContext): PatchResult {
// Pretend our player is ineligible for all ads
with(CheckAdEligibilityLambdaFingerprint.result!!) {
mutableMethod.addInstructions(
Expand All @@ -95,22 +52,7 @@ class VideoAdsPatch : AbstractAdPatch(
move-result-object p0
return-object p0
""",
listOf(ExternalLabel(skipLabelName, mutableMethod.instruction(0)))
)
}

with(GetReadyToShowAdFingerprint.result!!) {
val adFormatDeclined = "Ltv/twitch/android/shared/display/ads/theatre/StreamDisplayAdsPresenter\$Action\$AdFormatDeclined;"
mutableMethod.addInstructions(
0,
"""
${createConditionInstructions()}
sget-object p2, $adFormatDeclined->INSTANCE:$adFormatDeclined
invoke-static {p1, p2}, Ltv/twitch/android/core/mvp/presenter/StateMachineKt;->plus(Ltv/twitch/android/core/mvp/presenter/PresenterState;Ltv/twitch/android/core/mvp/presenter/PresenterAction;)Ltv/twitch/android/core/mvp/presenter/StateAndAction;
move-result-object p1
return-object p1
""",
listOf(ExternalLabel(skipLabelName, mutableMethod.instruction(0)))
listOf(ExternalLabel("show_video_ads", mutableMethod.instruction(0)))
)
}

Expand All @@ -119,12 +61,24 @@ class VideoAdsPatch : AbstractAdPatch(
mutableMethod.addInstructions(0, """
${createConditionInstructions()}
const/4 v0, 0
:$skipLabelName
:show_video_ads
return v0
"""
)
}

// Block playAds call
with(AdsManagerFingerprint.result!!) {
mutableMethod.addInstructions(
0,
"""
${createConditionInstructions()}
return-void
""",
listOf(ExternalLabel("show_video_ads", mutableMethod.instruction(0)))
)
}

SettingsPatch.PreferenceScreen.ADS.CLIENT_SIDE.addPreferences(
SwitchPreference(
"revanced_block_video_ads",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ class SettingsPatch : BytecodePatch(
val GENERAL = CustomCategory("general", "General settings")
val OTHER = CustomCategory("other", "Other settings")
val CLIENT_SIDE = CustomCategory("client_ads", "Client-side ads")
val SURESTREAM = CustomCategory("surestream_ads", "Server-side surestream ads")

internal inner class CustomCategory(key: String, title: String) : Screen.Category(key, title) {
/* For Twitch, we need to load our CustomPreferenceCategory class instead of the default one. */
Expand Down

0 comments on commit a43d149

Please sign in to comment.