refactor(myfitnesspal): HideAdsPatch

This commit is contained in:
Pun Butrach
2026-01-11 23:52:48 +07:00
parent b8cacb507d
commit 8e94a17c28
2 changed files with 19 additions and 17 deletions

View File

@@ -1,19 +1,22 @@
package app.revanced.patches.myfitnesspal.ads
import app.revanced.patcher.fingerprint
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
import app.revanced.patcher.accessFlags
import app.revanced.patcher.definingClass
import app.revanced.patcher.name
import app.revanced.patcher.patch.BytecodePatchContext
import app.revanced.patcher.returnType
import com.android.tools.smali.dexlib2.AccessFlags
internal val isPremiumUseCaseImplFingerprint = fingerprint {
internal val BytecodePatchContext.isPremiumUseCaseImplMethod by gettingFirstMutableMethodDeclaratively {
accessFlags(AccessFlags.PUBLIC)
custom { method, classDef ->
classDef.endsWith("IsPremiumUseCaseImpl;") && method.name == "doWork"
}
definingClass("IsPremiumUseCaseImpl;")
name("doWork")
}
internal val mainActivityNavigateToNativePremiumUpsellFingerprint = fingerprint {
internal val BytecodePatchContext.mainActivityNavigateToNativePremiumUpsellMethod by gettingFirstMutableMethodDeclaratively {
accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL)
returns("V")
custom { method, classDef ->
classDef.endsWith("MainActivity;") && method.name == "navigateToNativePremiumUpsell"
}
returnType("V")
definingClass("MainActivity;")
name("navigateToNativePremiumUpsell")
}

View File

@@ -1,18 +1,17 @@
package app.revanced.patches.myfitnesspal.ads
import app.revanced.patcher.extensions.replaceInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.patch.creatingBytecodePatch
@Suppress("unused")
val hideAdsPatch = bytecodePatch(
name = "Hide ads",
description = "Hides most of the ads across the app.",
@Suppress("unused", "ObjectPropertyName")
val `Hide ads` by creatingBytecodePatch(
description = "Hides most of the ads across the app."
) {
compatibleWith("com.myfitnesspal.android"("24.14.2"))
apply {
// Overwrite the premium status specifically for ads.
isPremiumUseCaseImplFingerprint.method.replaceInstructions(
isPremiumUseCaseImplMethod.replaceInstructions(
0,
"""
sget-object v0, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean;
@@ -22,7 +21,7 @@ val hideAdsPatch = bytecodePatch(
// Prevent the premium upsell dialog from showing when the main activity is launched.
// In other places that are premium-only the dialog will still show.
mainActivityNavigateToNativePremiumUpsellFingerprint.method.replaceInstructions(
mainActivityNavigateToNativePremiumUpsellMethod.replaceInstructions(
0,
"return-void",
)