mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-19 16:29:45 +00:00
Fix staticness check and functionality of ModifyVariable in constructors
This commit is contained in:
1 parent
ce622cdfa6
commit
66bdb7b3b0
3 files changed
+44
-9
No files matched your search
+4
-5
@@ -35,6 +35,7 @@ import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.InjectionPoint.RestrictTargetLevel;
|
||||
import org.spongepowered.asm.mixin.injection.code.Injector;
|
||||
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
@@ -121,16 +122,12 @@ public class ModifyVariableInjector extends Injector {
|
||||
protected void sanityCheck(Target target, List<InjectionPoint> injectionPoints) {
|
||||
super.sanityCheck(target, injectionPoints);
|
||||
|
||||
if (target.isStatic != this.isStatic) {
|
||||
throw new InvalidInjectionException(this.info, "'static' of variable modifier method does not match target in " + this);
|
||||
}
|
||||
|
||||
int ordinal = this.discriminator.getOrdinal();
|
||||
if (ordinal < -1) {
|
||||
throw new InvalidInjectionException(this.info, "Invalid ordinal " + ordinal + " specified in " + this);
|
||||
}
|
||||
|
||||
if (this.discriminator.getIndex() == 0 && !this.isStatic) {
|
||||
if (this.discriminator.getIndex() == 0 && !target.isStatic) {
|
||||
throw new InvalidInjectionException(this.info, "Invalid index 0 specified in non-static variable modifier " + this);
|
||||
}
|
||||
}
|
||||
@@ -149,6 +146,8 @@ public class ModifyVariableInjector extends Injector {
|
||||
if (this.discriminator.printLVT()) {
|
||||
this.printLocals(target, context);
|
||||
}
|
||||
|
||||
this.checkTargetForNode(target, node, RestrictTargetLevel.ALLOW_ALL);
|
||||
|
||||
InjectorData handler = new InjectorData(target, "handler", false);
|
||||
this.validateParams(handler, this.returnType, this.returnType);
|
||||
|
||||
@@ -72,10 +72,27 @@ import com.google.common.collect.ImmutableSet;
|
||||
*/
|
||||
public final class ClassInfo {
|
||||
|
||||
/**
|
||||
* Include <tt>private</tt> members when running a member search
|
||||
*/
|
||||
public static final int INCLUDE_PRIVATE = Opcodes.ACC_PRIVATE;
|
||||
|
||||
/**
|
||||
* Include <tt>private</tt> members when running a member search
|
||||
*/
|
||||
public static final int INCLUDE_STATIC = Opcodes.ACC_STATIC;
|
||||
|
||||
/**
|
||||
* Include <tt>private</tt> <b>and</b> <tt>static</tt> members when running
|
||||
* a member search
|
||||
*/
|
||||
public static final int INCLUDE_ALL = ClassInfo.INCLUDE_PRIVATE | ClassInfo.INCLUDE_STATIC;
|
||||
|
||||
/**
|
||||
* Include instance and class initialisers when running a method search
|
||||
*/
|
||||
public static final int INCLUDE_INITIALISERS = 0x40000;
|
||||
|
||||
/**
|
||||
* Search type for the findInHierarchy methods, replaces a boolean flag
|
||||
* which made calling code difficult to read
|
||||
@@ -682,9 +699,14 @@ public final class ClassInfo {
|
||||
* Interfaces
|
||||
*/
|
||||
private final Set<String> interfaces;
|
||||
|
||||
/**
|
||||
* Constructors and initialisers in this class
|
||||
*/
|
||||
private final Set<Method> initialisers;
|
||||
|
||||
/**
|
||||
* Public and protected methods (instance) methods in this class
|
||||
* Methods in this class
|
||||
*/
|
||||
private final Set<Method> methods;
|
||||
|
||||
@@ -754,6 +776,9 @@ public final class ClassInfo {
|
||||
this.superName = null;
|
||||
this.outerName = null;
|
||||
this.isProbablyStatic = true;
|
||||
this.initialisers = ImmutableSet.<Method>of(
|
||||
new Method("<init>", "()V")
|
||||
);
|
||||
this.methods = ImmutableSet.<Method>of(
|
||||
new Method("getClass", "()Ljava/lang/Class;"),
|
||||
new Method("hashCode", "()I"),
|
||||
@@ -787,6 +812,7 @@ public final class ClassInfo {
|
||||
try {
|
||||
this.name = classNode.name;
|
||||
this.superName = classNode.superName != null ? classNode.superName : ClassInfo.JAVA_LANG_OBJECT;
|
||||
this.initialisers = new HashSet<Method>();
|
||||
this.methods = new HashSet<Method>();
|
||||
this.fields = new HashSet<Field>();
|
||||
this.isInterface = ((classNode.access & Opcodes.ACC_INTERFACE) != 0);
|
||||
@@ -839,7 +865,9 @@ public final class ClassInfo {
|
||||
}
|
||||
|
||||
private void addMethod(MethodNode method, boolean injected) {
|
||||
if (!method.name.startsWith("<")) {
|
||||
if (method.name.startsWith("<")) {
|
||||
this.initialisers.add(new Method(method, injected));
|
||||
} else {
|
||||
this.methods.add(new Method(method, injected));
|
||||
}
|
||||
}
|
||||
@@ -1739,8 +1767,8 @@ public final class ClassInfo {
|
||||
* @param memberType Type of member list to search
|
||||
* @return the field object or null if the field could not be resolved
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <M extends Member> M findMember(String name, String desc, int flags, Type memberType) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<M> members = (Set<M>)(memberType == Type.METHOD ? this.methods : this.fields);
|
||||
|
||||
for (M member : members) {
|
||||
@@ -1748,6 +1776,14 @@ public final class ClassInfo {
|
||||
return member;
|
||||
}
|
||||
}
|
||||
|
||||
if (memberType == Type.METHOD && (flags & ClassInfo.INCLUDE_INITIALISERS) != 0) {
|
||||
for (Method ctor : this.initialisers) {
|
||||
if (ctor.equals(name, desc) && ctor.matchesFlags(flags)) {
|
||||
return (M)ctor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public final class Locals {
|
||||
if (classInfo == null) {
|
||||
throw new LVTGeneratorError("Could not load class metadata for " + classNode.name + " generating LVT for " + method.name);
|
||||
}
|
||||
Method methodInfo = classInfo.findMethod(method);
|
||||
Method methodInfo = classInfo.findMethod(method, method.access | ClassInfo.INCLUDE_INITIALISERS);
|
||||
if (methodInfo == null) {
|
||||
throw new LVTGeneratorError("Could not locate method metadata for " + method.name + " generating LVT in " + classNode.name);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user