Skip to content

Commit 9df0a7d

Browse files
committed
feat(duolingo/premium): Refactor EnablePremiumPatch field handling
- Import MethodUtil for improved method handling. - Update field removal logic to use a more explicit approach. - Ensure proper targeting of user properties in the LoggedIn constructor. This refactor enhances code clarity and maintainability by explicitly iterating over fields and improving method reference handling.
1 parent 96e73ea commit 9df0a7d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

patches/src/main/kotlin/app/revanced/patches/duolingo/premium/EnablePremiumPatch.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.android.tools.smali.dexlib2.AccessFlags
1010
import com.android.tools.smali.dexlib2.Opcode
1111
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
1212
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
13+
import com.android.tools.smali.dexlib2.util.MethodUtil
1314

1415
@Suppress("unused")
1516
val enablePremiumPatch = bytecodePatch(
@@ -31,12 +32,14 @@ val enablePremiumPatch = bytecodePatch(
3132

3233
// Remove final keyword on fields we want to patch
3334
val fields = setOf(hasPlusField, subscriberLevelField, isPaidField)
34-
fields.forEach { userFingerprint.classDef.fieldByName(it.name).removeFlag(AccessFlags.FINAL) }
35+
fields.forEach { field ->
36+
userFingerprint.classDef.fields.first { it.name == field.name }.removeFlags(AccessFlags.FINAL)
37+
}
3538

3639
// For patching user properties, we target the User object that is passed in to the
3740
// constructor of the LoggedIn class. This way we don't affect all instances of users
3841
// (eg. viewing a friend's profile).
39-
loggedInStateFingerprint.classDef.constructor().apply {
42+
loggedInStateFingerprint.classDef.methods.first { MethodUtil.isConstructor(it) }.apply {
4043
val userType = userFingerprint.classDef.type
4144
val patchIndex = this.instructions.count() - 1
4245
// Single-parameter method means User will always be in p1.

0 commit comments

Comments
 (0)