2014-02-11 09:39:15 +01:00
|
|
|
package appeng.transformer;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import net.minecraft.launchwrapper.IClassTransformer;
|
|
|
|
|
2014-02-11 17:41:05 +01:00
|
|
|
import org.apache.logging.log4j.Level;
|
2014-02-11 09:39:15 +01:00
|
|
|
import org.objectweb.asm.ClassReader;
|
|
|
|
import org.objectweb.asm.ClassWriter;
|
|
|
|
import org.objectweb.asm.Opcodes;
|
|
|
|
import org.objectweb.asm.tree.AbstractInsnNode;
|
|
|
|
import org.objectweb.asm.tree.ClassNode;
|
|
|
|
import org.objectweb.asm.tree.FieldNode;
|
|
|
|
import org.objectweb.asm.tree.InsnNode;
|
|
|
|
import org.objectweb.asm.tree.MethodInsnNode;
|
|
|
|
import org.objectweb.asm.tree.MethodNode;
|
|
|
|
import org.objectweb.asm.tree.VarInsnNode;
|
|
|
|
|
2014-02-11 17:41:05 +01:00
|
|
|
import appeng.core.AELog;
|
|
|
|
|
2014-02-11 09:39:15 +01:00
|
|
|
import com.google.common.collect.HashMultimap;
|
|
|
|
import com.google.common.collect.Multimap;
|
|
|
|
|
2014-02-11 17:41:05 +01:00
|
|
|
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
|
|
|
|
2014-02-11 09:39:15 +01:00
|
|
|
public class AppEngASMTransformer implements IClassTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
Multimap<String, String> publicShit = HashMultimap.create();
|
|
|
|
|
|
|
|
public AppEngASMTransformer() {
|
|
|
|
publicShit.put( "net.minecraft.client.gui.inventory.GuiContainer", "func_146977_a" );
|
2014-02-11 10:26:18 +01:00
|
|
|
publicShit.put( "net.minecraft.client.gui.inventory.GuiContainer", "a" );
|
2014-02-11 09:39:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public byte[] transform(String name, String transformedName, byte[] basicClass)
|
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
try
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
if ( transformedName != null && publicShit.containsKey( transformedName ) )
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
ClassNode classNode = new ClassNode();
|
|
|
|
ClassReader classReader = new ClassReader( basicClass );
|
|
|
|
classReader.accept( classNode, 0 );
|
|
|
|
|
|
|
|
for (String Set : publicShit.get( transformedName ))
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
makePublic( classNode, Set );
|
2014-02-11 09:39:15 +01:00
|
|
|
}
|
2014-02-11 17:41:05 +01:00
|
|
|
|
|
|
|
// CALL VIRUAL!
|
|
|
|
if ( transformedName.equals( "net.minecraft.client.gui.inventory.GuiContainer" ) )
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
for (MethodNode mn : classNode.methods)
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
if ( mn.name.equals( "func_146977_a" ) || (mn.name.equals( "a" ) && mn.desc.equals( "(Lzk;)V" )) )
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
MethodNode newNode = new MethodNode( Opcodes.ACC_PUBLIC, "func_146977_a_original", mn.desc, mn.signature, new String[0] );
|
|
|
|
newNode.instructions.add( new VarInsnNode( Opcodes.ALOAD, 0 ) );
|
|
|
|
newNode.instructions.add( new VarInsnNode( Opcodes.ALOAD, 1 ) );
|
|
|
|
newNode.instructions.add( new MethodInsnNode( Opcodes.INVOKESPECIAL, classNode.name, mn.name, mn.desc ) );
|
|
|
|
newNode.instructions.add( new InsnNode( Opcodes.RETURN ) );
|
|
|
|
log(newNode.name+newNode.desc+" - New Method");
|
|
|
|
classNode.methods.add( newNode );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MethodNode mn : classNode.methods)
|
|
|
|
{
|
2014-02-11 17:59:31 +01:00
|
|
|
if ( mn.name.equals("func_73863_a") || mn.name.equals( "drawScreen" ) || (mn.name.equals( "a" ) && mn.desc.equals( "(IIF)V" )) )
|
2014-02-11 17:41:05 +01:00
|
|
|
{
|
|
|
|
Iterator<AbstractInsnNode> i = mn.instructions.iterator();
|
|
|
|
while (i.hasNext())
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
AbstractInsnNode in = i.next();
|
2014-02-11 18:08:57 +01:00
|
|
|
if ( in.getOpcode() == Opcodes.INVOKESPECIAL )
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
MethodInsnNode n = (MethodInsnNode) in;
|
|
|
|
if ( n.name.equals( "func_146977_a" ) || (n.name.equals( "a" ) && n.desc.equals( "(Lzk;)V" )) )
|
|
|
|
{
|
|
|
|
log(n.name+n.desc+" - Invoke Virtual");
|
|
|
|
mn.instructions.insertBefore( n, new MethodInsnNode( Opcodes.INVOKEVIRTUAL, n.owner, n.name, n.desc ) );
|
|
|
|
mn.instructions.remove( in );
|
|
|
|
break;
|
|
|
|
}
|
2014-02-11 09:39:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 17:41:05 +01:00
|
|
|
|
|
|
|
ClassWriter writer = new ClassWriter( ClassWriter.COMPUTE_MAXS );
|
|
|
|
classNode.accept( writer );
|
|
|
|
return writer.toByteArray();
|
2014-02-11 09:39:15 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-11 17:41:05 +01:00
|
|
|
catch( Throwable t ) {}
|
|
|
|
|
2014-02-11 09:39:15 +01:00
|
|
|
return basicClass;
|
|
|
|
}
|
|
|
|
|
2014-02-11 17:41:05 +01:00
|
|
|
private void log(String string)
|
2014-02-11 09:39:15 +01:00
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
FMLRelaunchLog.log("AE2-CORE", Level.INFO, string );
|
|
|
|
}
|
2014-02-11 09:39:15 +01:00
|
|
|
|
2014-02-11 17:41:05 +01:00
|
|
|
private void makePublic(ClassNode classNode, String set)
|
|
|
|
{
|
2014-02-11 09:39:15 +01:00
|
|
|
for (MethodNode mn : classNode.methods)
|
|
|
|
{
|
|
|
|
if ( mn.name.equals( set ) )
|
|
|
|
{
|
2014-02-11 17:41:05 +01:00
|
|
|
mn.access = Opcodes.ACC_PUBLIC;
|
|
|
|
log(mn.name+mn.desc+" - Public");
|
2014-02-11 09:39:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|