mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-18 11:29:13 +00:00
Resolve field obfuscations in superclass mappings
This commit is contained in:
1 parent
068f64be00
commit
e2275d15e2
6 files changed
+115
-7
No files matched your search
@@ -609,7 +609,7 @@ class AnnotatedMixin {
|
||||
}
|
||||
|
||||
if (targetMember.isField()) {
|
||||
ObfuscationData<String> obfFieldData = this.mixins.getObfField(targetMember.toSrg());
|
||||
ObfuscationData<String> obfFieldData = this.getObfFieldRecursive(targetMember);
|
||||
if (obfFieldData.isEmpty()) {
|
||||
this.mixins.printMessage(Kind.WARNING, "Cannot find field mapping for @At(" + key + ") '" + target + "'", element, inject);
|
||||
return false;
|
||||
@@ -627,6 +627,32 @@ class AnnotatedMixin {
|
||||
return true;
|
||||
}
|
||||
|
||||
private ObfuscationData<String> getObfFieldRecursive(MemberInfo targetMember) {
|
||||
ObfuscationData<String> targetNames = this.mixins.getObfClass(targetMember.owner);
|
||||
ObfuscationData<String> obfFieldData = this.mixins.getObfField(targetMember.toSrg());
|
||||
try {
|
||||
while (obfFieldData.isEmpty()) {
|
||||
TypeHandle targetType = this.mixins.getTypeHandle(targetMember.owner);
|
||||
if (targetType == null) {
|
||||
return obfFieldData;
|
||||
}
|
||||
TypeHandle superClass = targetType.getSuperclass();
|
||||
if (superClass == null) {
|
||||
return obfFieldData;
|
||||
}
|
||||
targetMember = targetMember.move(superClass.getName());
|
||||
obfFieldData = this.mixins.getObfField(targetMember.toSrg());
|
||||
if (!obfFieldData.isEmpty()) {
|
||||
for (ObfuscationType type : obfFieldData) {
|
||||
obfFieldData.add(type, MemberInfo.fromSrgField(obfFieldData.get(type), "").move(targetNames.get(type)).toSrg());
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
return obfFieldData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a field mapping to the local table
|
||||
*/
|
||||
|
||||
@@ -344,6 +344,22 @@ class AnnotatedMixins implements Messager, ITokenProvider, IOptionProvider, ITyp
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*/
|
||||
public ObfuscationData<String> getObfClass(String className) {
|
||||
ObfuscationData<String> data = new ObfuscationData<String>(className);
|
||||
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
String obfClass = targetEnv.getObfClass(className);
|
||||
if (obfClass != null) {
|
||||
data.add(targetEnv.getType(), obfClass);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void addMethodMapping(String className, String reference, ObfuscationData<MethodData> obfMethodData) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
|
||||
@@ -31,9 +31,19 @@ import java.util.Map;
|
||||
public class ObfuscationData<T> implements Iterable<ObfuscationType> {
|
||||
|
||||
private final Map<ObfuscationType, T> data = new HashMap<ObfuscationType, T>();
|
||||
|
||||
public void add(ObfuscationType type, T method) {
|
||||
this.data.put(type, method);
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
public ObfuscationData() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ObfuscationData(T defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public void add(ObfuscationType type, T value) {
|
||||
this.data.put(type, value);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
@@ -41,7 +51,8 @@ public class ObfuscationData<T> implements Iterable<ObfuscationType> {
|
||||
}
|
||||
|
||||
public T get(ObfuscationType type) {
|
||||
return this.data.get(type);
|
||||
T value = this.data.get(type);
|
||||
return value != null ? value : this.defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -190,6 +190,16 @@ class TargetObfuscationEnvironment {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a class
|
||||
*/
|
||||
public String getObfClass(String className) {
|
||||
if (this.initSrgs()) {
|
||||
return this.srgs.classMap.get(className);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out generated srgs
|
||||
|
||||
@@ -35,6 +35,7 @@ import javax.lang.model.element.PackageElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
@@ -145,6 +146,23 @@ public class TypeHandle {
|
||||
public TypeMirror getType() {
|
||||
return this.element != null ? this.element.asType() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enclosed element's superclass if available, or null if this
|
||||
* class does not have a superclass
|
||||
*/
|
||||
public TypeHandle getSuperclass() {
|
||||
if (this.element == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TypeMirror superClass = this.element.getSuperclass();
|
||||
if (superClass == null || superClass.getKind() == TypeKind.NONE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TypeHandle((DeclaredType)superClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the element is probably public
|
||||
|
||||
Reference in new issue
Block a user