Store member field mappings in the mapping table, possible fix for #3043

This commit is contained in:
Mumfrey 2016-06-29 15:33:27 +01:00
parent 6ad65f4e64
commit 32459b01b6
2 changed files with 55 additions and 2 deletions

View file

@ -259,14 +259,42 @@ public class FMLDeobfuscatingRemapper extends Remapper {
rawMethodMaps.get(cl).put(oldName+sig, newName);
}
String mapMemberFieldName(String owner, String name, String desc)
{
String remappedName = mapFieldName(owner, name, desc, true);
storeMemberFieldMapping(owner, name, desc, remappedName);
return remappedName;
}
private void storeMemberFieldMapping(String owner, String name, String desc, String remappedName) {
Map<String, String> fieldMap = getRawFieldMap(owner);
String key = name + ":" + desc;
String altKey = name + ":null";
if (!fieldMap.containsKey(key)) {
fieldMap.put(key, remappedName);
fieldMap.put(altKey, remappedName);
// Alternatively, maps could be made mutable and we could just set the relevant entry, saving
// the need to regenerate the super map each time
fieldNameMaps.remove(owner);
}
}
@Override
public String mapFieldName(String owner, String name, String desc)
{
return mapFieldName(owner, name, desc, false);
}
String mapFieldName(String owner, String name, String desc, boolean raw)
{
if (classNameBiMap == null || classNameBiMap.isEmpty())
{
return name;
}
Map<String, String> fieldMap = getFieldMap(owner);
Map<String, String> fieldMap = getFieldMap(owner, raw);
return fieldMap!=null && fieldMap.containsKey(name+":"+desc) ? fieldMap.get(name+":"+desc) : fieldMap!=null && fieldMap.containsKey(name+":null") ? fieldMap.get(name+":null") :name;
}
@ -332,8 +360,22 @@ public class FMLDeobfuscatingRemapper extends Remapper {
return super.mapSignature(signature, typeSignature);
}
private Map<String,String> getFieldMap(String className)
private Map<String,String> getRawFieldMap(String className)
{
if (!rawFieldMaps.containsKey(className))
{
rawFieldMaps.put(className, Maps.<String,String>newHashMap());
}
return rawFieldMaps.get(className);
}
private Map<String,String> getFieldMap(String className, boolean raw)
{
if (raw)
{
return getRawFieldMap(className);
}
if (!fieldNameMaps.containsKey(className) && !negativeCacheFields.contains(className))
{
findAndMergeSuperMaps(className);

View file

@ -20,6 +20,7 @@
package net.minecraftforge.fml.common.asm.transformers.deobf;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.Remapper;
@ -43,6 +44,16 @@ public class FMLRemappingAdapter extends RemappingClassAdapter {
super.visit(version, access, name, signature, superName, interfaces);
}
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
FMLDeobfuscatingRemapper remapper = FMLDeobfuscatingRemapper.INSTANCE;
FieldVisitor fv = cv.visitField(access,
remapper.mapMemberFieldName(className, name, desc),
remapper.mapDesc(desc), remapper.mapSignature(signature, true),
remapper.mapValue(value));
return createRemappingFieldAdapter(fv);
}
@Override
protected MethodVisitor createRemappingMethodAdapter(int access, String newDesc, MethodVisitor mv)
{