From cc78376cc1f904d35db56a71a388afe81248d278 Mon Sep 17 00:00:00 2001 From: Nolij Date: Sun, 24 Sep 2023 18:16:19 -0400 Subject: [PATCH] allow use of @CreateStatic on non-static methods (will convert to static) to get around mixin validations --- gradle.properties | 2 +- .../feltmc/feltasm/asm/FeltASMBootstrap.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0189271..82994b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G # Mod Properties -mod_version = 0.2.2 +mod_version = 0.3.0 maven_group = net.feltmc archives_base_name = feltasm asm_version=9.5 diff --git a/src/main/java/net/feltmc/feltasm/asm/FeltASMBootstrap.java b/src/main/java/net/feltmc/feltasm/asm/FeltASMBootstrap.java index 2c17b90..92a47d5 100644 --- a/src/main/java/net/feltmc/feltasm/asm/FeltASMBootstrap.java +++ b/src/main/java/net/feltmc/feltasm/asm/FeltASMBootstrap.java @@ -42,9 +42,25 @@ public static void apply(String targetClassName, ClassNode targetClass, String m var method = new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, methodNode.name, methodNode.desc, methodNode.signature, methodNode.exceptions != null ? methodNode.exceptions.toArray(String[]::new) : null); method.visitCode(); - - method.instructions.add(methodNode.instructions); - method.localVariables.addAll(methodNode.localVariables); + + for (var insnNode : methodNode.instructions) { + if (insnNode instanceof FieldInsnNode fieldInsnNode && + fieldInsnNode.owner.equals(slashedMixinClassName)) { + fieldInsnNode.owner = slashedTargetClassName; + method.instructions.add(fieldInsnNode); + } else if (insnNode instanceof MethodInsnNode methodInsnNode && + methodInsnNode.owner.equals(slashedMixinClassName)) { + methodInsnNode.owner = slashedTargetClassName; + method.instructions.add(methodInsnNode); + } else { + method.instructions.add(insnNode); + } + } + + for (LocalVariableNode localVariable : methodNode.localVariables) { + if (!localVariable.name.equals("this")) + method.localVariables.add(localVariable); + } method.visitEnd();