mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-20 12:19:52 +00:00
Generate signatures for mixed classes, fixes nearly all decomp issues
This commit is contained in:
1 parent
4e75544ca5
commit
d2fe040cb7
8 files changed
+1440
-22
No files matched your search
@@ -107,7 +107,7 @@ public class AccessorInfo extends SpecialMethodInfo {
|
||||
/**
|
||||
* Pattern for matching accessor names (for inflector)
|
||||
*/
|
||||
protected static final Pattern PATTERN_ACCESSOR = Pattern.compile("^(get|set|is|invoke|call)(([A-Z])(.*?))(_\\$md.*)$");
|
||||
protected static final Pattern PATTERN_ACCESSOR = Pattern.compile("^(get|set|is|invoke|call)(([A-Z])(.*?))(_\\$md.*)?$");
|
||||
|
||||
/**
|
||||
* Accessor method argument types (raw, from method)
|
||||
|
||||
@@ -452,10 +452,8 @@ public abstract class InjectionPoint {
|
||||
/**
|
||||
* Parse an InjectionPoint from the supplied {@link At} annotation
|
||||
*
|
||||
* @param mixin Data for the mixin containing the annotation, used to obtain
|
||||
* @param info Data for the mixin containing the annotation, used to obtain
|
||||
* the refmap, amongst other things
|
||||
* @param method The annotated handler method
|
||||
* @param parent The parent annotation which owns this {@link At} annotation
|
||||
* @param at {@link At} annotation to parse information from
|
||||
* @return InjectionPoint parsed from the supplied data or null if parsing
|
||||
* failed
|
||||
|
||||
@@ -105,7 +105,7 @@ public class InjectorTarget {
|
||||
* Get the slice instructions for the specified
|
||||
*
|
||||
* @param injectionPoint
|
||||
* @return
|
||||
* @return slice
|
||||
*/
|
||||
public InsnList getSlice(InjectionPoint injectionPoint) {
|
||||
return this.getSlice(injectionPoint.getSlice());
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Member.Type;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinInfo.MixinClassNode;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
import org.spongepowered.asm.util.ClassSignature;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -629,6 +630,11 @@ public class ClassInfo extends TreeInfo {
|
||||
* Outer class reference, not initialised until required
|
||||
*/
|
||||
private ClassInfo outerClass;
|
||||
|
||||
/**
|
||||
* Class signature, lazy-loaded where possible
|
||||
*/
|
||||
private ClassSignature signature;
|
||||
|
||||
/**
|
||||
* Private constructor used to initialise the ClassInfo for {@link Object}
|
||||
@@ -703,10 +709,12 @@ public class ClassInfo extends TreeInfo {
|
||||
this.isProbablyStatic = isProbablyStatic;
|
||||
this.outerName = outerName;
|
||||
this.methodMapper = new MethodMapper(MixinEnvironment.getCurrentEnvironment(), this);
|
||||
this.signature = ClassSignature.ofLazy(classNode);
|
||||
}
|
||||
|
||||
void addInterface(String iface) {
|
||||
this.interfaces.add(iface);
|
||||
this.getSignature().addInterface(iface);
|
||||
}
|
||||
|
||||
void addMethod(MethodNode method) {
|
||||
@@ -856,6 +864,15 @@ public class ClassInfo extends TreeInfo {
|
||||
|
||||
return this.outerClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class signature
|
||||
*
|
||||
* @return signature as a {@link ClassSignature} instance
|
||||
*/
|
||||
public ClassSignature getSignature() {
|
||||
return this.signature.wake();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class targets
|
||||
|
||||
@@ -41,6 +41,8 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.lib.Label;
|
||||
import org.spongepowered.asm.lib.Opcodes;
|
||||
import org.spongepowered.asm.lib.Type;
|
||||
import org.spongepowered.asm.lib.signature.SignatureReader;
|
||||
import org.spongepowered.asm.lib.signature.SignatureVisitor;
|
||||
import org.spongepowered.asm.lib.tree.*;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
@@ -277,6 +279,7 @@ class MixinApplicatorStandard {
|
||||
protected final void applyMixin(MixinTargetContext mixin, ApplicatorPass pass) {
|
||||
switch (pass) {
|
||||
case MAIN:
|
||||
this.applySignature(mixin);
|
||||
this.applyInterfaces(mixin);
|
||||
this.applyAttributes(mixin);
|
||||
this.applyAnnotations(mixin);
|
||||
@@ -300,6 +303,10 @@ class MixinApplicatorStandard {
|
||||
}
|
||||
}
|
||||
|
||||
protected void applySignature(MixinTargetContext mixin) {
|
||||
this.context.mergeSignature(mixin.getSignature());
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixin interfaces implemented by the mixin class onto the target class
|
||||
*
|
||||
@@ -440,6 +447,12 @@ class MixinApplicatorStandard {
|
||||
|
||||
this.targetClass.methods.add(method);
|
||||
mixin.addMergedMethod(method);
|
||||
|
||||
if (method.signature != null) {
|
||||
SignatureVisitor sv = mixin.getSignature().getRemapper();
|
||||
new SignatureReader(method.signature).accept(sv);
|
||||
method.signature = sv.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,6 +66,7 @@ import org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError;
|
||||
import org.spongepowered.asm.obfuscation.RemapperChain;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.SourceMap.File;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
import org.spongepowered.asm.util.ClassSignature;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
|
||||
/**
|
||||
@@ -295,6 +296,15 @@ public class MixinTargetContext implements IReferenceMapperContext {
|
||||
return this.targetClassInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the signature for this mixin class
|
||||
*
|
||||
* @return signature
|
||||
*/
|
||||
public ClassSignature getSignature() {
|
||||
return this.mixin.getClassInfo().getSignature();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SourceMap stratum for this mixin
|
||||
*
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.injection.struct.Target;
|
||||
import org.spongepowered.asm.mixin.transformer.meta.SourceMap;
|
||||
import org.spongepowered.asm.util.ASMHelper;
|
||||
import org.spongepowered.asm.util.ClassSignature;
|
||||
|
||||
/**
|
||||
* Struct for containing target class information during mixin application
|
||||
@@ -71,6 +72,11 @@ class TargetClassContext {
|
||||
*/
|
||||
private final SourceMap sourceMap;
|
||||
|
||||
/**
|
||||
* Target class signature
|
||||
*/
|
||||
private final ClassSignature signature;
|
||||
|
||||
/**
|
||||
* Mixins to apply
|
||||
*/
|
||||
@@ -103,6 +109,7 @@ class TargetClassContext {
|
||||
this.className = name;
|
||||
this.classNode = classNode;
|
||||
this.classInfo = ClassInfo.fromClassNode(classNode);
|
||||
this.signature = this.classInfo.getSignature();
|
||||
this.mixins = mixins;
|
||||
this.sourceMap = new SourceMap(classNode.sourceFile);
|
||||
this.sourceMap.addFile(this.classNode);
|
||||
@@ -113,76 +120,85 @@ class TargetClassContext {
|
||||
return this.className;
|
||||
}
|
||||
|
||||
public boolean isApplied() {
|
||||
boolean isApplied() {
|
||||
return this.applied;
|
||||
}
|
||||
|
||||
public boolean isExportForced() {
|
||||
boolean isExportForced() {
|
||||
return this.forceExport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transformer session ID
|
||||
*/
|
||||
public String getSessionId() {
|
||||
String getSessionId() {
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the internal class name
|
||||
*/
|
||||
public String getName() {
|
||||
String getName() {
|
||||
return this.classNode.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class name
|
||||
*/
|
||||
public String getClassName() {
|
||||
String getClassName() {
|
||||
return this.className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class tree
|
||||
*/
|
||||
public ClassNode getClassNode() {
|
||||
ClassNode getClassNode() {
|
||||
return this.classNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class methods (from the tree)
|
||||
*/
|
||||
public List<MethodNode> getMethods() {
|
||||
List<MethodNode> getMethods() {
|
||||
return this.classNode.methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class fields (from the tree)
|
||||
*/
|
||||
public List<FieldNode> getFields() {
|
||||
List<FieldNode> getFields() {
|
||||
return this.classNode.fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target class metadata
|
||||
*/
|
||||
public ClassInfo getClassInfo() {
|
||||
ClassInfo getClassInfo() {
|
||||
return this.classInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mixins for this target class
|
||||
*/
|
||||
public SortedSet<MixinInfo> getMixins() {
|
||||
SortedSet<MixinInfo> getMixins() {
|
||||
return this.mixins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source map that is generated for the target class
|
||||
*/
|
||||
public SourceMap getSourceMap() {
|
||||
SourceMap getSourceMap() {
|
||||
return this.sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the supplied signature into this class's signature
|
||||
*
|
||||
* @param signature signature to merge
|
||||
*/
|
||||
void mergeSignature(ClassSignature signature) {
|
||||
this.signature.merge(signature);
|
||||
}
|
||||
|
||||
MethodNode findAliasedMethod(Deque<String> aliases, String desc) {
|
||||
String alias = aliases.poll();
|
||||
@@ -227,7 +243,7 @@ class TargetClassContext {
|
||||
* @param method method to get a target handle for
|
||||
* @return new or existing target handle for the supplied method
|
||||
*/
|
||||
public Target getTargetMethod(MethodNode method) {
|
||||
Target getTargetMethod(MethodNode method) {
|
||||
if (!this.classNode.methods.contains(method)) {
|
||||
throw new IllegalArgumentException("Invalid target method supplied to getTargetMethod()");
|
||||
}
|
||||
@@ -241,13 +257,13 @@ class TargetClassContext {
|
||||
return target;
|
||||
}
|
||||
|
||||
public String getUniqueName(MethodNode method, boolean preservePrefix) {
|
||||
String getUniqueName(MethodNode method, boolean preservePrefix) {
|
||||
String uniqueIndex = Integer.toHexString(this.nextUniqueMethodIndex++);
|
||||
String pattern = preservePrefix ? "%2$s_$md$%1$s$%3$s" : "md%s$%s$%s";
|
||||
return String.format(pattern, this.sessionId.substring(30), method.name, uniqueIndex);
|
||||
}
|
||||
|
||||
public String getUniqueName(FieldNode field) {
|
||||
String getUniqueName(FieldNode field) {
|
||||
String uniqueIndex = Integer.toHexString(this.nextUniqueFieldIndex++);
|
||||
return String.format("fd%s$%s$%s", this.sessionId.substring(30), field.name, uniqueIndex);
|
||||
}
|
||||
@@ -255,13 +271,15 @@ class TargetClassContext {
|
||||
/**
|
||||
* Apply mixins to this class
|
||||
*/
|
||||
public void applyMixins() {
|
||||
void applyMixins() {
|
||||
if (this.applied) {
|
||||
throw new IllegalStateException("Mixins already applied to target class " + this.className);
|
||||
}
|
||||
this.applied = true;
|
||||
MixinApplicatorStandard applicator = this.createApplicator();
|
||||
applicator.apply(this.mixins);
|
||||
|
||||
this.classNode.signature = this.signature.toString();
|
||||
}
|
||||
|
||||
private MixinApplicatorStandard createApplicator() {
|
||||
@@ -271,11 +289,10 @@ class TargetClassContext {
|
||||
return new MixinApplicatorStandard(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process {@link Debug} annotations on the class after application
|
||||
*/
|
||||
public void processDebugTasks() {
|
||||
void processDebugTasks() {
|
||||
if (!MixinEnvironment.getCurrentEnvironment().getOption(Option.DEBUG_VERBOSE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user