Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
package appeng.transformer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.core.AEConfig;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
import cpw.mods.fml.common.DummyModContainer;
|
||||
import cpw.mods.fml.common.LoadController;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
|
||||
|
||||
@MCVersion()
|
||||
public class AppEngCore extends DummyModContainer implements IFMLLoadingPlugin
|
||||
{
|
||||
|
||||
public final AppEngCore instance;
|
||||
|
||||
protected final ModMetadata md = new ModMetadata();
|
||||
|
||||
public AppEngCore() {
|
||||
instance = this;
|
||||
FMLRelaunchLog.info( "[AppEng] Core Init" );
|
||||
md.autogenerated = false;
|
||||
md.authorList.add( "AlgorithmX2" );
|
||||
md.credits = "AlgorithmX2";
|
||||
md.modId = getModId();
|
||||
md.version = getVersion();
|
||||
md.name = getName();
|
||||
md.url = "http://ae2.ae-mod.info";
|
||||
md.description = "Embedded Coremod for Applied Energistics 2";
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void load(FMLInitializationEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerBus(EventBus bus, LoadController controller)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass()
|
||||
{
|
||||
return new String[] { "appeng.transformer.asm.ASMIntegration" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModContainerClass()
|
||||
{
|
||||
return "appeng.transformer.AppEngCore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSetupClass()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModId()
|
||||
{
|
||||
return "appliedenergistics2-core";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "AppliedEnergistics2 Core";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion()
|
||||
{
|
||||
return AEConfig.VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayVersion()
|
||||
{
|
||||
return getVersion();
|
||||
}
|
||||
|
||||
public ModMetadata getMetadata()
|
||||
{
|
||||
return md;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass()
|
||||
{
|
||||
return "appeng.transformer.asm.ASMTweaker";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package appeng.transformer;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
|
||||
|
||||
public class MissingCoreMod extends CustomModLoadingErrorDisplayException
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = -966774766922821652L;
|
||||
private boolean deobf = false;
|
||||
|
||||
@Override
|
||||
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer)
|
||||
{
|
||||
Class clz = errorScreen.getClass();
|
||||
try
|
||||
{
|
||||
clz.getField( "mc" );
|
||||
deobf = true;
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime)
|
||||
{
|
||||
int offset = 10;
|
||||
drawCenteredString( fontRenderer, "Sorry, couldn't load AE2 Properly.", errorScreen.width / 2, offset += 15, 0xffffff );
|
||||
drawCenteredString( fontRenderer, "Please make sure that AE2 is installed into your mods folder.", errorScreen.width / 2, offset += 15, 0xeeeeee );
|
||||
|
||||
offset += 15;
|
||||
|
||||
if ( deobf )
|
||||
{
|
||||
offset += 15;
|
||||
drawCenteredString( fontRenderer, "In a developer environment add the following too your args,", errorScreen.width / 2, offset += 15, 0xffffff );
|
||||
drawCenteredString( fontRenderer, "-Dfml.coreMods.load=appeng.transformer.AppEngCore", errorScreen.width / 2, offset += 15, 0xeeeeee );
|
||||
}
|
||||
else
|
||||
{
|
||||
drawCenteredString( fontRenderer, "You're launcher may refer to this by different names,", errorScreen.width / 2, offset += 15, 0xffffff );
|
||||
|
||||
offset += 5;
|
||||
|
||||
drawCenteredString( fontRenderer, "MultiMC calls this tab \"Loader Mods\"", errorScreen.width / 2, offset += 15, 0xeeeeee );
|
||||
drawCenteredString( fontRenderer, "Magic Launcher calls this tab \"External Mods\"", errorScreen.width / 2, offset += 15, 0xeeeeee );
|
||||
drawCenteredString( fontRenderer, "Most other launchers refer to this tab as just \"Mods\"", errorScreen.width / 2, offset += 15, 0xeeeeee );
|
||||
|
||||
offset += 15;
|
||||
|
||||
drawCenteredString( fontRenderer, "Also make sure that the AE2 file is a .jar, and not a .zip", errorScreen.width / 2, offset += 15, 0xffffff );
|
||||
}
|
||||
}
|
||||
|
||||
public void drawCenteredString(FontRenderer fontRenderer, String string, int x, int y, int colour)
|
||||
{
|
||||
fontRenderer.drawStringWithShadow( string, x - fontRenderer.getStringWidth( string.replaceAll( "\\P{InBasic_Latin}", "" ) ) / 2, y, colour );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package appeng.transformer.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
public @interface integration {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface InterfaceList {
|
||||
|
||||
public Interface[] value();
|
||||
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Interface {
|
||||
|
||||
public String iface();
|
||||
|
||||
public String iname();
|
||||
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface Method {
|
||||
|
||||
public String iname();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package appeng.transformer.asm;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import appeng.integration.IntegrationRegistry;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.transformer.annotations.integration;
|
||||
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
||||
|
||||
public class ASMIntegration implements IClassTransformer
|
||||
{
|
||||
|
||||
private IntegrationRegistry integrationModules = new IntegrationRegistry();
|
||||
|
||||
public ASMIntegration() {
|
||||
|
||||
/**
|
||||
* Side, Display Name, ModID ClassPostFix
|
||||
*/
|
||||
|
||||
for ( IntegrationType type : IntegrationType.values() )
|
||||
{
|
||||
integrationModules.add( type );
|
||||
}
|
||||
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", IntegrationType.TE );
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Mystcraft", "Mystcraft", IntegrationType.Mystcraft );
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Greg Tech", "gregtech_addon", IntegrationType.GT );
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Universal Electricity", null, IntegrationType.UE );
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Logistics Pipes", "LogisticsPipes|Main", IntegrationType.LP );
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Better Storage", IntegrationType.betterstorage );
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Forestry", "Forestry", IntegrationType.Forestry );
|
||||
// integrationModules.add( IntegrationSide.BOTH, "Mekanism", "Mekanism", IntegrationType.Mekanism );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass)
|
||||
{
|
||||
if ( basicClass == null || transformedName.startsWith( "appeng.transformer" ) )
|
||||
return basicClass;
|
||||
|
||||
if ( transformedName.startsWith( "appeng." ) )
|
||||
{
|
||||
// log( "Found " + transformedName );
|
||||
|
||||
ClassNode classNode = new ClassNode();
|
||||
ClassReader classReader = new ClassReader( basicClass );
|
||||
classReader.accept( classNode, 0 );
|
||||
|
||||
try
|
||||
{
|
||||
boolean reWrite = removeOptionals( classNode );
|
||||
|
||||
if ( reWrite )
|
||||
{
|
||||
ClassWriter writer = new ClassWriter( ClassWriter.COMPUTE_MAXS );
|
||||
classNode.accept( writer );
|
||||
return writer.toByteArray();
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
private boolean removeOptionals(ClassNode classNode)
|
||||
{
|
||||
boolean changed = false;
|
||||
|
||||
if ( classNode.visibleAnnotations != null )
|
||||
{
|
||||
for (AnnotationNode an : classNode.visibleAnnotations)
|
||||
{
|
||||
if ( hasAnnotation( an, integration.Interface.class ) )
|
||||
{
|
||||
if ( stripInterface( classNode, integration.Interface.class, an ) )
|
||||
changed = true;
|
||||
}
|
||||
else if ( hasAnnotation( an, integration.InterfaceList.class ) )
|
||||
{
|
||||
for (Object o : ((List) an.values.get( 1 )))
|
||||
{
|
||||
if ( stripInterface( classNode, integration.InterfaceList.class, (AnnotationNode) o ) )
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<MethodNode> i = classNode.methods.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
MethodNode mn = i.next();
|
||||
|
||||
if ( mn.visibleAnnotations != null )
|
||||
{
|
||||
for (AnnotationNode an : mn.visibleAnnotations)
|
||||
{
|
||||
if ( hasAnnotation( an, integration.Method.class ) )
|
||||
{
|
||||
if ( stripMethod( classNode, mn, i, integration.Method.class, an ) )
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( changed )
|
||||
log( "Updated " + classNode.name );
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private boolean hasAnnotation(AnnotationNode ann, Class anno)
|
||||
{
|
||||
return ann.desc.equals( Type.getDescriptor( anno ) );
|
||||
}
|
||||
|
||||
private boolean stripMethod(ClassNode classNode, MethodNode mn, Iterator<MethodNode> i, Class class1, AnnotationNode an)
|
||||
{
|
||||
if ( an.values.size() != 2 )
|
||||
throw new RuntimeException( "Unable to handle Method annotation on " + classNode.name );
|
||||
|
||||
String iName = null;
|
||||
|
||||
if ( an.values.get( 0 ).equals( "iname" ) )
|
||||
iName = (String) an.values.get( 1 );
|
||||
|
||||
if ( iName != null )
|
||||
{
|
||||
IntegrationType type = IntegrationType.valueOf( iName );
|
||||
if ( !IntegrationRegistry.instance.isEnabled( type ) )
|
||||
{
|
||||
log( "Removing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is disabled." );
|
||||
i.remove();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
log( "Allowing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is enabled." );
|
||||
}
|
||||
else
|
||||
throw new RuntimeException( "Unable to handle Method annotation on " + classNode.name );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean stripInterface(ClassNode classNode, Class class1, AnnotationNode an)
|
||||
{
|
||||
if ( an.values.size() != 4 )
|
||||
throw new RuntimeException( "Unable to handle Interface annotation on " + classNode.name );
|
||||
|
||||
String iFace = null;
|
||||
String iName = null;
|
||||
|
||||
if ( an.values.get( 0 ).equals( "iface" ) )
|
||||
iFace = (String) an.values.get( 1 );
|
||||
else if ( an.values.get( 2 ).equals( "iface" ) )
|
||||
iFace = (String) an.values.get( 3 );
|
||||
|
||||
if ( an.values.get( 0 ).equals( "iname" ) )
|
||||
iName = (String) an.values.get( 1 );
|
||||
else if ( an.values.get( 2 ).equals( "iname" ) )
|
||||
iName = (String) an.values.get( 3 );
|
||||
|
||||
IntegrationType type = IntegrationType.valueOf( iName );
|
||||
|
||||
if ( iName != null && iFace != null )
|
||||
{
|
||||
if ( !IntegrationRegistry.instance.isEnabled( type ) )
|
||||
{
|
||||
log( "Removing Interface " + iFace + " from " + classNode.name + " because " + iName + " integration is disabled." );
|
||||
classNode.interfaces.remove( iFace.replace( '.', '/' ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
log( "Allowing Interface " + iFace + " from " + classNode.name + " because " + iName + " integration is enabled." );
|
||||
}
|
||||
else
|
||||
throw new RuntimeException( "Unable to handle Method annotation on " + classNode.name );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void log(String string)
|
||||
{
|
||||
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package appeng.transformer.asm;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
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.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLRelaunchLog;
|
||||
|
||||
public class ASMTweaker implements IClassTransformer
|
||||
{
|
||||
|
||||
class publicLine
|
||||
{
|
||||
|
||||
public publicLine(String name, String desc) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
final String name, desc;
|
||||
|
||||
};
|
||||
|
||||
Multimap<String, publicLine> privateToPublicMethods = HashMultimap.create();
|
||||
|
||||
public ASMTweaker() {
|
||||
privateToPublicMethods.put( "net.minecraft.client.gui.inventory.GuiContainer", new publicLine( "func_146977_a", "(Lnet/minecraft/inventory/Slot;)V" ) );
|
||||
privateToPublicMethods.put( "net.minecraft.client.gui.inventory.GuiContainer", new publicLine( "a", "(Lzk;)V" ) );
|
||||
|
||||
privateToPublicMethods.put( "appeng.tile.AEBaseTile", new publicLine( "writeToNBT", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
|
||||
privateToPublicMethods.put( "appeng.tile.AEBaseTile", new publicLine( "func_77955_b", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
|
||||
privateToPublicMethods.put( "appeng.tile.AEBaseTile", new publicLine( "b", "(Ldh;)V" ) );
|
||||
|
||||
privateToPublicMethods.put( "appeng.tile.AEBaseTile", new publicLine( "readFromNBT", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
|
||||
privateToPublicMethods.put( "appeng.tile.AEBaseTile", new publicLine( "func_145839_a", "(Lnet/minecraft/nbt/NBTTagCompound;)V" ) );
|
||||
privateToPublicMethods.put( "appeng.tile.AEBaseTile", new publicLine( "a", "(Ldh;)V" ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass)
|
||||
{
|
||||
if ( basicClass == null )
|
||||
return basicClass;
|
||||
|
||||
try
|
||||
{
|
||||
if ( transformedName != null && privateToPublicMethods.containsKey( transformedName ) )
|
||||
{
|
||||
ClassNode classNode = new ClassNode();
|
||||
ClassReader classReader = new ClassReader( basicClass );
|
||||
classReader.accept( classNode, 0 );
|
||||
|
||||
for (publicLine Set : privateToPublicMethods.get( transformedName ))
|
||||
{
|
||||
makePublic( classNode, Set );
|
||||
}
|
||||
|
||||
// CALL VIRUAL!
|
||||
if ( transformedName.equals( "net.minecraft.client.gui.inventory.GuiContainer" ) )
|
||||
{
|
||||
for (MethodNode mn : classNode.methods)
|
||||
{
|
||||
if ( mn.name.equals( "func_146977_a" ) || (mn.name.equals( "a" ) && mn.desc.equals( "(Lzk;)V" )) )
|
||||
{
|
||||
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)
|
||||
{
|
||||
if ( mn.name.equals( "func_73863_a" ) || mn.name.equals( "drawScreen" ) || (mn.name.equals( "a" ) && mn.desc.equals( "(IIF)V" )) )
|
||||
{
|
||||
Iterator<AbstractInsnNode> i = mn.instructions.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
AbstractInsnNode in = i.next();
|
||||
if ( in.getOpcode() == Opcodes.INVOKESPECIAL )
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClassWriter writer = new ClassWriter( ClassWriter.COMPUTE_MAXS );
|
||||
classNode.accept( writer );
|
||||
return writer.toByteArray();
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
}
|
||||
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
private void log(String string)
|
||||
{
|
||||
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
|
||||
}
|
||||
|
||||
private void makePublic(ClassNode classNode, publicLine set)
|
||||
{
|
||||
for (MethodNode mn : classNode.methods)
|
||||
{
|
||||
if ( mn.name.equals( set.name ) && mn.desc.equals( set.desc ) )
|
||||
{
|
||||
mn.access = (mn.access & (~(Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED))) | Opcodes.ACC_PUBLIC;
|
||||
log( mn.name + mn.desc + " - Transformed" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user