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