mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-28 02:05:37 +00:00
Add support for pseudo mixins, closes #152. Version bump to 0.6.2.
This commit is contained in:
1 parent
bc810b25da
commit
946520c0ed
20 files changed
+627
-88
No files matched your search
@@ -62,7 +62,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.6.1";
|
||||
public static final String VERSION = "0.6.2";
|
||||
|
||||
// Consts
|
||||
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.mixin;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* A Mixin marked as <b>Pseudo</b> is allowed to target classes which are not
|
||||
* available at compile time and may not be available at runtime. This means
|
||||
* that certain restrictions apply:
|
||||
*
|
||||
* <p>In particular, the superclass requirement for pseudo mixins is extremely
|
||||
* important if the target has an obfuscated class in its hierarchy. For example
|
||||
* let's assume that we're mixing into a class <tt>SomeCustomScreen</tt> from
|
||||
* another party which extends <tt>GuiScreen</tt> which is obfuscated.
|
||||
* Attempting to inject into <tt>initGui</tt> will succeed at dev time and fail
|
||||
* at production time, because the reference is obfuscated. We can overcome this
|
||||
* by ensuring the mixin inherits from the same superclass, thus allowing
|
||||
* <tt>initGui</tt> to be resolved in the superclass hierarchy (this is not the
|
||||
* case for normal mixins).</p>
|
||||
*
|
||||
* <p>{@link Overwrite} methods which are <b>not</b> inherited from a superclass
|
||||
* (if the target is obfuscated) <b>must</b> be decorated manually with aliases.
|
||||
* </p>
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface Pseudo {
|
||||
|
||||
}
|
||||
@@ -1563,7 +1563,8 @@ public class ClassInfo extends TreeInfo {
|
||||
ClassNode classNode = TreeInfo.getClassNode(className);
|
||||
info = new ClassInfo(classNode);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
ClassInfo.logger.warn("Error loading class: {}", className);
|
||||
// ex.printStackTrace();
|
||||
}
|
||||
|
||||
// Put null in the cache if load failed
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Pseudo;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfig;
|
||||
@@ -681,6 +682,11 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
*/
|
||||
private final int priority;
|
||||
|
||||
/**
|
||||
* True if the mixin is annotated with {@link Pseudo}
|
||||
*/
|
||||
private final boolean virtual;
|
||||
|
||||
/**
|
||||
* Mixin targets, read from the {@link Mixin} annotation on the mixin class
|
||||
*/
|
||||
@@ -770,6 +776,7 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
// Read the class bytes and transform
|
||||
try {
|
||||
this.priority = this.readPriority(this.pendingState.getClassNode());
|
||||
this.virtual = this.readPseudo(this.pendingState.getClassNode());
|
||||
this.targetClasses = this.readTargetClasses(this.pendingState.getClassNode(), suppressPlugin);
|
||||
this.targetClassNames = Collections.unmodifiableList(Lists.transform(this.targetClasses, Functions.toStringFunction()));
|
||||
} catch (InvalidMixinException ex) {
|
||||
@@ -864,11 +871,15 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
private ClassInfo getTarget(String targetName, boolean checkPublic) throws InvalidMixinException {
|
||||
ClassInfo targetInfo = ClassInfo.forName(targetName);
|
||||
if (targetInfo == null) {
|
||||
this.handleTargetError(String.format("@Mixin target %s was not found %s", targetName, this));
|
||||
if (this.isVirtual()) {
|
||||
this.logger.debug("Skipping virtual target {} for {}", targetName, this);
|
||||
} else {
|
||||
this.handleTargetError(String.format("@Mixin target %s was not found %s", targetName, this));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
this.type.validateTarget(targetName, targetInfo);
|
||||
if (checkPublic && targetInfo.isPublic()) {
|
||||
if (checkPublic && targetInfo.isPublic() && !this.isVirtual()) {
|
||||
this.handleTargetError(String.format("@Mixin target %s is public in %s and should be specified in value", targetName, this));
|
||||
}
|
||||
return targetInfo;
|
||||
@@ -901,7 +912,11 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
Integer priority = ASMHelper.getAnnotationValue(mixin, "priority");
|
||||
return priority == null ? this.parent.getDefaultMixinPriority() : priority.intValue();
|
||||
}
|
||||
|
||||
|
||||
protected boolean readPseudo(ClassNode classNode) {
|
||||
return ASMHelper.getInvisibleAnnotation(classNode, Pseudo.class) != null;
|
||||
}
|
||||
|
||||
private boolean isReloading() {
|
||||
return this.pendingState instanceof Reloaded;
|
||||
}
|
||||
@@ -991,6 +1006,10 @@ class MixinInfo extends TreeInfo implements Comparable<MixinInfo>, IMixinInfo {
|
||||
public boolean isUnique() {
|
||||
return this.getState().isUnique();
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
return this.virtual;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the mixin class is actually class-loadable
|
||||
|
||||
@@ -123,6 +123,10 @@ public class SignaturePrinter {
|
||||
}
|
||||
}
|
||||
|
||||
public String getFormattedArgs() {
|
||||
return this.appendArgs(new StringBuilder(), true).toString();
|
||||
}
|
||||
|
||||
public String getReturnType() {
|
||||
return SignaturePrinter.getTypeName(this.returnType, false, this.fullyQualified);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user