Skip to content

Commit 591e106

Browse files
authored
feat(Duolingo): Add Skip energy recharge ads patch (#6167)
1 parent e7336d2 commit 591e106

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public final class app/revanced/patches/duolingo/debug/EnableDebugMenuPatchKt {
184184
public static final fun getEnableDebugMenuPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
185185
}
186186

187+
public final class app/revanced/patches/duolingo/energy/SkipEnergyRechargeAdsPatchKt {
188+
public static final fun getSkipEnergyRechargeAdsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
189+
}
190+
187191
public final class app/revanced/patches/facebook/ads/mainfeed/HideSponsoredStoriesPatchKt {
188192
public static final fun getHideSponsoredStoriesPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
189193
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package app.revanced.patches.duolingo.energy
2+
3+
import app.revanced.patcher.fingerprint
4+
import com.android.tools.smali.dexlib2.AccessFlags
5+
import com.android.tools.smali.dexlib2.Opcode
6+
7+
/**
8+
* Matches the class found in [energyConfigToStringFingerprint].
9+
*/
10+
internal val initializeEnergyConfigFingerprint = fingerprint {
11+
accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR)
12+
opcodes(Opcode.RETURN_VOID)
13+
}
14+
15+
// Class name currently is not obfuscated but it may be in the future.
16+
internal val energyConfigToStringFingerprint = fingerprint {
17+
parameters()
18+
returns("Ljava/lang/String;")
19+
strings("EnergyConfig(", "maxEnergy=") // Partial string matches.
20+
custom { method, _ -> method.name == "toString" }
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package app.revanced.patches.duolingo.energy
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
4+
import app.revanced.patcher.patch.bytecodePatch
5+
import app.revanced.util.findFieldFromToString
6+
7+
@Suppress("unused")
8+
val skipEnergyRechargeAdsPatch = bytecodePatch(
9+
name = "Skip energy recharge ads",
10+
description = "Skips watching ads to recharge energy."
11+
) {
12+
compatibleWith("com.duolingo")
13+
14+
execute {
15+
initializeEnergyConfigFingerprint
16+
.match(energyConfigToStringFingerprint.classDef)
17+
.method.apply {
18+
val energyField = energyConfigToStringFingerprint.method
19+
.findFieldFromToString("energy=")
20+
val insertIndex = initializeEnergyConfigFingerprint.patternMatch!!.startIndex
21+
22+
addInstructions(
23+
insertIndex,
24+
"""
25+
const/16 v0, 99
26+
iput v0, p0, $energyField
27+
"""
28+
)
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)