mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
feat: Minor refactor and return proxy, if class has been proxied already
This commit is contained in:
parent
ce21bd60f3
commit
4b26305bd5
3 changed files with 11 additions and 7 deletions
|
@ -33,7 +33,7 @@ class Patcher(
|
||||||
// TODO: the iterator would return the proxied class matching the current index of the list
|
// TODO: the iterator would return the proxied class matching the current index of the list
|
||||||
// TODO: instead of the original class
|
// TODO: instead of the original class
|
||||||
for (classProxy in cache.classProxy) {
|
for (classProxy in cache.classProxy) {
|
||||||
if (!classProxy.proxyused) continue
|
if (!classProxy.proxyUsed) continue
|
||||||
// TODO: merge this class with cache.classes somehow in an iterator
|
// TODO: merge this class with cache.classes somehow in an iterator
|
||||||
classProxy.mutatedClass
|
classProxy.mutatedClass
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,15 @@ class Cache(
|
||||||
internal val classes: Set<ClassDef>,
|
internal val classes: Set<ClassDef>,
|
||||||
val resolvedMethods: MethodMap
|
val resolvedMethods: MethodMap
|
||||||
) {
|
) {
|
||||||
internal val classProxy = mutableListOf<ClassProxy>()
|
internal val classProxy = mutableSetOf<ClassProxy>()
|
||||||
|
|
||||||
fun findClass(predicate: (ClassDef) -> Boolean): ClassProxy? {
|
fun findClass(predicate: (ClassDef) -> Boolean): ClassProxy? {
|
||||||
// if a class has been found with the given predicate,
|
// if we already proxied the class matching the predicate,
|
||||||
val foundClass = classes.singleOrNull(predicate) ?: return null
|
val proxiedClass = classProxy.singleOrNull{classProxy -> predicate(classProxy.immutableClass)}
|
||||||
|
// return that proxy
|
||||||
|
if (proxiedClass != null) return proxiedClass
|
||||||
|
// else search the original class list
|
||||||
|
val foundClass = classes.singleOrNull(predicate) ?: return null
|
||||||
// create a class proxy with the index of the class in the classes list
|
// create a class proxy with the index of the class in the classes list
|
||||||
// TODO: There might be a more elegant way to the comment above
|
// TODO: There might be a more elegant way to the comment above
|
||||||
val classProxy = ClassProxy(foundClass, classes.indexOf(foundClass))
|
val classProxy = ClassProxy(foundClass, classes.indexOf(foundClass))
|
||||||
|
|
|
@ -8,12 +8,12 @@ class ClassProxy(
|
||||||
val immutableClass: ClassDef,
|
val immutableClass: ClassDef,
|
||||||
val originalClassIndex: Int,
|
val originalClassIndex: Int,
|
||||||
) {
|
) {
|
||||||
internal var proxyused = false
|
internal var proxyUsed = false
|
||||||
internal lateinit var mutatedClass: MutableClass
|
internal lateinit var mutatedClass: MutableClass
|
||||||
|
|
||||||
fun resolve(): MutableClass {
|
fun resolve(): MutableClass {
|
||||||
if (!proxyused) {
|
if (!proxyUsed) {
|
||||||
proxyused = true
|
proxyUsed = true
|
||||||
mutatedClass = MutableClass(immutableClass)
|
mutatedClass = MutableClass(immutableClass)
|
||||||
}
|
}
|
||||||
return mutatedClass
|
return mutatedClass
|
||||||
|
|
Loading…
Reference in a new issue