Skip to content

Commit

Permalink
Fix: Register ClassInfos for generated classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
LlamaLad7 committed May 8, 2023
1 parent 568546d commit fa9edbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void defineClass(ClassNode node, MethodHandles.Lookup scope) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
node.accept(writer);
DEFINER.define(node.name.replace('/', '.'), writer.toByteArray(), scope);
MixinInternals.registerClassInfo(node);
}

@FunctionalInterface
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/llamalad7/mixinextras/utils/MixinInternals.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
import org.spongepowered.asm.mixin.transformer.ClassInfo;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
import org.spongepowered.asm.mixin.transformer.ext.IExtension;
Expand All @@ -31,6 +32,7 @@ public class MixinInternals {
private static final Field INJECTION_INFO_TARGET_NODES_FIELD;
private static final Field INJECTION_NODE_DECORATIONS_FIELD;
private static final Field INJECTION_INFO_INJECTOR_FIELD;
private static final Method CLASS_INFO_FROM_CLASS_NODE_METHOD;

static {
try {
Expand All @@ -53,6 +55,8 @@ public class MixinInternals {
INJECTION_NODE_DECORATIONS_FIELD.setAccessible(true);
INJECTION_INFO_INJECTOR_FIELD = InjectionInfo.class.getDeclaredField("injector");
INJECTION_INFO_INJECTOR_FIELD.setAccessible(true);
CLASS_INFO_FROM_CLASS_NODE_METHOD = ClassInfo.class.getDeclaredMethod("fromClassNode", ClassNode.class);
CLASS_INFO_FROM_CLASS_NODE_METHOD.setAccessible(true);
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
throw new RuntimeException("Failed to access some mixin internals, please report to LlamaLad7!", e);
}
Expand Down Expand Up @@ -139,4 +143,12 @@ private static ClassNode getClassNode(IMixinInfo mixin) {
}
}

public static void registerClassInfo(ClassNode classNode) {
try {
CLASS_INFO_FROM_CLASS_NODE_METHOD.invoke(null, classNode);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to use mixin internals, please report to LlamaLad7!", e);
}
}

}

0 comments on commit fa9edbd

Please sign in to comment.