mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 09:08:04 +01:00
fix: Patch should have access to the Cache
BREAKING CHANGE: Method signature of execute() was changed to include the cache, this will break existing implementations of the Patch class.
This commit is contained in:
parent
cb9b1b9416
commit
4dd820ffdf
3 changed files with 7 additions and 4 deletions
|
@ -23,7 +23,7 @@ class Patcher(
|
||||||
private val patches: MutableList<Patch> = mutableListOf()
|
private val patches: MutableList<Patch> = mutableListOf()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val classes = Io.readClassesFromJar(input);
|
val classes = Io.readClassesFromJar(input)
|
||||||
cache = Cache(classes, MethodResolver(classes, signatures).resolve())
|
cache = Cache(classes, MethodResolver(classes, signatures).resolve())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class Patcher(
|
||||||
return buildMap {
|
return buildMap {
|
||||||
for (patch in patches) {
|
for (patch in patches) {
|
||||||
val result: Result<Nothing?> = try {
|
val result: Result<Nothing?> = try {
|
||||||
val pr = patch.execute()
|
val pr = patch.execute(cache)
|
||||||
if (pr.isSuccess()) continue
|
if (pr.isSuccess()) continue
|
||||||
Result.failure(Exception(pr.error()?.errorMessage() ?: "Unknown error"))
|
Result.failure(Exception(pr.error()?.errorMessage() ?: "Unknown error"))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.revanced.patcher.patch
|
package net.revanced.patcher.patch
|
||||||
|
|
||||||
|
import net.revanced.patcher.cache.Cache
|
||||||
|
|
||||||
abstract class Patch(val patchName: String) {
|
abstract class Patch(val patchName: String) {
|
||||||
abstract fun execute(): PatchResult
|
abstract fun execute(cache: Cache): PatchResult
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.revanced.patcher
|
package net.revanced.patcher
|
||||||
|
|
||||||
|
import net.revanced.patcher.cache.Cache
|
||||||
import net.revanced.patcher.patch.Patch
|
import net.revanced.patcher.patch.Patch
|
||||||
import net.revanced.patcher.patch.PatchResult
|
import net.revanced.patcher.patch.PatchResult
|
||||||
import net.revanced.patcher.patch.PatchResultSuccess
|
import net.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
@ -48,7 +49,7 @@ internal class PatcherTest {
|
||||||
|
|
||||||
patcher.addPatches(
|
patcher.addPatches(
|
||||||
object : Patch("TestPatch") {
|
object : Patch("TestPatch") {
|
||||||
override fun execute(): PatchResult {
|
override fun execute(cache: Cache): PatchResult {
|
||||||
// Get the method from the resolver cache
|
// Get the method from the resolver cache
|
||||||
val mainMethod = patcher.cache.methods["mainMethod"]
|
val mainMethod = patcher.cache.methods["mainMethod"]
|
||||||
// Get the instruction list
|
// Get the instruction list
|
||||||
|
|
Loading…
Reference in a new issue