From 4dd820ffdf1b98fe41b50f7cb2670b89acfbb99d Mon Sep 17 00:00:00 2001 From: Lucaskyy Date: Sun, 20 Mar 2022 22:04:53 +0100 Subject: [PATCH] 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. --- src/main/kotlin/net/revanced/patcher/Patcher.kt | 4 ++-- src/main/kotlin/net/revanced/patcher/patch/Patch.kt | 4 +++- src/test/kotlin/net/revanced/patcher/PatcherTest.kt | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/net/revanced/patcher/Patcher.kt b/src/main/kotlin/net/revanced/patcher/Patcher.kt index b72667e6..670a249f 100644 --- a/src/main/kotlin/net/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/net/revanced/patcher/Patcher.kt @@ -23,7 +23,7 @@ class Patcher( private val patches: MutableList = mutableListOf() init { - val classes = Io.readClassesFromJar(input); + val classes = Io.readClassesFromJar(input) cache = Cache(classes, MethodResolver(classes, signatures).resolve()) } @@ -35,7 +35,7 @@ class Patcher( return buildMap { for (patch in patches) { val result: Result = try { - val pr = patch.execute() + val pr = patch.execute(cache) if (pr.isSuccess()) continue Result.failure(Exception(pr.error()?.errorMessage() ?: "Unknown error")) } catch (e: Exception) { diff --git a/src/main/kotlin/net/revanced/patcher/patch/Patch.kt b/src/main/kotlin/net/revanced/patcher/patch/Patch.kt index 37fe508b..f062a74c 100644 --- a/src/main/kotlin/net/revanced/patcher/patch/Patch.kt +++ b/src/main/kotlin/net/revanced/patcher/patch/Patch.kt @@ -1,5 +1,7 @@ package net.revanced.patcher.patch +import net.revanced.patcher.cache.Cache + abstract class Patch(val patchName: String) { - abstract fun execute(): PatchResult + abstract fun execute(cache: Cache): PatchResult } diff --git a/src/test/kotlin/net/revanced/patcher/PatcherTest.kt b/src/test/kotlin/net/revanced/patcher/PatcherTest.kt index eeedcb67..b552e98c 100644 --- a/src/test/kotlin/net/revanced/patcher/PatcherTest.kt +++ b/src/test/kotlin/net/revanced/patcher/PatcherTest.kt @@ -1,5 +1,6 @@ package net.revanced.patcher +import net.revanced.patcher.cache.Cache import net.revanced.patcher.patch.Patch import net.revanced.patcher.patch.PatchResult import net.revanced.patcher.patch.PatchResultSuccess @@ -48,7 +49,7 @@ internal class PatcherTest { patcher.addPatches( object : Patch("TestPatch") { - override fun execute(): PatchResult { + override fun execute(cache: Cache): PatchResult { // Get the method from the resolver cache val mainMethod = patcher.cache.methods["mainMethod"] // Get the instruction list