mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-18 07:59:14 +00:00
This commit is contained in:
1 parent
2c9e3d1d39
commit
5afccbd4dd
15 files changed
+382
-85
No files matched your search
@@ -35,6 +35,7 @@ import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.MethodData;
|
||||
import org.spongepowered.asm.util.ConstraintParser;
|
||||
import org.spongepowered.asm.util.ConstraintParser.Constraint;
|
||||
import org.spongepowered.asm.util.ConstraintViolationException;
|
||||
@@ -43,8 +44,6 @@ import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
|
||||
|
||||
import net.minecraftforge.srg2source.rangeapplier.MethodData;
|
||||
|
||||
abstract class AnnotatedMixinElementHandler {
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,13 +36,12 @@ import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.InvalidMemberDescriptorException;
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.obfuscation.MethodData;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.struct.Message;
|
||||
|
||||
import net.minecraftforge.srg2source.rangeapplier.MethodData;
|
||||
|
||||
class AnnotatedMixinInjectorHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
AnnotatedMixinInjectorHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
|
||||
@@ -30,11 +30,10 @@ import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.MethodData;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
|
||||
import net.minecraftforge.srg2source.rangeapplier.MethodData;
|
||||
|
||||
class AnnotatedMixinOverwriteHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
AnnotatedMixinOverwriteHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
@@ -73,8 +72,7 @@ class AnnotatedMixinOverwriteHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
for (ObfuscationType type : obfData) {
|
||||
MethodData obfMethod = obfData.get(type);
|
||||
String obfName = obfMethod.name.substring(obfMethod.name.lastIndexOf('/') + 1);
|
||||
this.addMethodMapping(type, mcpName, obfName, mcpSignature, obfMethod.sig);
|
||||
this.addMethodMapping(type, mcpName, obfMethod.getSimpleName(), mcpSignature, obfMethod.getDesc());
|
||||
}
|
||||
|
||||
if (!"true".equalsIgnoreCase(this.ap.getOption(SupportedOptions.DISABLE_OVERWRITE_CHECKER))) {
|
||||
|
||||
@@ -29,11 +29,10 @@ import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.spongepowered.asm.obfuscation.MethodData;
|
||||
import org.spongepowered.tools.MirrorUtils;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
|
||||
import net.minecraftforge.srg2source.rangeapplier.MethodData;
|
||||
|
||||
class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
AnnotatedMixinShadowHandler(IMixinAnnotationProcessor ap, AnnotatedMixin mixin) {
|
||||
@@ -85,7 +84,7 @@ class AnnotatedMixinShadowHandler extends AnnotatedMixinElementHandler {
|
||||
|
||||
for (ObfuscationType type : obfData) {
|
||||
MethodData obfMethod = obfData.get(type);
|
||||
this.addMethodMapping(type, name.setObfuscatedName(obfMethod.name), mcpSignature, obfMethod.sig);
|
||||
this.addMethodMapping(type, name.setObfuscatedName(obfMethod.getName()), mcpSignature, obfMethod.getDesc());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@ import javax.tools.StandardLocation;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.MethodData;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IObfuscationManager;
|
||||
|
||||
import net.minecraftforge.srg2source.rangeapplier.MethodData;
|
||||
|
||||
public class ObfuscationManager implements IObfuscationManager {
|
||||
|
||||
/**
|
||||
@@ -215,7 +215,11 @@ public class ObfuscationManager implements IObfuscationManager {
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
if (!data.isEmpty() || !Constants.INIT.equals(method.name)) {
|
||||
return data;
|
||||
}
|
||||
|
||||
return this.remapDescriptor(data, method);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -233,6 +237,28 @@ public class ObfuscationManager implements IObfuscationManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.isEmpty() || !Constants.INIT.equals(method.getSimpleName())) {
|
||||
return data;
|
||||
}
|
||||
|
||||
return this.remapDescriptor(data, new MemberInfo(method));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap a method owner and descriptor only, used for remapping ctors
|
||||
*
|
||||
* @param data Output method data collection
|
||||
* @param method Method to remap
|
||||
* @return data
|
||||
*/
|
||||
public ObfuscationData<MethodData> remapDescriptor(ObfuscationData<MethodData> data, MemberInfo method) {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
MemberInfo obfMethod = targetEnv.remapDescriptor(method);
|
||||
if (obfMethod != null) {
|
||||
data.add(targetEnv.getType(), obfMethod.asMethodData());
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -301,10 +327,7 @@ public class ObfuscationManager implements IObfuscationManager {
|
||||
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
|
||||
MethodData obfMethod = obfMethodData.get(targetEnv.getType());
|
||||
if (obfMethod != null) {
|
||||
int slashPos = obfMethod.name.lastIndexOf('/');
|
||||
String obfName = obfMethod.name.substring(slashPos + 1);
|
||||
String obfOwner = obfMethod.name.substring(0, slashPos);
|
||||
MemberInfo remappedReference = new MemberInfo(obfName, obfOwner, obfMethod.sig, false);
|
||||
MemberInfo remappedReference = new MemberInfo(obfMethod);
|
||||
targetEnv.addMapping(className, reference, remappedReference.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,13 +43,41 @@ import javax.tools.StandardLocation;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.MethodData;
|
||||
import org.spongepowered.asm.obfuscation.SrgContainer;
|
||||
import org.spongepowered.asm.util.ObfuscationUtil;
|
||||
import org.spongepowered.asm.util.ObfuscationUtil.IClassRemapper;
|
||||
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
|
||||
|
||||
import net.minecraftforge.srg2source.rangeapplier.MethodData;
|
||||
import net.minecraftforge.srg2source.rangeapplier.SrgContainer;
|
||||
|
||||
class TargetObfuscationEnvironment {
|
||||
|
||||
final class RemapperProxy implements IClassRemapper {
|
||||
|
||||
@Override
|
||||
public String map(String typeName) {
|
||||
if (TargetObfuscationEnvironment.this.srgs == null) {
|
||||
return null;
|
||||
}
|
||||
return TargetObfuscationEnvironment.this.srgs.getClassMapping(typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmap(String typeName) {
|
||||
if (TargetObfuscationEnvironment.this.srgs == null) {
|
||||
return null;
|
||||
}
|
||||
return TargetObfuscationEnvironment.this.srgs.getClassMapping(typeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SRG container for mcp->? mappings
|
||||
*/
|
||||
protected SrgContainer srgs;
|
||||
|
||||
private final RemapperProxy remapper = new RemapperProxy();
|
||||
|
||||
/**
|
||||
* Type
|
||||
*/
|
||||
@@ -75,11 +103,6 @@ class TargetObfuscationEnvironment {
|
||||
*/
|
||||
private final ReferenceMapper refMapper;
|
||||
|
||||
/**
|
||||
* SRG container for mcp->? mappings
|
||||
*/
|
||||
private SrgContainer srgs;
|
||||
|
||||
/**
|
||||
* True once we've tried to initialise the srgs, initially false so that we
|
||||
* can do srg init lazily
|
||||
@@ -175,17 +198,47 @@ class TargetObfuscationEnvironment {
|
||||
*/
|
||||
public MethodData getObfMethod(MethodData method) {
|
||||
if (this.initSrgs()) {
|
||||
return this.srgs.methodMap.get(method);
|
||||
return this.srgs.getMethodMapping(method);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap only the owner and descriptor of the specified method
|
||||
*
|
||||
* @param method method to remap
|
||||
* @return remapped method or null if no remapping occurred
|
||||
*/
|
||||
public MemberInfo remapDescriptor(MemberInfo method) {
|
||||
boolean transformed = false;
|
||||
|
||||
String owner = method.owner;
|
||||
if (owner != null) {
|
||||
String newOwner = this.remapper.map(owner);
|
||||
if (newOwner != null) {
|
||||
owner = newOwner;
|
||||
transformed = true;
|
||||
}
|
||||
}
|
||||
|
||||
String desc = method.desc;
|
||||
if (desc != null) {
|
||||
String newDesc = ObfuscationUtil.mapDescriptor(method.desc, this.remapper);
|
||||
if (!newDesc.equals(method.desc)) {
|
||||
desc = newDesc;
|
||||
transformed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return transformed ? new MemberInfo(method.name, owner, desc, method.matchAll) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an obfuscation mapping for a field
|
||||
*/
|
||||
public String getObfField(String field) {
|
||||
if (this.initSrgs()) {
|
||||
return this.srgs.fieldMap.get(field);
|
||||
return this.srgs.getFieldMapping(field);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -195,7 +248,7 @@ class TargetObfuscationEnvironment {
|
||||
*/
|
||||
public String getObfClass(String className) {
|
||||
if (this.initSrgs()) {
|
||||
return this.srgs.classMap.get(className);
|
||||
return this.srgs.getClassMapping(className);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,10 @@ package org.spongepowered.tools.obfuscation.interfaces;
|
||||
|
||||
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
|
||||
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
|
||||
import org.spongepowered.asm.obfuscation.MethodData;
|
||||
import org.spongepowered.tools.obfuscation.ObfuscationData;
|
||||
import org.spongepowered.tools.obfuscation.TypeHandle;
|
||||
|
||||
import net.minecraftforge.srg2source.rangeapplier.MethodData;
|
||||
|
||||
/**
|
||||
* Manages obfuscation things
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user