mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 09:08:04 +01:00
refactor: convert Patch to abstract class
BREAKING CHANGE: Patch class is now an abstract class. You must implement it. You can use anonymous implements, like done in the tests.
This commit is contained in:
parent
428f7f4dec
commit
cb9b1b9416
2 changed files with 56 additions and 57 deletions
|
@ -1,9 +1,5 @@
|
||||||
package net.revanced.patcher.patch
|
package net.revanced.patcher.patch
|
||||||
|
|
||||||
class Patch(val patchName: String, val fn: () -> PatchResult) {
|
abstract class Patch(val patchName: String) {
|
||||||
fun execute(): PatchResult {
|
abstract fun execute(): PatchResult
|
||||||
return fn()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.revanced.patcher
|
package net.revanced.patcher
|
||||||
|
|
||||||
import net.revanced.patcher.patch.Patch
|
import net.revanced.patcher.patch.Patch
|
||||||
|
import net.revanced.patcher.patch.PatchResult
|
||||||
import net.revanced.patcher.patch.PatchResultSuccess
|
import net.revanced.patcher.patch.PatchResultSuccess
|
||||||
import net.revanced.patcher.signature.Signature
|
import net.revanced.patcher.signature.Signature
|
||||||
import net.revanced.patcher.util.ExtraTypes
|
import net.revanced.patcher.util.ExtraTypes
|
||||||
|
@ -46,7 +47,8 @@ internal class PatcherTest {
|
||||||
val patcher = Patcher(testData, testSigs)
|
val patcher = Patcher(testData, testSigs)
|
||||||
|
|
||||||
patcher.addPatches(
|
patcher.addPatches(
|
||||||
Patch ("TestPatch") {
|
object : Patch("TestPatch") {
|
||||||
|
override fun execute(): 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
|
||||||
|
@ -101,7 +103,8 @@ internal class PatcherTest {
|
||||||
// You can also return PatchResultError with a message.
|
// You can also return PatchResultError with a message.
|
||||||
// If an exception is thrown inside this function,
|
// If an exception is thrown inside this function,
|
||||||
// a PatchResultError will be returned with the error message.
|
// a PatchResultError will be returned with the error message.
|
||||||
PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue