Skip to content

Commit b5dd8d1

Browse files
committed
Added support for arbitrarily deeply nested classes
1 parent 1d99fe0 commit b5dd8d1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

common/src/main/kotlin/com/lambda/util/DynamicReflectionSerializer.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,33 @@ object DynamicReflectionSerializer : Loadable {
7474
"${Network.mappings}/${Network.gameVersion}"
7575
.downloadIfNotPresent(cache.resolveFile(Network.gameVersion))
7676
.map { file ->
77-
file.readLines()
77+
val standardMappings = file.readLines()
7878
.map { it.split(' ') }
79-
.associate { it[0].split('$').last() to it[1] }
79+
.filter { it.size == 2 }
80+
.associate { (obf, deobf) -> obf to deobf }
81+
82+
buildMap {
83+
putAll(standardMappings)
84+
85+
standardMappings.forEach { (obf, deobf) ->
86+
put(obf.split('$').last(), deobf)
87+
if ('$' !in obf) return@forEach
88+
put(obf.replace('$', '.'), deobf)
89+
val parts = obf.split('$')
90+
if (!parts.all { it.startsWith("class_") }) return@forEach
91+
(1 until parts.size).forEach { i ->
92+
put("${parts.take(i).joinToString("$")}.${parts.drop(i).joinToString("$")}", deobf)
93+
}
94+
}
95+
}
8096
}
8197
.getOrElse {
8298
LOG.error("Unable to download deobfuscated qualifiers", it)
8399
emptyMap()
84100
}
85101
}
86102

103+
87104
val String.remappedName get() = mappings.getOrDefault(this, this)
88105

89106
fun <T : Any> Class<T>.dynamicName(remap: Boolean) =

0 commit comments

Comments
 (0)