Skip to content

Commit

Permalink
feat(twitch): 15.4.1 support (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios authored Jun 21, 2023
1 parent becb033 commit 826ed49
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@ 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", arrayOf(
"14.3.3",
"14.4.0",
"14.5.0",
"14.5.2",
"14.6.0",
"14.6.1"
)
)
]
)
@Compatibility([Package("tv.twitch.android.app", arrayOf("15.4.1"))])
@Target(AnnotationTarget.CLASS)
internal annotation class AudioAdsCompatibility

Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@ package app.revanced.patches.twitch.ad.embedded.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[
Package(
"tv.twitch.android.app", arrayOf(
"14.3.3",
"14.4.0",
"14.5.0",
"14.5.2",
"14.6.0",
"14.6.1"
)
)
]
)
@Compatibility([Package("tv.twitch.android.app", arrayOf("15.4.1"))])
@Target(AnnotationTarget.CLASS)
internal annotation class EmbeddedAdsCompatibility

Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@ package app.revanced.patches.twitch.ad.video.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[
Package(
"tv.twitch.android.app", arrayOf(
"14.3.3",
"14.4.0",
"14.5.0",
"14.5.2",
"14.6.0",
"14.6.1"
)
)
]
)
@Compatibility([Package("tv.twitch.android.app", arrayOf("15.4.1"))])
@Target(AnnotationTarget.CLASS)
internal annotation class VideoAdsCompatibility

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

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags

