Skip to content

Commit 40f287b

Browse files
committed
fixed particle, entity, and block entity reflection based no render selection
1 parent f6f6227 commit 40f287b

File tree

3 files changed

+72
-42
lines changed

3 files changed

+72
-42
lines changed

src/main/kotlin/com/lambda/module/modules/render/NoRender.kt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.lambda.module.modules.render
1919

2020
import com.lambda.module.Module
2121
import com.lambda.module.tag.ModuleTag
22+
import com.lambda.util.DynamicReflectionSerializer.remappedName
2223
import com.lambda.util.reflections.scanResult
2324
import io.github.classgraph.ClassInfo
2425
import net.minecraft.block.entity.BlockEntity
@@ -122,16 +123,22 @@ object NoRender : Module(
122123
): Map<String, String> {
123124
val map = mutableMapOf<String, String>()
124125
items
125-
.filter { item ->
126-
if (strictDirectory) item.name.startsWith(directory) && !item.name.substring(directory.length).contains(".")
127-
else item.name.startsWith(directory)
128-
}
129-
.forEach { item ->
130-
val value = item.name
131-
.substring(item.name.indexOfLast { it == '.' } + 1)
126+
.map {
127+
val remappedName = it.name.remappedName
128+
val displayName = remappedName
129+
.substring(remappedName.indexOfLast { it == '.' } + 1)
132130
.replace(removePattern, "")
133131
.fancyFormat()
134-
map[item.simpleName] = value
132+
MappingInfo(it.simpleName, remappedName, displayName)
133+
}
134+
.sortedBy { it.displayName.lowercase() }
135+
.filter { info ->
136+
if (strictDirectory)
137+
info.remapped.startsWith(directory) && !info.remapped.substring(directory.length).contains(".")
138+
else info.remapped.startsWith(directory)
139+
}
140+
.forEach { info ->
141+
map[info.raw] = info.displayName
135142
}
136143
return map
137144
}
@@ -180,4 +187,10 @@ object NoRender : Module(
180187
modifier.statusEffect == StatusEffects.DARKNESS && noDarkness -> false
181188
else -> true
182189
}
190+
191+
private data class MappingInfo(
192+
val raw: String,
193+
val remapped: String,
194+
val displayName: String
195+
)
183196
}

src/main/kotlin/com/lambda/util/DynamicException.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
package com.lambda.util
1919

20-
import com.lambda.util.DynamicReflectionSerializer.remappedName
20+
import com.lambda.util.DynamicReflectionSerializer.simpleRemappedName
2121
import java.io.PrintStream
2222
import java.io.PrintWriter
2323

2424
class DynamicException(original: Throwable) : Throwable(original) {
2525
private fun Array<StackTraceElement>.remapClassNames() =
2626
map { element ->
2727
StackTraceElement(
28-
element.className.remappedName,
29-
element.methodName.remappedName,
28+
element.className.simpleRemappedName,
29+
element.methodName.simpleRemappedName,
3030
element.fileName,
3131
element.lineNumber
3232
)

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

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import net.minecraft.util.Identifier
3838
import net.minecraft.util.math.BlockPos
3939
import net.minecraft.util.math.ChunkPos
4040
import org.apache.logging.log4j.Logger
41+
import java.io.File
4142
import java.lang.reflect.InaccessibleObjectException
4243
import java.util.*
4344
import 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

Comments
 (0)