diff --git a/src/main/kotlin/app/revanced/patcher/Patcher.kt b/src/main/kotlin/app/revanced/patcher/Patcher.kt index 45802766..1b291546 100644 --- a/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -33,7 +33,7 @@ class Patcher( // TODO: the iterator would return the proxied class matching the current index of the list // TODO: instead of the original class for (classProxy in cache.classProxy) { - if (!classProxy.proxyused) continue + if (!classProxy.proxyUsed) continue // TODO: merge this class with cache.classes somehow in an iterator classProxy.mutatedClass } diff --git a/src/main/kotlin/app/revanced/patcher/cache/Cache.kt b/src/main/kotlin/app/revanced/patcher/cache/Cache.kt index aec78e83..5d2a3103 100644 --- a/src/main/kotlin/app/revanced/patcher/cache/Cache.kt +++ b/src/main/kotlin/app/revanced/patcher/cache/Cache.kt @@ -8,11 +8,15 @@ class Cache( internal val classes: Set, val resolvedMethods: MethodMap ) { - internal val classProxy = mutableListOf() + internal val classProxy = mutableSetOf() fun findClass(predicate: (ClassDef) -> Boolean): ClassProxy? { - // if a class has been found with the given predicate, - val foundClass = classes.singleOrNull(predicate) ?: return null + // if we already proxied the class matching the predicate, + 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 // TODO: There might be a more elegant way to the comment above val classProxy = ClassProxy(foundClass, classes.indexOf(foundClass)) diff --git a/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt b/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt index 8e02d46c..32c97545 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt @@ -8,12 +8,12 @@ class ClassProxy( val immutableClass: ClassDef, val originalClassIndex: Int, ) { - internal var proxyused = false + internal var proxyUsed = false internal lateinit var mutatedClass: MutableClass fun resolve(): MutableClass { - if (!proxyused) { - proxyused = true + if (!proxyUsed) { + proxyUsed = true mutatedClass = MutableClass(immutableClass) } return mutatedClass