@@ -38,6 +38,7 @@ import net.minecraft.util.Identifier
3838import net.minecraft.util.math.BlockPos
3939import net.minecraft.util.math.ChunkPos
4040import org.apache.logging.log4j.Logger
41+ import java.io.File
4142import java.lang.reflect.InaccessibleObjectException
4243import java.util.*
4344import kotlin.jvm.optionals.getOrDefault
@@ -75,44 +76,59 @@ object DynamicReflectionSerializer : Loadable {
7576
7677 private const val INDENT = 2
7778
78- private val mappings = runBlocking {
79+ private val simpleMappings = runBlocking {
7980 " ${LambdaAPI .mappings} /${LambdaAPI .GAME_VERSION } "
80- .downloadIfNotPresent(cache.resolveFile(LambdaAPI .GAME_VERSION ))
81- .map { file ->
82- val standardMappings = file.readLines()
83- .map { it.split(' ' ) }
84- .filter { it.size == 2 }
85- .associate { (obf, deobf) -> obf to deobf }
86-
87- buildMap {
88- putAll(standardMappings)
89-
90- standardMappings.forEach { (obf, deobf) ->
91- put(obf.split(' $' ).last(), deobf)
92- if (' $' !in obf) return @forEach
93- put(obf.replace(' $' , ' .' ), deobf)
94- val parts = obf.split(' $' )
95- if (! parts.all { it.startsWith(" class_" ) }) return @forEach
96- (1 until parts.size).forEach { i ->
97- put(" ${parts.take(i).joinToString(" $" )} .${parts.drop(i).joinToString(" $" )} " , deobf)
98- }
99- }
100- }
81+ .downloadIfNotPresent(cache.resolveFile(" ${LambdaAPI .GAME_VERSION } -simple" ))
82+ .map(::buildMappingsMap)
83+ .getOrElse {
84+ LOG .error(" Unable to download simplified deobfuscated qualifiers" , it)
85+ emptyMap()
10186 }
87+ }
88+
89+ private val qualifiedMappings = runBlocking {
90+ " ${LambdaAPI .mappings} /${LambdaAPI .GAME_VERSION } -qualified"
91+ .downloadIfNotPresent(cache.resolveFile(LambdaAPI .GAME_VERSION ))
92+ .map(::buildMappingsMap)
10293 .getOrElse {
10394 LOG .error(" Unable to download deobfuscated qualifiers" , it)
10495 emptyMap()
10596 }
10697 }
10798
99+ val String .simpleRemappedName get() = simpleMappings.getOrDefault(this , this )
100+ val String .remappedName get() = qualifiedMappings.getOrDefault(this , this )
101+
102+ private fun buildMappingsMap (file : File ): Map <String , String > {
103+ val standardMappings = file.readLines()
104+ .map { it.split(' ' ) }
105+ .filter { it.size == 2 }
106+ .associate { (obf, deobf) -> obf to deobf }
107+
108+ return buildMap {
109+ putAll(standardMappings)
110+ standardMappings.forEach { (obf, deobf) ->
111+ val parts = obf.split(' $' )
112+ put(parts.last(), deobf)
113+ if (' $' !in obf) return @forEach
114+ put(obf.replace(' $' , ' .' ), deobf)
115+ if (! parts.all { it.startsWith(" class_" ) }) return @forEach
116+ (1 until parts.size).forEach { i ->
117+ put(" ${parts.take(i).joinToString(" $" )} .${parts.drop(i).joinToString(" $" )} " , deobf)
118+ }
119+ }
120+ }
121+ }
108122
109- val String .remappedName get() = mappings.getOrDefault( this , this )
110-
111- fun < T : Any > KClass<T>. dynamicName ( remap : Boolean ) =
112- if (remap) qualifiedName?.remappedName else simpleName
123+ fun < T : Any > KClass<T>. dynamicName ( remap : Boolean , simple : Boolean = true) =
124+ if (remap)
125+ if (simple) qualifiedName?.simpleRemappedName else qualifiedName?.remappedName
126+ else if (simple) simpleName else qualifiedName
113127
114- fun <T : Any > KProperty1 <T , * >.dynamicName (remap : Boolean ) =
115- if (remap) name.remappedName else name
128+ fun <T : Any > KProperty1 <T , * >.dynamicName (remap : Boolean , simple : Boolean = true) =
129+ if (remap)
130+ if (simple) name.simpleRemappedName else name.remappedName
131+ else name
116132
117133 fun Any.dynamicString (
118134 maxRecursionDepth : Int = 6,
@@ -121,14 +137,15 @@ object DynamicReflectionSerializer : Loadable {
121137 visitedObjects : MutableSet <Any > = HashSet (),
122138 builder : StringBuilder = StringBuilder (),
123139 remap : Boolean = !Lambda .isDebug,
140+ simple : Boolean = true
124141 ): String {
125142 if (visitedObjects.contains(this )) {
126- builder.appendLine(" $indent${this ::class .dynamicName(remap)} (Circular Reference)" )
143+ builder.appendLine(" $indent${this ::class .dynamicName(remap, simple )} (Circular Reference)" )
127144 return builder.toString()
128145 }
129146
130147 visitedObjects.add(this )
131- builder.appendLine(" $indent${this ::class .dynamicName(remap)} " )
148+ builder.appendLine(" $indent${this ::class .dynamicName(remap, simple )} " )
132149
133150 this ::class .memberProperties
134151 .forEach { processField(it, indent, builder, currentDepth, maxRecursionDepth, visitedObjects, remap) }
@@ -197,5 +214,5 @@ object DynamicReflectionSerializer : Loadable {
197214 }
198215 }
199216
200- override fun load () = " Loaded ${mappings .size} deobfuscated qualifier"
217+ override fun load () = " Loaded ${simpleMappings .size} deobfuscated qualifier"
201218}
0 commit comments