Skip to content

Commit

Permalink
feat(trakt): add unlock-pro patch (#2210)
Browse files Browse the repository at this point in the history
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
johnconner122 and oSumAtrIX committed May 21, 2023
1 parent 633703d commit 1e8dcae
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
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
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"
}
)
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"
}
)
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 src/main/kotlin/app/revanced/patches/trakt/patch/UnlockProPatch.kt
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
"""
}
}

0 comments on commit 1e8dcae

Please sign in to comment.