mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-25 04:04:21 +00:00
0.7.9 - Allow certain injectors to target mixin methods, closes #251
This commit is contained in:
1 parent
1f936baea1
commit
ba0c777116
13 files changed
+100
-17
No files matched your search
@@ -60,7 +60,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.7.8";
|
||||
public static final String VERSION = "0.7.9";
|
||||
|
||||
/**
|
||||
* Log all the things
|
||||
|
||||
@@ -215,6 +215,22 @@ public abstract class InjectionPoint {
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a priority check in the context of this injection point. A priority
|
||||
* check should return <tt>true</tt> if the injection point is allowed to
|
||||
* inject given the relative priorities of the <em>target</em> (a method
|
||||
* merged by another mixin with <tt>targetPriority</tt>) and the incoming
|
||||
* mixin with priority <tt>mixinPriority</tt>.
|
||||
*
|
||||
* @param targetPriority Priority of the mixin which originally merged the
|
||||
* target method in question
|
||||
* @param mixinPriority Priority of the mixin which owns the owning injector
|
||||
* @return true if the priority check succeeds
|
||||
*/
|
||||
public boolean checkPriority(int targetPriority, int mixinPriority) {
|
||||
return targetPriority < mixinPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find injection points in the supplied insn list
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
|
||||
import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
|
||||
import org.spongepowered.asm.mixin.refmap.IMixinContext;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.util.Bytecode;
|
||||
|
||||
@@ -214,12 +215,21 @@ public abstract class Injector {
|
||||
* @return Target insn nodes in the target method
|
||||
*/
|
||||
private Collection<TargetNode> findTargetNodes(InjectorTarget injectorTarget, List<InjectionPoint> injectionPoints) {
|
||||
IMixinContext mixin = this.info.getContext();
|
||||
MethodNode method = injectorTarget.getMethod();
|
||||
Map<Integer, TargetNode> targetNodes = new TreeMap<Integer, TargetNode>();
|
||||
Collection<AbstractInsnNode> nodes = new ArrayList<AbstractInsnNode>(32);
|
||||
|
||||
|
||||
for (InjectionPoint injectionPoint : injectionPoints) {
|
||||
nodes.clear();
|
||||
|
||||
if (injectorTarget.isMerged()
|
||||
&& !mixin.getClassName().equals(injectorTarget.getMergedBy())
|
||||
&& !injectionPoint.checkPriority(injectorTarget.getMergedPriority(), mixin.getPriority())) {
|
||||
throw new InvalidInjectionException(this.info, String.format(
|
||||
"%s on %s with priority %d cannot inject into %s merged by %s with priority %d", injectionPoint, this, mixin.getPriority(),
|
||||
injectorTarget, injectorTarget.getMergedBy(), injectorTarget.getMergedPriority()));
|
||||
}
|
||||
|
||||
if (this.findTargetNodes(method, injectionPoint, injectorTarget.getSlice(injectionPoint), nodes)) {
|
||||
for (AbstractInsnNode insn : nodes) {
|
||||
|
||||
@@ -27,10 +27,14 @@ package org.spongepowered.asm.mixin.injection.code;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.spongepowered.asm.lib.tree.AnnotationNode;
|
||||
import org.spongepowered.asm.lib.tree.InsnList;
|
||||
import org.spongepowered.asm.lib.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.MixinMerged;
|
||||
import org.spongepowered.asm.util.Annotations;
|
||||
|
||||
/**
|
||||
* Couples {@link MethodSlice method slices} to a {@link Target} for injection
|
||||
@@ -52,6 +56,10 @@ public class InjectorTarget {
|
||||
* Target method data
|
||||
*/
|
||||
private final Target target;
|
||||
|
||||
private final String mergedBy;
|
||||
|
||||
private final int mergedPriority;
|
||||
|
||||
/**
|
||||
* ctor
|
||||
@@ -62,6 +70,15 @@ public class InjectorTarget {
|
||||
public InjectorTarget(ISliceContext context, Target target) {
|
||||
this.context = context;
|
||||
this.target = target;
|
||||
|
||||
AnnotationNode merged = Annotations.getVisible(target.method, MixinMerged.class);
|
||||
this.mergedBy = Annotations.<String>getValue(merged, "mixin");
|
||||
this.mergedPriority = Annotations.<Integer>getValue(merged, "priority", IMixinConfig.DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.target.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +95,29 @@ public class InjectorTarget {
|
||||
return this.target.method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this target method was merged by another mixin
|
||||
*/
|
||||
public boolean isMerged() {
|
||||
return this.mergedBy != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the mixin which merged this method, returns null for non-
|
||||
* mixin methods
|
||||
*/
|
||||
public String getMergedBy() {
|
||||
return this.mergedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the priority of the mixin which merged this method, or default
|
||||
* priority for non-mixin methods
|
||||
*/
|
||||
public int getMergedPriority() {
|
||||
return this.mergedPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the slice instructions for the specified slice id
|
||||
*
|
||||
|
||||
@@ -65,6 +65,11 @@ public class BeforeFinalReturn extends InjectionPoint {
|
||||
|
||||
this.context = data.getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPriority(int targetPriority, int ownerPriority) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
|
||||
|
||||
@@ -78,6 +78,11 @@ public class BeforeReturn extends InjectionPoint {
|
||||
|
||||
this.ordinal = data.getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPriority(int targetPriority, int ownerPriority) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
|
||||
|
||||
@@ -49,6 +49,11 @@ public class MethodHead extends InjectionPoint {
|
||||
public MethodHead(InjectionPointData data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPriority(int targetPriority, int ownerPriority) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
|
||||
|
||||
@@ -430,17 +430,9 @@ public abstract class InjectionInfo extends SpecialMethodInfo implements ISliceC
|
||||
return;
|
||||
}
|
||||
|
||||
String owner = Annotations.<String>getValue(merged, "mixin");
|
||||
int priority = Annotations.<Integer>getValue(merged, "priority");
|
||||
|
||||
if (priority >= this.mixin.getPriority() && !owner.equals(this.mixin.getClassName())) {
|
||||
throw new InvalidInjectionException(this, String.format("%s cannot inject into %s::%s%s merged by %s with priority %d", this,
|
||||
this.classNode.name, target.name, target.desc, owner, priority));
|
||||
}
|
||||
|
||||
if (Annotations.getVisible(target, Final.class) != null) {
|
||||
throw new InvalidInjectionException(this, String.format("%s cannot inject into @Final method %s::%s%s merged by %s", this,
|
||||
this.classNode.name, target.name, target.desc, owner));
|
||||
this.classNode.name, target.name, target.desc, Annotations.<String>getValue(merged, "mixin")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,13 @@ public interface IMixinContext {
|
||||
* Get the mixin transformer extension manager
|
||||
*/
|
||||
public abstract Extensions getExtensions();
|
||||
|
||||
/**
|
||||
* Get the mixin class name
|
||||
*
|
||||
* @return the mixin class name
|
||||
*/
|
||||
public abstract String getClassName();
|
||||
|
||||
/**
|
||||
* Get the internal mixin class name
|
||||
|
||||
@@ -288,6 +288,7 @@ public class MixinTargetContext extends ClassContext implements IMixinContext {
|
||||
*
|
||||
* @return the mixin class name
|
||||
*/
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return this.mixin.getClassName();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user