diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java deleted file mode 100644 index 53dac0b0cf..0000000000 --- a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java +++ /dev/null @@ -1,88 +0,0 @@ -package dev.openrs2.deob.transform; - -import java.util.ArrayList; -import java.util.List; - -import com.google.common.collect.ImmutableList; -import dev.openrs2.asm.classpath.ClassPath; -import dev.openrs2.asm.classpath.Library; -import dev.openrs2.asm.transform.Transformer; -import dev.openrs2.deob.annotation.OriginalArg; -import dev.openrs2.deob.annotation.OriginalClass; -import dev.openrs2.deob.annotation.OriginalMember; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AnnotationNode; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldNode; -import org.objectweb.asm.tree.MethodNode; - -public final class OriginalNameTransformer extends Transformer { - private static AnnotationNode createOriginalClassAnnotation(String name) { - var annotation = new AnnotationNode(Type.getDescriptor(OriginalClass.class)); - annotation.values = ImmutableList.of("value", name); - return annotation; - } - - private static AnnotationNode createOriginalMemberAnnotation(String owner, String name, String desc) { - var annotation = new AnnotationNode(Type.getDescriptor(OriginalMember.class)); - annotation.values = ImmutableList.of( - "owner", owner, - "name", name, - "descriptor", desc - ); - return annotation; - } - - private static AnnotationNode createOriginalArgAnnotation(int index) { - var annotation = new AnnotationNode(Type.getDescriptor(OriginalArg.class)); - annotation.values = ImmutableList.of("value", index); - return annotation; - } - - @Override - public boolean transformClass(ClassPath classPath, Library library, ClassNode clazz) { - if (clazz.invisibleAnnotations == null) { - clazz.invisibleAnnotations = new ArrayList<>(); - } - clazz.invisibleAnnotations.add(createOriginalClassAnnotation(clazz.name)); - - return false; - } - - @Override - public boolean transformField(ClassPath classPath, Library library, ClassNode clazz, FieldNode field) { - if (field.invisibleAnnotations == null) { - field.invisibleAnnotations = new ArrayList<>(); - } - field.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, field.name, field.desc)); - - return false; - } - - @SuppressWarnings("unchecked") - @Override - public boolean preTransformMethod(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) { - if (method.name.equals("") || method.name.equals("")) { - return false; - } - - if (method.invisibleAnnotations == null) { - method.invisibleAnnotations = new ArrayList<>(); - } - method.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, method.name, method.desc)); - - int args = Type.getArgumentTypes(method.desc).length; - if (method.invisibleParameterAnnotations == null) { - method.invisibleParameterAnnotations = (List[]) new List[args]; - } - for (var i = 0; i < method.invisibleParameterAnnotations.length; i++) { - var annotations = method.invisibleParameterAnnotations[i]; - if (annotations == null) { - annotations = method.invisibleParameterAnnotations[i] = new ArrayList<>(); - } - annotations.add(createOriginalArgAnnotation(i)); - } - - return false; - } -} diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.kt new file mode 100644 index 0000000000..d6c9d0cf0e --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.kt @@ -0,0 +1,91 @@ +package dev.openrs2.deob.transform + +import dev.openrs2.asm.classpath.ClassPath +import dev.openrs2.asm.classpath.Library +import dev.openrs2.asm.transform.Transformer +import dev.openrs2.deob.annotation.OriginalArg +import dev.openrs2.deob.annotation.OriginalClass +import dev.openrs2.deob.annotation.OriginalMember +import org.objectweb.asm.Type +import org.objectweb.asm.tree.AnnotationNode +import org.objectweb.asm.tree.ClassNode +import org.objectweb.asm.tree.FieldNode +import org.objectweb.asm.tree.MethodNode + +class OriginalNameTransformer : Transformer() { + public override fun transformClass(classPath: ClassPath, library: Library, clazz: ClassNode): Boolean { + if (clazz.invisibleAnnotations == null) { + clazz.invisibleAnnotations = mutableListOf() + } + clazz.invisibleAnnotations.add(createOriginalClassAnnotation(clazz.name)) + return false + } + + public override fun transformField( + classPath: ClassPath, + library: Library, + clazz: ClassNode, + field: FieldNode + ): Boolean { + if (field.invisibleAnnotations == null) { + field.invisibleAnnotations = mutableListOf() + } + field.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, field.name, field.desc)) + return false + } + + public override fun preTransformMethod( + classPath: ClassPath, + library: Library, + clazz: ClassNode, + method: MethodNode + ): Boolean { + if (method.name == "" || method.name == "") { + return false + } + + if (method.invisibleAnnotations == null) { + method.invisibleAnnotations = mutableListOf() + } + method.invisibleAnnotations.add(createOriginalMemberAnnotation(clazz.name, method.name, method.desc)) + + val args = Type.getArgumentTypes(method.desc).size + if (method.invisibleParameterAnnotations == null) { + method.invisibleParameterAnnotations = arrayOfNulls(args) + } + for (i in method.invisibleParameterAnnotations.indices) { + var annotations = method.invisibleParameterAnnotations[i] + if (annotations == null) { + annotations = mutableListOf() + method.invisibleParameterAnnotations[i] = annotations + } + annotations.add(createOriginalArgAnnotation(i)) + } + + return false + } + + companion object { + private fun createOriginalClassAnnotation(name: String): AnnotationNode { + val annotation = AnnotationNode(Type.getDescriptor(OriginalClass::class.java)) + annotation.values = listOf("value", name) + return annotation + } + + private fun createOriginalMemberAnnotation(owner: String, name: String, desc: String): AnnotationNode { + val annotation = AnnotationNode(Type.getDescriptor(OriginalMember::class.java)) + annotation.values = listOf( + "owner", owner, + "name", name, + "descriptor", desc + ) + return annotation + } + + private fun createOriginalArgAnnotation(index: Int): AnnotationNode { + val annotation = AnnotationNode(Type.getDescriptor(OriginalArg::class.java)) + annotation.values = listOf("value", index) + return annotation + } + } +}