Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
@@ -18,9 +18,8 @@
package appeng.transformer;
import java.util.Map;
import com.google.common.eventbus.EventBus;
import java.util.Map;
import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
@@ -31,9 +30,12 @@ import cpw.mods.fml.relauncher.FMLRelaunchLog;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
import com.google.common.eventbus.EventBus;
import appeng.core.AEConfig;
@MCVersion("1.7.10")
@MCVersion( "1.7.10" )
public class AppEngCore extends DummyModContainer implements IFMLLoadingPlugin
{
@@ -41,7 +43,8 @@ public class AppEngCore extends DummyModContainer implements IFMLLoadingPlugin
protected final ModMetadata md = new ModMetadata();
public AppEngCore() {
public AppEngCore()
{
this.instance = this;
FMLRelaunchLog.info( "[AppEng] Core Init" );
this.md.autogenerated = false;
@@ -55,16 +58,10 @@ public class AppEngCore extends DummyModContainer implements IFMLLoadingPlugin
}
@EventHandler
public void load(FMLInitializationEvent event)
public void load( FMLInitializationEvent event )
{
}
@Override
public boolean registerBus(EventBus bus, LoadController controller)
{
return true;
}
@Override
public String[] getASMTransformerClass()
{
@@ -84,11 +81,23 @@ public class AppEngCore extends DummyModContainer implements IFMLLoadingPlugin
}
@Override
public void injectData(Map<String, Object> data)
public void injectData( Map<String, Object> data )
{
}
@Override
public String getAccessTransformerClass()
{
return "appeng.transformer.asm.ASMTweaker";
}
@Override
public ModMetadata getMetadata()
{
return this.md;
}
@Override
public String getModId()
{
@@ -107,21 +116,15 @@ public class AppEngCore extends DummyModContainer implements IFMLLoadingPlugin
return AEConfig.VERSION;
}
@Override
public boolean registerBus( EventBus bus, LoadController controller )
{
return true;
}
@Override
public String getDisplayVersion()
{
return this.getVersion();
}
@Override
public ModMetadata getMetadata()
{
return this.md;
}
@Override
public String getAccessTransformerClass()
{
return "appeng.transformer.asm.ASMTweaker";
}
}
@@ -18,11 +18,13 @@
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
{
@@ -30,7 +32,7 @@ public class MissingCoreMod extends CustomModLoadingErrorDisplayException
private boolean deobf = false;
@Override
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer)
public void initGui( GuiErrorScreen errorScreen, FontRenderer fontRenderer )
{
Class clz = errorScreen.getClass();
try
@@ -38,14 +40,14 @@ public class MissingCoreMod extends CustomModLoadingErrorDisplayException
clz.getField( "mc" );
this.deobf = true;
}
catch (Throwable ignored)
catch( Throwable ignored )
{
}
}
@Override
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime)
public void drawScreen( GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime )
{
int offset = 10;
this.drawCenteredString( fontRenderer, "Sorry, couldn't load AE2 Properly.", errorScreen.width / 2, offset += 15, 0xffffff );
@@ -53,7 +55,7 @@ public class MissingCoreMod extends CustomModLoadingErrorDisplayException
offset += 15;
if ( this.deobf )
if( this.deobf )
{
offset += 15;
this.drawCenteredString( fontRenderer, "In a developer environment add the following too your args,", errorScreen.width / 2, offset += 15, 0xffffff );
@@ -75,7 +77,7 @@ public class MissingCoreMod extends CustomModLoadingErrorDisplayException
}
}
public void drawCenteredString(FontRenderer fontRenderer, String string, int x, int y, int colour)
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 );
}
@@ -48,7 +48,7 @@ public class ASMIntegration implements IClassTransformer
* Side, Display Name, ModID ClassPostFix
*/
for ( IntegrationType type : IntegrationType.values() )
for( IntegrationType type : IntegrationType.values() )
{
IntegrationRegistry.INSTANCE.add( type );
}
@@ -67,10 +67,10 @@ public class ASMIntegration implements IClassTransformer
@Override
public byte[] transform( String name, String transformedName, byte[] basicClass )
{
if ( basicClass == null || transformedName.startsWith( "appeng.transformer" ) )
if( basicClass == null || transformedName.startsWith( "appeng.transformer" ) )
return basicClass;
if ( transformedName.startsWith( "appeng." ) )
if( transformedName.startsWith( "appeng." ) )
{
// log( "Found " + transformedName );
@@ -82,14 +82,14 @@ public class ASMIntegration implements IClassTransformer
{
boolean reWrite = this.removeOptionals( classNode );
if ( reWrite )
if( reWrite )
{
ClassWriter writer = new ClassWriter( ClassWriter.COMPUTE_MAXS );
classNode.accept( writer );
return writer.toByteArray();
}
}
catch ( Throwable t )
catch( Throwable t )
{
t.printStackTrace();
}
@@ -101,20 +101,20 @@ public class ASMIntegration implements IClassTransformer
{
boolean changed = false;
if ( classNode.visibleAnnotations != null )
if( classNode.visibleAnnotations != null )
{
for ( AnnotationNode an : classNode.visibleAnnotations )
for( AnnotationNode an : classNode.visibleAnnotations )
{
if ( this.hasAnnotation( an, Integration.Interface.class ) )
if( this.hasAnnotation( an, Integration.Interface.class ) )
{
if ( this.stripInterface( classNode, Integration.Interface.class, an ) )
if( this.stripInterface( classNode, Integration.Interface.class, an ) )
changed = true;
}
else if ( this.hasAnnotation( an, Integration.InterfaceList.class ) )
else if( this.hasAnnotation( an, Integration.InterfaceList.class ) )
{
for ( Object o : ( ( List ) an.values.get( 1 ) ) )
for( Object o : ( (List) an.values.get( 1 ) ) )
{
if ( this.stripInterface( classNode, Integration.InterfaceList.class, ( AnnotationNode ) o ) )
if( this.stripInterface( classNode, Integration.InterfaceList.class, (AnnotationNode) o ) )
changed = true;
}
}
@@ -122,25 +122,24 @@ public class ASMIntegration implements IClassTransformer
}
Iterator<MethodNode> i = classNode.methods.iterator();
while ( i.hasNext() )
while( i.hasNext() )
{
MethodNode mn = i.next();
if ( mn.visibleAnnotations != null )
if( mn.visibleAnnotations != null )
{
for ( AnnotationNode an : mn.visibleAnnotations )
for( AnnotationNode an : mn.visibleAnnotations )
{
if ( this.hasAnnotation( an, Integration.Method.class ) )
if( this.hasAnnotation( an, Integration.Method.class ) )
{
if ( this.stripMethod( classNode, mn, i, Integration.Method.class, an ) )
if( this.stripMethod( classNode, mn, i, Integration.Method.class, an ) )
changed = true;
}
}
}
}
if ( changed )
if( changed )
this.log( "Updated " + classNode.name );
return changed;
@@ -151,57 +150,29 @@ public class ASMIntegration implements IClassTransformer
return ann.desc.equals( Type.getDescriptor( annotation ) );
}
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 ) )
{
this.log( "Removing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is disabled." );
i.remove();
return true;
}
else
this.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 )
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( "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 );
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( iName != null && iFace != null )
{
if ( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
if( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
{
this.log( "Removing Interface " + iFace + " from " + classNode.name + " because " + iName + " integration is disabled." );
classNode.interfaces.remove( iFace.replace( '.', '/' ) );
@@ -216,9 +187,36 @@ public class ASMIntegration implements IClassTransformer
return false;
}
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 ) )
{
this.log( "Removing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is disabled." );
i.remove();
return true;
}
else
this.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 void log( String string )
{
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
}
}
@@ -18,6 +18,7 @@
package appeng.transformer.asm;
import java.util.Iterator;
import org.apache.logging.log4j.Level;
@@ -38,25 +39,14 @@ import cpw.mods.fml.relauncher.FMLRelaunchLog;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
public class ASMTweaker implements IClassTransformer
{
class publicLine
{
public publicLine(String name, String desc) {
this.name = name;
this.desc = desc;
}
final String name;
final String desc;
}
final Multimap<String, publicLine> privateToPublicMethods = HashMultimap.create();
public ASMTweaker() {
public ASMTweaker()
{
this.privateToPublicMethods.put( "net.minecraft.client.gui.inventory.GuiContainer", new publicLine( "func_146977_a", "(Lnet/minecraft/inventory/Slot;)V" ) );
this.privateToPublicMethods.put( "net.minecraft.client.gui.inventory.GuiContainer", new publicLine( "a", "(Lzk;)V" ) );
@@ -70,30 +60,30 @@ public class ASMTweaker implements IClassTransformer
}
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass)
public byte[] transform( String name, String transformedName, byte[] basicClass )
{
if ( basicClass == null )
if( basicClass == null )
return null;
try
{
if ( transformedName != null && this.privateToPublicMethods.containsKey( transformedName ) )
if( transformedName != null && this.privateToPublicMethods.containsKey( transformedName ) )
{
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader( basicClass );
classReader.accept( classNode, 0 );
for (publicLine Set : this.privateToPublicMethods.get( transformedName ))
for( publicLine Set : this.privateToPublicMethods.get( transformedName ) )
{
this.makePublic( classNode, Set );
}
// CALL VIRTUAL!
if ( transformedName.equals( "net.minecraft.client.gui.inventory.GuiContainer" ) )
if( transformedName.equals( "net.minecraft.client.gui.inventory.GuiContainer" ) )
{
for (MethodNode mn : classNode.methods)
for( MethodNode mn : classNode.methods )
{
if ( mn.name.equals( "func_146977_a" ) || (mn.name.equals( "a" ) && mn.desc.equals( "(Lzk;)V" )) )
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 ) );
@@ -106,18 +96,18 @@ public class ASMTweaker implements IClassTransformer
}
}
for (MethodNode mn : classNode.methods)
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" )) )
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())
while( i.hasNext() )
{
AbstractInsnNode in = i.next();
if ( in.getOpcode() == Opcodes.INVOKESPECIAL )
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" )) )
if( n.name.equals( "func_146977_a" ) || ( n.name.equals( "a" ) && n.desc.equals( "(Lzk;)V" ) ) )
{
this.log( n.name + n.desc + " - Invoke Virtual" );
mn.instructions.insertBefore( n, new MethodInsnNode( Opcodes.INVOKEVIRTUAL, n.owner, n.name, n.desc, false ) );
@@ -135,27 +125,40 @@ public class ASMTweaker implements IClassTransformer
return writer.toByteArray();
}
}
catch (Throwable ignored)
catch( Throwable ignored )
{
}
return basicClass;
}
private void log(String string)
private void makePublic( ClassNode classNode, publicLine set )
{
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
}
private void makePublic(ClassNode classNode, publicLine set)
{
for (MethodNode mn : classNode.methods)
for( MethodNode mn : classNode.methods )
{
if ( mn.name.equals( set.name ) && mn.desc.equals( set.desc ) )
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;
mn.access = ( mn.access & ( ~( Opcodes.ACC_FINAL | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED ) ) ) | Opcodes.ACC_PUBLIC;
this.log( mn.name + mn.desc + " - Transformed" );
}
}
}
private void log( String string )
{
FMLRelaunchLog.log( "AE2-CORE", Level.INFO, string );
}
class publicLine
{
final String name;
final String desc;
public publicLine( String name, String desc )
{
this.name = name;
this.desc = desc;
}
}
}