Skip to content

Commit 9633b4e

Browse files
mrweddersoSumAtrIX
andauthored
feat(MyFitnessPal): Add Hide ads patch (#2594)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 2a94ad6 commit 9633b4e

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

api/revanced-patches.api

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,20 @@ public final class app/revanced/patches/myexpenses/misc/pro/UnlockProPatch : app
333333
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
334334
}
335335

336+
public final class app/revanced/patches/myfitnesspal/ads/HideAdsPatch : app/revanced/patcher/patch/BytecodePatch {
337+
public static final field INSTANCE Lapp/revanced/patches/myfitnesspal/ads/HideAdsPatch;
338+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
339+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
340+
}
341+
342+
public final class app/revanced/patches/myfitnesspal/ads/fingerprints/IsPremiumUseCaseImplFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
343+
public static final field INSTANCE Lapp/revanced/patches/myfitnesspal/ads/fingerprints/IsPremiumUseCaseImplFingerprint;
344+
}
345+
346+
public final class app/revanced/patches/myfitnesspal/ads/fingerprints/MainActivityNavigateToNativePremiumUpsellFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
347+
public static final field INSTANCE Lapp/revanced/patches/myfitnesspal/ads/fingerprints/MainActivityNavigateToNativePremiumUpsellFingerprint;
348+
}
349+
336350
public final class app/revanced/patches/netguard/broadcasts/removerestriction/RemoveBroadcastsRestrictionPatch : app/revanced/patcher/patch/ResourcePatch {
337351
public static final field INSTANCE Lapp/revanced/patches/netguard/broadcasts/removerestriction/RemoveBroadcastsRestrictionPatch;
338352
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package app.revanced.patches.myfitnesspal.ads
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions
5+
import app.revanced.patcher.patch.BytecodePatch
6+
import app.revanced.patcher.patch.annotation.CompatiblePackage
7+
import app.revanced.patcher.patch.annotation.Patch
8+
import app.revanced.patches.myfitnesspal.ads.fingerprints.IsPremiumUseCaseImplFingerprint
9+
import app.revanced.patches.myfitnesspal.ads.fingerprints.MainActivityNavigateToNativePremiumUpsellFingerprint
10+
import app.revanced.util.exception
11+
12+
@Patch(
13+
name = "Hide ads",
14+
description = "Hides most of the ads across the app.",
15+
compatiblePackages = [CompatiblePackage("com.myfitnesspal.android")]
16+
)
17+
@Suppress("unused")
18+
object HideAdsPatch : BytecodePatch(
19+
setOf(IsPremiumUseCaseImplFingerprint, MainActivityNavigateToNativePremiumUpsellFingerprint)
20+
) {
21+
override fun execute(context: BytecodeContext) {
22+
// Overwrite the premium status specifically for ads.
23+
IsPremiumUseCaseImplFingerprint.result?.mutableMethod?.replaceInstructions(
24+
0,
25+
"""
26+
sget-object v0, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean;
27+
return-object v0
28+
"""
29+
) ?: throw IsPremiumUseCaseImplFingerprint.exception
30+
31+
// Prevent the premium upsell dialog from showing when the main activity is launched.
32+
// In other places that are premium-only the dialog will still show.
33+
MainActivityNavigateToNativePremiumUpsellFingerprint.result?.mutableMethod?.replaceInstructions(
34+
0,
35+
"return-void"
36+
) ?: throw MainActivityNavigateToNativePremiumUpsellFingerprint.exception
37+
}
38+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package app.revanced.patches.myfitnesspal.ads.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
import com.android.tools.smali.dexlib2.AccessFlags
5+
6+
object IsPremiumUseCaseImplFingerprint : MethodFingerprint(
7+
accessFlags = AccessFlags.PUBLIC.value,
8+
customFingerprint = { methodDef, classDef ->
9+
classDef.type.endsWith("IsPremiumUseCaseImpl;") && methodDef.name == "doWork"
10+
}
11+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package app.revanced.patches.myfitnesspal.ads.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
7+
object MainActivityNavigateToNativePremiumUpsellFingerprint : MethodFingerprint(
8+
returnType = "V",
9+
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
10+
customFingerprint = { methodDef, classDef ->
11+
classDef.type.endsWith("MainActivity;") && methodDef.name == "navigateToNativePremiumUpsell"
12+
}
13+
)

0 commit comments

Comments
 (0)