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.
49 lines
1.6 KiB
49 lines
1.6 KiB
package dev.openrs2.bundler.transform
|
|
|
|
import com.github.michaelbull.logging.InlineLogger
|
|
import dev.openrs2.asm.InsnMatcher
|
|
import dev.openrs2.asm.classpath.ClassPath
|
|
import dev.openrs2.asm.classpath.Library
|
|
import dev.openrs2.asm.transform.Transformer
|
|
import org.objectweb.asm.tree.ClassNode
|
|
import org.objectweb.asm.tree.LdcInsnNode
|
|
import org.objectweb.asm.tree.MethodNode
|
|
import javax.inject.Singleton
|
|
|
|
@Singleton
|
|
class LoadLibraryTransformer : Transformer() {
|
|
private var jnilibs = 0
|
|
private var amd64Checks = 0
|
|
|
|
override fun preTransform(classPath: ClassPath) {
|
|
jnilibs = 0
|
|
amd64Checks = 0
|
|
}
|
|
|
|
override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean {
|
|
val jnilib = method.instructions.find { it is LdcInsnNode && it.cst == "libjaggl.jnilib" } ?: return false
|
|
jnilib as LdcInsnNode
|
|
jnilib.cst = "libjaggl.dylib"
|
|
jnilibs++
|
|
|
|
for (match in AMD64_CHECK_MATCHER.match(method)) {
|
|
val ldc = match[1] as LdcInsnNode
|
|
if (ldc.cst == "amd64") {
|
|
match.forEach(method.instructions::remove)
|
|
amd64Checks++
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
override fun postTransform(classPath: ClassPath) {
|
|
logger.info { "Replaced $jnilibs jnilibs with dylibs and removed $amd64Checks amd64 jagmisc checks" }
|
|
}
|
|
|
|
private companion object {
|
|
private val logger = InlineLogger()
|
|
private val AMD64_CHECK_MATCHER =
|
|
InsnMatcher.compile("GETSTATIC LDC INVOKEVIRTUAL IFNE GETSTATIC LDC INVOKEVIRTUAL IFNE")
|
|
}
|
|
}
|
|
|