forked from inotia00/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(trakt): add
unlock-pro
patch (ReVanced#2210)
Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
1 parent
633703d
commit 1e8dcae
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/app/revanced/patches/trakt/annotations/UnlockProCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package app.revanced.patches.trakt.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility([Package("tv.trakt.trakt")]) | ||
@Target(AnnotationTarget.CLASS) | ||
internal annotation class UnlockProCompatibility |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPEPFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package app.revanced.patches.trakt.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
|
||
object IsVIPEPFingerprint : MethodFingerprint( | ||
customFingerprint = custom@{ methodDef, _ -> | ||
if (!methodDef.definingClass.endsWith("RealmUserSettings;")) return@custom false | ||
|
||
methodDef.name == "isVIPEP" | ||
} | ||
) |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package app.revanced.patches.trakt.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
|
||
object IsVIPFingerprint : MethodFingerprint( | ||
customFingerprint = custom@{ methodDef, _ -> | ||
if (!methodDef.definingClass.endsWith("RealmUserSettings;")) return@custom false | ||
|
||
methodDef.name == "isVIP" | ||
} | ||
) |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/app/revanced/patches/trakt/fingerprints/RealmUserSettingsFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.revanced.patches.trakt.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
|
||
object RealmUserSettingsFingerprint : MethodFingerprint( | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.definingClass.endsWith("RealmUserSettings;") | ||
} | ||
) |
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/app/revanced/patches/trakt/patch/UnlockProPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package app.revanced.patches.trakt.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patches.trakt.annotations.UnlockProCompatibility | ||
import app.revanced.patches.trakt.fingerprints.IsVIPEPFingerprint | ||
import app.revanced.patches.trakt.fingerprints.IsVIPFingerprint | ||
import app.revanced.patches.trakt.fingerprints.RealmUserSettingsFingerprint | ||
|
||
@Patch | ||
@Name("unlock-pro") | ||
@Description("Unlocks pro features.") | ||
@UnlockProCompatibility | ||
@Version("0.0.1") | ||
class UnlockProPatch : BytecodePatch( | ||
listOf(RealmUserSettingsFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
RealmUserSettingsFingerprint.result?.classDef?.let { realUserSettingsClass -> | ||
arrayOf(IsVIPFingerprint, IsVIPEPFingerprint).onEach { fingerprint -> | ||
// Resolve both fingerprints on the same class. | ||
if (!fingerprint.resolve(context, realUserSettingsClass)) | ||
throw fingerprint.toErrorResult() | ||
}.forEach { fingerprint -> | ||
// Return true for both VIP check methods. | ||
fingerprint.result?.mutableMethod?.addInstructions(0, RETURN_TRUE_INSTRUCTIONS) | ||
?: return fingerprint.toErrorResult() | ||
} | ||
} ?: return RealmUserSettingsFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val RETURN_TRUE_INSTRUCTIONS = | ||
""" | ||
const/4 v0, 0x1 | ||
invoke-static {v0}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean; | ||
move-result-object v1 | ||
return-object v1 | ||
""" | ||
} | ||
} |