Fix refmap remapping not able to remap methods without class names

This commit is contained in:
shedaniel
2021-01-07 01:03:17 +08:00
parent 5966eb1d36
commit fbb9fcef68
2 changed files with 20 additions and 1 deletions

View File

@@ -1,2 +1,2 @@
rootProject.name = 'architect-plugin' rootProject.name = 'architectury-plugin'

View File

@@ -26,6 +26,8 @@ import org.objectweb.asm.tree.MethodInsnNode
import org.zeroturnaround.zip.ZipUtil import org.zeroturnaround.zip.ZipUtil
import java.io.* import java.io.*
import java.net.URL import java.net.URL
import java.nio.file.FileSystemAlreadyExistsException
import java.nio.file.FileSystems
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import java.util.* import java.util.*
@@ -246,6 +248,7 @@ modId = "$fakeModId"
private fun remapRefmap(obj: JsonObject) { private fun remapRefmap(obj: JsonObject) {
val srg = project.extensions.getByType(LoomGradleExtension::class.java).mappingsProvider.mappingsWithSrg val srg = project.extensions.getByType(LoomGradleExtension::class.java).mappingsProvider.mappingsWithSrg
val methodPattern = "L(.*);(.*)(\\(.*)".toRegex() val methodPattern = "L(.*);(.*)(\\(.*)".toRegex()
val methodPatternWithoutClass = "(.*)(\\(.*)".toRegex()
val fieldPattern = "(.*):(.*)".toRegex() val fieldPattern = "(.*):(.*)".toRegex()
obj.keySet().forEach { key -> obj.keySet().forEach { key ->
@@ -253,6 +256,7 @@ modId = "$fakeModId"
val methodMatch = methodPattern.matchEntire(originalRef) val methodMatch = methodPattern.matchEntire(originalRef)
val fieldMatch = fieldPattern.matchEntire(originalRef) val fieldMatch = fieldPattern.matchEntire(originalRef)
val methodMatchWithoutClass = methodPatternWithoutClass.matchEntire(originalRef)
when { when {
methodMatch != null -> { methodMatch != null -> {
@@ -291,6 +295,21 @@ modId = "$fakeModId"
}) })
) )
} }
methodMatchWithoutClass != null -> {
val replacementName: String = srg.classes.asSequence()
.flatMap { it.methods.asSequence() }
.filter { it.getName("intermediary") == methodMatchWithoutClass.groups[1]!!.value }
.firstOrNull { it.getDescriptor("intermediary") == methodMatchWithoutClass.groups[2]!!.value }
?.getName("srg") ?: methodMatchWithoutClass.groups[1]!!.value
obj.addProperty(
key, originalRef
.replaceFirst(methodMatchWithoutClass.groups[1]!!.value, replacementName)
.replaceFirst(methodMatchWithoutClass.groups[2]!!.value, methodMatchWithoutClass.groups[2]!!.value.remapDescriptor {
srg.classes.firstOrNull { def -> def.getName("intermediary") == it }?.getName("srg")
?: it
})
)
}
else -> logger.warn("Failed to remap refmap value: $originalRef") else -> logger.warn("Failed to remap refmap value: $originalRef")
} }
} }