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.
39 lines
1.2 KiB
39 lines
1.2 KiB
package dev.openrs2.deob.transform
|
|
|
|
import dev.openrs2.asm.classpath.ClassPath
|
|
import dev.openrs2.asm.classpath.Library
|
|
import dev.openrs2.asm.transform.Transformer
|
|
import org.objectweb.asm.Opcodes
|
|
import org.objectweb.asm.tree.ClassNode
|
|
import org.objectweb.asm.tree.MethodNode
|
|
import javax.inject.Singleton
|
|
|
|
@Singleton
|
|
class MethodOrderTransformer : Transformer() {
|
|
override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean {
|
|
clazz.methods.sortWith(STATIC_COMPARATOR.then(INIT_COMPARATOR))
|
|
return false
|
|
}
|
|
|
|
private companion object {
|
|
private val STATIC_COMPARATOR = Comparator<MethodNode> { a, b ->
|
|
val aStatic = a.access and Opcodes.ACC_STATIC != 0
|
|
val bStatic = b.access and Opcodes.ACC_STATIC != 0
|
|
when {
|
|
aStatic && !bStatic -> -1
|
|
!aStatic && bStatic -> 1
|
|
else -> 0
|
|
}
|
|
}
|
|
|
|
private val INIT_COMPARATOR = Comparator<MethodNode> { a, b ->
|
|
val aInit = a.name.startsWith('<')
|
|
val bInit = b.name.startsWith('<')
|
|
when {
|
|
aInit && !bInit -> -1
|
|
!aInit && bInit -> 1
|
|
else -> 0
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|