Force the descriptors to the right type for the field they're referencing. Fixes

the sand issue
This commit is contained in:
cpw 2014-06-24 15:37:39 -04:00
parent 6aae913919
commit 237c28b6cb
2 changed files with 58 additions and 0 deletions

View file

@ -405,4 +405,21 @@ public class FMLDeobfuscatingRemapper extends Remapper {
{
return ImmutableSet.copyOf(classNameBiMap.keySet());
}
public String getStaticFieldType(String oldType, String oldName, String newType, String newName)
{
String fType = getFieldType(oldType, oldName);
if (oldType.equals(newType))
{
return fType;
}
Map<String,String> newClassMap = fieldDescriptions.get(newType);
if (newClassMap == null)
{
newClassMap = Maps.newHashMap();
fieldDescriptions.put(newType, newClassMap);
}
newClassMap.put(newName, fType);
return fType;
}
}

View file

@ -13,7 +13,11 @@
package cpw.mods.fml.common.asm.transformers.deobf;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.Remapper;
import org.objectweb.asm.commons.RemappingClassAdapter;
import org.objectweb.asm.commons.RemappingMethodAdapter;
public class FMLRemappingAdapter extends RemappingClassAdapter {
public FMLRemappingAdapter(ClassVisitor cv)
@ -31,4 +35,41 @@ public class FMLRemappingAdapter extends RemappingClassAdapter {
FMLDeobfuscatingRemapper.INSTANCE.mergeSuperMaps(name, superName, interfaces);
super.visit(version, access, name, signature, superName, interfaces);
}
@Override
protected MethodVisitor createRemappingMethodAdapter(int access, String newDesc, MethodVisitor mv)
{
return new StaticFixingMethodVisitor(access, newDesc, mv, remapper);
}
private static class StaticFixingMethodVisitor extends RemappingMethodAdapter
{
public StaticFixingMethodVisitor(int access, String desc, MethodVisitor mv, Remapper remapper)
{
super(access, desc, mv, remapper);
}
@Override
public void visitFieldInsn(int opcode, String originalType, String originalName, String desc)
{
// This method solves the problem of a static field reference changing type. In all probability it is a
// compatible change, however we need to fix up the desc to point at the new type
String type = remapper.mapType(originalType);
String fieldName = remapper.mapFieldName(originalType, originalName, desc);
String newDesc = remapper.mapDesc(desc);
if (opcode == Opcodes.GETSTATIC && type.startsWith("net/minecraft/") && newDesc.startsWith("Lnet/minecraft/"))
{
String replDesc = FMLDeobfuscatingRemapper.INSTANCE.getStaticFieldType(originalType, originalName, type, fieldName);
if (replDesc != null)
{
newDesc = remapper.mapDesc(replDesc);
}
}
// super.super
if (mv != null) {
mv.visitFieldInsn(opcode, type, fieldName, newDesc);
}
}
}
}