mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 09:08:04 +01:00
parent
a492808021
commit
8544fc4cbc
3 changed files with 18 additions and 6 deletions
|
@ -3,6 +3,7 @@ package app.revanced.patcher
|
||||||
import app.revanced.patcher.cache.Cache
|
import app.revanced.patcher.cache.Cache
|
||||||
import app.revanced.patcher.cache.findIndexed
|
import app.revanced.patcher.cache.findIndexed
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.PatchMetadata
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.signature.MethodSignature
|
import app.revanced.patcher.signature.MethodSignature
|
||||||
import app.revanced.patcher.signature.resolver.SignatureResolver
|
import app.revanced.patcher.signature.resolver.SignatureResolver
|
||||||
|
@ -118,14 +119,14 @@ class Patcher(
|
||||||
fun applyPatches(
|
fun applyPatches(
|
||||||
stopOnError: Boolean = false,
|
stopOnError: Boolean = false,
|
||||||
callback: (String) -> Unit = {}
|
callback: (String) -> Unit = {}
|
||||||
): Map<String, Result<PatchResultSuccess>> {
|
): Map<PatchMetadata, Result<PatchResultSuccess>> {
|
||||||
if (!sigsResolved) {
|
if (!sigsResolved) {
|
||||||
SignatureResolver(cache.classes, signatures).resolve(cache.methodMap)
|
SignatureResolver(cache.classes, signatures).resolve(cache.methodMap)
|
||||||
sigsResolved = true
|
sigsResolved = true
|
||||||
}
|
}
|
||||||
return buildMap {
|
return buildMap {
|
||||||
for (patch in patches) {
|
for (patch in patches) {
|
||||||
callback(patch.patchName)
|
callback(patch.metadata.shortName)
|
||||||
val result: Result<PatchResultSuccess> = try {
|
val result: Result<PatchResultSuccess> = try {
|
||||||
val pr = patch.execute(cache)
|
val pr = patch.execute(cache)
|
||||||
if (pr.isSuccess()) {
|
if (pr.isSuccess()) {
|
||||||
|
@ -136,7 +137,7 @@ class Patcher(
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Result.failure(e)
|
Result.failure(e)
|
||||||
}
|
}
|
||||||
this[patch.patchName] = result
|
this[patch.metadata] = result
|
||||||
if (result.isFailure && stopOnError) break
|
if (result.isFailure && stopOnError) break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,12 @@ package app.revanced.patcher.patch
|
||||||
|
|
||||||
import app.revanced.patcher.cache.Cache
|
import app.revanced.patcher.cache.Cache
|
||||||
|
|
||||||
abstract class Patch(val patchName: String) {
|
abstract class Patch(val metadata: PatchMetadata) {
|
||||||
abstract fun execute(cache: Cache): PatchResult
|
abstract fun execute(cache: Cache): PatchResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class PatchMetadata(
|
||||||
|
val shortName: String,
|
||||||
|
val fullName: String,
|
||||||
|
val description: String,
|
||||||
|
)
|
|
@ -4,6 +4,7 @@ import app.revanced.patcher.cache.Cache
|
||||||
import app.revanced.patcher.extensions.AccessFlagExtensions.Companion.or
|
import app.revanced.patcher.extensions.AccessFlagExtensions.Companion.or
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.PatchMetadata
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.proxy.mutableTypes.MutableField.Companion.toMutable
|
import app.revanced.patcher.proxy.mutableTypes.MutableField.Companion.toMutable
|
||||||
|
@ -61,7 +62,11 @@ internal class PatcherTest {
|
||||||
)
|
)
|
||||||
|
|
||||||
patcher.addPatches(listOf(
|
patcher.addPatches(listOf(
|
||||||
object : Patch("TestPatch") {
|
object : Patch(PatchMetadata(
|
||||||
|
"test-patch",
|
||||||
|
"My Test Patch",
|
||||||
|
"A very good description."
|
||||||
|
)) {
|
||||||
override fun execute(cache: Cache): PatchResult {
|
override fun execute(cache: Cache): PatchResult {
|
||||||
// Get the result from the resolver cache
|
// Get the result from the resolver cache
|
||||||
val result = cache.methodMap["main-method"]
|
val result = cache.methodMap["main-method"]
|
||||||
|
|
Loading…
Reference in a new issue