object CheckAdEligibilityLambdaFingerprint : MethodFingerprint(
"L",
AccessFlags.PRIVATE or AccessFlags.FINAL or AccessFlags.STATIC,
listOf("L", "L", "L"),
returnType = "Lio/reactivex/Single;",
parameters = listOf("L"),
customFingerprint = { method, _ ->
method.definingClass.endsWith("AdEligibilityFetcher;") &&
method.name.contains("shouldRequestAd")
method.definingClass.endsWith("/AdEligibilityFetcher;")
&& method.name == "shouldRequestAd"
}
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package app.revanced.patches.twitch.ad.video.fingerprints


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

object ContentConfigShowAdsFingerprint : MethodFingerprint(
returnType = "Z",
parameters = listOf(),
customFingerprint = { method, _ ->
method.definingClass.endsWith("ContentConfigData;") && method.name == "getShowAds"
method.definingClass.endsWith("/ContentConfigData;") && method.name == "getShowAds"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package app.revanced.patches.twitch.ad.video.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

object GetReadyToShowAdFingerprint : MethodFingerprint(
returnType = "Ltv/twitch/android/core/mvp/presenter/StateAndAction;",
parameters = listOf("L", "L"),
customFingerprint = { method, _ ->
method.definingClass.endsWith("/StreamDisplayAdsPresenter;") && method.name == "getReadyToShowAdOrAbort"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.patches.twitch.ad.video.patch

import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
Expand Down Expand Up @@ -86,7 +87,7 @@ class VideoAdsPatch : AbstractAdPatch(
)

// Pretend our player is ineligible for all ads
with(CheckAdEligibilityLambdaFingerprint.result!!) {
CheckAdEligibilityLambdaFingerprint.result?.apply {
mutableMethod.addInstructionsWithLabels(
0,
"""
Expand All @@ -98,9 +99,9 @@ class VideoAdsPatch : AbstractAdPatch(
""",
ExternalLabel(skipLabelName, mutableMethod.getInstruction(0))
)
}
} ?: return CheckAdEligibilityLambdaFingerprint.toErrorResult()

with(GetReadyToShowAdFingerprint.result!!) {
GetReadyToShowAdFingerprint.result?.apply {
val adFormatDeclined = "Ltv/twitch/android/shared/display/ads/theatre/StreamDisplayAdsPresenter\$Action\$AdFormatDeclined;"
mutableMethod.addInstructionsWithLabels(
0,
Expand All @@ -113,18 +114,18 @@ class VideoAdsPatch : AbstractAdPatch(
""",
ExternalLabel(skipLabelName, mutableMethod.getInstruction(0))
)
}
} ?: return GetReadyToShowAdFingerprint.toErrorResult()

// Spoof showAds JSON field
with(ContentConfigShowAdsFingerprint.result!!) {
ContentConfigShowAdsFingerprint.result?.apply {
mutableMethod.addInstructions(0, """
${createConditionInstructions()}
const/4 v0, 0
:$skipLabelName
return v0
"""
)
}
} ?: return ContentConfigShowAdsFingerprint.toErrorResult()

SettingsPatch.PreferenceScreen.ADS.CLIENT_SIDE.addPreferences(
SwitchPreference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.revanced.patches.twitch.chat.antidelete.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility([Package("tv.twitch.android.app")])
@Compatibility([Package("tv.twitch.android.app", arrayOf("15.4.1"))])
@Target(AnnotationTarget.CLASS)
internal annotation class ShowDeletedMessagesCompatibility

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.patches.twitch.chat.antidelete.patch

import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
Expand Down Expand Up @@ -44,7 +45,7 @@ class ShowDeletedMessagesPatch : BytecodePatch(

override fun execute(context: BytecodeContext): PatchResult {
// Spoiler mode: Force set hasModAccess member to true in constructor
DeletedMessageClickableSpanCtorFingerprint.result!!.mutableMethod.apply {
DeletedMessageClickableSpanCtorFingerprint.result?.mutableMethod?.apply {
addInstructionsWithLabels(
implementation!!.instructions.lastIndex, /* place in front of return-void */
"""
Expand All @@ -54,14 +55,14 @@ class ShowDeletedMessagesPatch : BytecodePatch(
""",
ExternalLabel("no_spoiler", getInstruction(implementation!!.instructions.lastIndex))
)
}
} ?: return DeletedMessageClickableSpanCtorFingerprint.toErrorResult()

// Spoiler mode: Disable setHasModAccess setter
SetHasModAccessFingerprint.result!!.mutableMethod.addInstruction(0, "return-void")

SetHasModAccessFingerprint.result?.mutableMethod?.addInstruction(0, "return-void")
?: return SetHasModAccessFingerprint.toErrorResult()

// Cross-out mode: Reformat span of deleted message
ChatUtilCreateDeletedSpanFingerprint.result!!.mutableMethod.apply {
ChatUtilCreateDeletedSpanFingerprint.result?.mutableMethod?.apply {
addInstructionsWithLabels(
0,
"""
Expand All @@ -72,7 +73,7 @@ class ShowDeletedMessagesPatch : BytecodePatch(
""",
ExternalLabel("no_reformat", getInstruction(0))
)
}
} ?: return ChatUtilCreateDeletedSpanFingerprint.toErrorResult()

SettingsPatch.PreferenceScreen.CHAT.GENERAL.addPreferences(
ListPreference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package app.revanced.patches.twitch.chat.autoclaim.annotations
import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility([Package("tv.twitch.android.app")])
@Compatibility([Package("tv.twitch.android.app", arrayOf("15.4.1"))])
@Target(AnnotationTarget.CLASS)
internal annotation class AutoClaimChannelPointsCompatibility
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class AutoClaimChannelPointPatch : BytecodePatch(
ExternalLabel("auto_claim", getInstruction(lastIndex))
)
} ?: return CommunityPointsButtonViewDelegateFingerprint.toErrorResult()

return PatchResultSuccess()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package app.revanced.patches.twitch.debug.fingerprints


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

object IsDebugConfigEnabledFingerprint : MethodFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("BuildConfigUtil;") && methodDef.name == "isDebugConfigEnabled"
methodDef.definingClass.endsWith("/BuildConfigUtil;") && methodDef.name == "isDebugConfigEnabled"
}
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package app.revanced.patches.twitch.debug.fingerprints


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

object IsOmVerificationEnabledFingerprint : MethodFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("BuildConfigUtil;") && methodDef.name == "isOmVerificationEnabled"
methodDef.definingClass.endsWith("/BuildConfigUtil;") && methodDef.name == "isOmVerificationEnabled"
}
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package app.revanced.patches.twitch.debug.fingerprints


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

object ShouldShowDebugOptionsFingerprint : MethodFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("BuildConfigUtil;") && methodDef.name == "shouldShowDebugOptions"
methodDef.definingClass.endsWith("/BuildConfigUtil;") && methodDef.name == "shouldShowDebugOptions"
}
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.patches.twitch.debug.patch

import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
Expand Down Expand Up @@ -38,18 +39,16 @@ class DebugModePatch : BytecodePatch(
IsOmVerificationEnabledFingerprint,
ShouldShowDebugOptionsFingerprint
).forEach {
with(it.result!!) {
with(mutableMethod) {
addInstructions(
0,
"""
invoke-static {}, Lapp/revanced/twitch/patches/DebugModePatch;->isDebugModeEnabled()Z
move-result v0
return v0
"""
)
}
}
it.result?.mutableMethod?.apply {
addInstructions(
0,
"""
invoke-static {}, Lapp/revanced/twitch/patches/DebugModePatch;->isDebugModeEnabled()Z
move-result v0
return v0
"""
)
} ?: return it.toErrorResult()
}

SettingsPatch.PreferenceScreen.MISC.OTHER.addPreferences(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.patches.twitch.misc.settings.bytecode.patch

import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
Expand Down Expand Up @@ -45,7 +46,7 @@ class SettingsPatch : BytecodePatch(
) {
override fun execute(context: BytecodeContext): PatchResult {
// Hook onCreate to handle fragment creation
with(SettingsActivityOnCreateFingerprint.result!!) {
SettingsActivityOnCreateFingerprint.result?.apply {
val insertIndex = mutableMethod.implementation!!.instructions.size - 2
mutableMethod.addInstructionsWithLabels(
insertIndex,
Expand All @@ -57,20 +58,20 @@ class SettingsPatch : BytecodePatch(
""",
ExternalLabel("no_rv_settings_init", mutableMethod.getInstruction(insertIndex))
)
}
} ?: return SettingsActivityOnCreateFingerprint.toErrorResult()

// Create new menu item for settings menu
with(SettingsMenuItemEnumFingerprint.result!!) {
SettingsMenuItemEnumFingerprint.result?.apply {
injectMenuItem(
REVANCED_SETTINGS_MENU_ITEM_NAME,
REVANCED_SETTINGS_MENU_ITEM_ID,
REVANCED_SETTINGS_MENU_ITEM_TITLE_RES,
REVANCED_SETTINGS_MENU_ITEM_ICON_RES
)
}
} ?: return SettingsMenuItemEnumFingerprint.toErrorResult()

// Intercept settings menu creation and add new menu item
with(MenuGroupsUpdatedFingerprint.result!!) {
MenuGroupsUpdatedFingerprint.result?.apply {
mutableMethod.addInstructions(
0,
"""
Expand All @@ -79,10 +80,10 @@ class SettingsPatch : BytecodePatch(
move-result-object p1
"""
)
}
} ?: return MenuGroupsUpdatedFingerprint.toErrorResult()

// Intercept onclick events for the settings menu
with(MenuGroupsOnClickFingerprint.result!!) {
MenuGroupsOnClickFingerprint.result?.apply {
val insertIndex = 0
mutableMethod.addInstructionsWithLabels(
insertIndex,
Expand All @@ -96,7 +97,7 @@ class SettingsPatch : BytecodePatch(
""",
ExternalLabel("no_rv_settings_onclick", mutableMethod.getInstruction(insertIndex))
)
}
} ?: return MenuGroupsOnClickFingerprint.toErrorResult()

addString("revanced_settings", "ReVanced Settings", false)
addString("revanced_reboot_message", "Twitch needs to restart to apply your changes. Restart now?", false)
Expand Down

0 comments on commit 826ed49

Please sign in to comment.