From 237c28b6cb4230eee49769f4cca4ab9645248988 Mon Sep 17 00:00:00 2001 From: cpw Date: Tue, 24 Jun 2014 15:37:39 -0400 Subject: [PATCH] Force the descriptors to the right type for the field they're referencing. Fixes the sand issue --- .../deobf/FMLDeobfuscatingRemapper.java | 17 ++++++++ .../deobf/FMLRemappingAdapter.java | 41 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java b/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java index a144accb2..3fb6a1485 100644 --- a/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java +++ b/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLDeobfuscatingRemapper.java @@ -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 newClassMap = fieldDescriptions.get(newType); + if (newClassMap == null) + { + newClassMap = Maps.newHashMap(); + fieldDescriptions.put(newType, newClassMap); + } + newClassMap.put(newName, fType); + return fType; + } } diff --git a/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLRemappingAdapter.java b/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLRemappingAdapter.java index 7918f7743..f312560e0 100644 --- a/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLRemappingAdapter.java +++ b/fml/src/main/java/cpw/mods/fml/common/asm/transformers/deobf/FMLRemappingAdapter.java @@ -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); + } + } + } }