From 31326ec2f112edd100936c8b151c20440897aef1 Mon Sep 17 00:00:00 2001 From: Su5eD <su5ed@outlook.com> Date: Wed, 24 Jul 2024 11:35:36 +0200 Subject: [PATCH] Add annotation node to MethodSliceContext --- .../java/org/sinytra/adapter/patch/MethodContextImpl.java | 8 ++++---- .../org/sinytra/adapter/patch/util/MockMixinRuntime.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java b/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java index b1271fb..0c89e05 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/MethodContextImpl.java @@ -179,7 +179,7 @@ private List<AbstractInsnNode> computeInjectionTargetInsns(@Nullable TargetPair // Parse injection point InjectionPoint injectionPoint = InjectionPoint.parse(mixinContext, this.methodNode, annotation.unwrap(), atNode.unwrap()); // Find target instructions - InsnList instructions = getSlicedInsns(annotation, this.classNode, this.methodNode, target.classNode(), target.methodNode(), patchContext()); + InsnList instructions = getSlicedInsns(annotation, target.classNode(), target.methodNode(), patchContext()); List<AbstractInsnNode> targetInsns = new ArrayList<>(); try { injectionPoint.find(target.methodNode().desc, instructions, targetInsns); @@ -209,15 +209,15 @@ public boolean failsDirtyInjectionCheck() { return dirtyPair != null && findInjectionTargetInsns(dirtyPair).isEmpty(); } - private InsnList getSlicedInsns(AnnotationHandle parentAnnotation, ClassNode classNode, MethodNode injectorMethod, ClassNode targetClass, MethodNode targetMethod, PatchContext context) { + private InsnList getSlicedInsns(AnnotationHandle parentAnnotation, ClassNode targetClass, MethodNode targetMethod, PatchContext context) { return parentAnnotation.<AnnotationNode>getValue("slice") .map(handle -> { Object value = handle.get(); return value instanceof List<?> list ? (AnnotationNode) list.get(0) : (AnnotationNode) value; }) .map(sliceAnn -> { - IMixinContext mixinContext = MockMixinRuntime.forClass(classNode.name, targetClass.name, context.environment()); - ISliceContext sliceContext = MockMixinRuntime.forSlice(mixinContext, injectorMethod); + IMixinContext mixinContext = MockMixinRuntime.forClass(this.classNode.name, targetClass.name, context.environment()); + ISliceContext sliceContext = MockMixinRuntime.forSlice(mixinContext, this.methodNode, this.methodAnnotation.unwrap()); return computeSlicedInsns(sliceContext, sliceAnn, targetMethod); }) .orElse(targetMethod.instructions); diff --git a/definition/src/main/java/org/sinytra/adapter/patch/util/MockMixinRuntime.java b/definition/src/main/java/org/sinytra/adapter/patch/util/MockMixinRuntime.java index cabe7cc..7749f89 100644 --- a/definition/src/main/java/org/sinytra/adapter/patch/util/MockMixinRuntime.java +++ b/definition/src/main/java/org/sinytra/adapter/patch/util/MockMixinRuntime.java @@ -45,8 +45,8 @@ public static IMixinContext forClass(String className, String targetClass, Patch return new ClassMixinContext(className, targetClass, environment); } - public static ISliceContext forSlice(IMixinContext context, MethodNode methodNode) { - return new MethodSliceContext(context, methodNode); + public static ISliceContext forSlice(IMixinContext context, MethodNode methodNode, AnnotationNode annotationNode) { + return new MethodSliceContext(context, methodNode, annotationNode); } public static InjectionInfo forInjectionInfo(String className, String targetClass, PatchEnvironment environment) { @@ -61,7 +61,7 @@ public static InjectionInfo forInjectionInfo(String className, String targetClas } } - private record MethodSliceContext(IMixinContext context, MethodNode methodNode) implements ISliceContext { + private record MethodSliceContext(IMixinContext context, MethodNode methodNode, AnnotationNode annotationNode) implements ISliceContext { @Override public IMixinContext getMixin() { return this.context; @@ -75,7 +75,7 @@ public String remap(String reference) { //@formatter:off @Override public MethodSlice getSlice(String id) {throw new UnsupportedOperationException();} @Override public MethodNode getMethod() {return this.methodNode;} - @Override public AnnotationNode getAnnotationNode() {throw new UnsupportedOperationException();} + @Override public AnnotationNode getAnnotationNode() {return this.annotationNode;} @Override public ISelectorContext getParent() {throw new UnsupportedOperationException();} @Override public IAnnotationHandle getAnnotation() {throw new UnsupportedOperationException();} @Override public IAnnotationHandle getSelectorAnnotation() {throw new UnsupportedOperationException();}