diff --git a/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java b/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java deleted file mode 100644 index aab5de9591..0000000000 --- a/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.java +++ /dev/null @@ -1,47 +0,0 @@ -package dev.openrs2.bundler.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.LdcInsnNode; -import org.objectweb.asm.tree.MethodNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class CachePathTransformer extends Transformer { - private static final Logger logger = LoggerFactory.getLogger(CachePathTransformer.class); - - private int paths; - - @Override - protected void preTransform(ClassPath classPath) { - paths = 0; - } - - @Override - protected boolean transformCode(ClassPath classPath, Library library, ClassNode clazz, MethodNode method) { - for (var insn : method.instructions) { - if (insn.getOpcode() != Opcodes.LDC) { - continue; - } - - var ldc = (LdcInsnNode) insn; - if (ldc.cst.equals(".jagex_cache_") || ldc.cst.equals(".file_store_")) { - ldc.cst = ".openrs2_cache_"; - paths++; - } else if (ldc.cst.equals("jagex_")) { - ldc.cst = ".openrs2_"; - paths++; - } - } - - return false; - } - - @Override - protected void postTransform(ClassPath classPath) { - logger.info("Updated {} cache paths", paths); - } -} diff --git a/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.kt b/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.kt new file mode 100644 index 0000000000..d5c817475e --- /dev/null +++ b/bundler/src/main/java/dev/openrs2/bundler/transform/CachePathTransformer.kt @@ -0,0 +1,46 @@ +package dev.openrs2.bundler.transform + +import com.github.michaelbull.logging.InlineLogger +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 + +class CachePathTransformer : Transformer() { + private var paths = 0 + + override fun preTransform(classPath: ClassPath) { + paths = 0 + } + + override fun transformCode(classPath: ClassPath, library: Library, clazz: ClassNode, method: MethodNode): Boolean { + for (insn in method.instructions) { + if (insn !is LdcInsnNode) { + continue + } + + when (insn.cst) { + ".jagex_cache_", ".file_store_" -> { + insn.cst = ".openrs2_cache_" + paths++ + } + "jagex_" -> { + insn.cst = ".openrs2_" + paths++ + } + } + } + + return false + } + + override fun postTransform(classPath: ClassPath) { + logger.info { "Updated $paths cache paths" } + } + + companion object { + private val logger = InlineLogger() + } +}