Open-source multiplayer game server compatible with the RuneScape client https://www.openrs2.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
openrs2/asm/src/main/java/dev/openrs2/asm/remap/ClassForNameRemapper.kt

35 lines
1.1 KiB

package dev.openrs2.asm.remap
import dev.openrs2.asm.InsnMatcher
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.LdcInsnNode
import org.objectweb.asm.tree.MethodInsnNode
import org.objectweb.asm.tree.MethodNode
object ClassForNameRemapper {
private val INVOKE_MATCHER = InsnMatcher.compile("LDC INVOKESTATIC")
private fun isClassForName(match: List<AbstractInsnNode>): Boolean {
val ldc = match[0] as LdcInsnNode
if (ldc.cst !is String) {
return false
}
val invokestatic = match[1] as MethodInsnNode
return invokestatic.owner == "java/lang/Class"
&& invokestatic.name == "forName"
&& invokestatic.desc == "(Ljava/lang/String;)Ljava/lang/Class;"
}
@JvmStatic
fun remap(remapper: Remapper, method: MethodNode) {
INVOKE_MATCHER.match(method).filter(ClassForNameRemapper::isClassForName).forEach {
val ldc = it[0] as LdcInsnNode
val name = remapper.map(ldc.cst as String)
if (name != null) {
ldc.cst = name
}
}
}
}