@@ -2,39 +2,35 @@ package app.revanced.patches.nova.prime.patch
22
33import app.revanced.util.exception
44import app.revanced.patcher.data.BytecodeContext
5- import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6+ import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
67import app.revanced.patcher.patch.BytecodePatch
7- import app.revanced.patcher.patch.PatchResult
88import app.revanced.patcher.patch.annotation.Patch
99import app.revanced.patcher.patch.annotation.CompatiblePackage
10- import app.revanced.patches.nova.prime.fingerprints.UnlockPrimeFingerprint
11- import com.android.tools.smali.dexlib2.builder .instruction.BuilderInstruction11x
10+ import app.revanced.patches.nova.prime.fingerprints.UpdatePrimeStatusFingerprint
11+ import com.android.tools.smali.dexlib2.iface .instruction.OneRegisterInstruction
1212
1313@Patch(
1414 name = " Unlock prime" ,
1515 description = " Unlocks Nova Prime and all functions of the app." ,
1616 compatiblePackages = [CompatiblePackage (" com.teslacoilsw.launcher" )]
1717)
18+ @Suppress(" unused" )
1819object UnlockPrimePatch : BytecodePatch(
19- setOf(UnlockPrimeFingerprint )
20+ setOf(UpdatePrimeStatusFingerprint )
2021) {
21- override fun execute (context : BytecodeContext ) {
22- UnlockPrimeFingerprint .result?.apply {
23- // Any value except 0 unlocks prime, but 512 is needed for a protection mechanism
24- // which would reset the preferences if the value on disk had changed after a restart.
25- val PRIME_STATUS : Int = 512
26- val insertIndex = scanResult.patternScanResult!! .endIndex + 1
22+ // Any value except 0 unlocks Nova Prime, but 512 is needed for a protection mechanism
23+ // otherwise the preferences will be reset if the status on disk changes after a restart.
24+ private const val PRIME_STATUS = 512
2725
28- val primeStatusRegister =
29- (mutableMethod.implementation !! .instructions[insertIndex - 1 ] as BuilderInstruction11x ).registerA
26+ override fun execute ( context : BytecodeContext ) = UpdatePrimeStatusFingerprint .result?. let {
27+ val setStatusIndex = it.scanResult.patternScanResult !! .startIndex
3028
31- mutableMethod.addInstruction(
32- insertIndex,
33- """
34- const/16 v$primeStatusRegister , $PRIME_STATUS
35- """
36- )
37- } ? : throw UnlockPrimeFingerprint .exception
29+ it.mutableMethod.apply {
30+ val statusRegister = getInstruction<OneRegisterInstruction >(setStatusIndex).registerA
31+ replaceInstruction(setStatusIndex, " const/16 v$statusRegister , $PRIME_STATUS " )
32+ }
3833
39- }
34+ return @let
35+ } ? : throw UpdatePrimeStatusFingerprint .exception
4036}
0 commit comments