From 81975d9063faa41adf2252aca672e184dfeca18c Mon Sep 17 00:00:00 2001 From: LemADEC Date: Sat, 29 Aug 2015 20:47:21 +0200 Subject: [PATCH] Replaced stdout with a proper logger --- .../cr0s/warpdrive/core/ClassTransformer.java | 86 +++++++++---------- .../cr0s/warpdrive/core/FMLLoadingPlugin.java | 10 ++- .../warpdrive/world/SpaceWorldGenerator.java | 2 +- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/core/ClassTransformer.java b/src/main/java/cr0s/warpdrive/core/ClassTransformer.java index 0ba04238..ac2e07a9 100644 --- a/src/main/java/cr0s/warpdrive/core/ClassTransformer.java +++ b/src/main/java/cr0s/warpdrive/core/ClassTransformer.java @@ -48,26 +48,24 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans @Override public byte[] transform(String name, String transformedName, byte[] bytes) { if (nodemap == null) { - System.out.println("Nodemap is null, transformation cancelled"); + FMLLoadingPlugin.logger.info("Nodemap is null, transformation cancelled"); return bytes; } - String className = name.replace('/', '.'); - - // if (debugLog) { System.out.println("Checking " + name); } - if (className.equals(nodemap.get("EntityLivingBase.class")) || className.equals("net.minecraft.entity.EntityLivingBase")) { + // if (debugLog) { FMLLoadingPlugin.logger.info("Checking " + name); } + if (transformedName.equals("net.minecraft.entity.EntityLivingBase")) { bytes = transformMinecraftEntityLivingBase(bytes); - } else if (className.equals(nodemap.get("EntityItem.class")) || className.equals("net.minecraft.entity.item.EntityItem")) { + } else if (transformedName.equals("net.minecraft.entity.item.EntityItem")) { bytes = transformMinecraftEntityItem(bytes); - } else if (className.equals("com.creativemd.itemphysic.physics.ServerPhysic")) { + } else if (transformedName.equals("com.creativemd.itemphysic.physics.ServerPhysic")) { bytes = transformItemPhysicEntityItem(bytes); - } else if (className.equals(nodemap.get("WorldClient.class")) || className.equals("net.minecraft.client.multiplayer.WorldClient")) { + } else if (transformedName.equals("net.minecraft.client.multiplayer.WorldClient")) { bytes = transformMinecraftWorldClient(bytes); - } else if (className.equals(nodemap.get("Chunk.class")) || className.equals("net.minecraft.world.chunk.Chunk")) { + } else if (transformedName.equals("net.minecraft.world.chunk.Chunk")) { bytes = transformMinecraftChunk(bytes); } @@ -88,11 +86,11 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } MethodNode methodnode = (MethodNode) methods.next(); - // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + // if (debugLog) { FMLLoadingPlugin.logger.info("- Method " + methodnode.name + " " + methodnode.desc); } if ( (methodnode.name.equals(nodemap.get("moveEntityWithHeading.name")) || methodnode.name.equals("moveEntityWithHeading")) && methodnode.desc.equals(nodemap.get("moveEntityWithHeading.desc")) ) { - if (debugLog) { System.out.println("Method found!"); } + if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } int instructionIndex = 0; @@ -112,7 +110,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectedCount++; } } @@ -123,12 +121,12 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } while (true); if (injectedCount != operationCount) { - System.out.println("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); + FMLLoadingPlugin.logger.info("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); } else { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); bytes = writer.toByteArray(); - System.out.println("Injection successfull!"); + FMLLoadingPlugin.logger.info("Successful injection in " + classNode.name); } return bytes; } @@ -147,11 +145,11 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } MethodNode methodnode = (MethodNode) methods.next(); - // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + // if (debugLog) { FMLLoadingPlugin.logger.info("- Method " + methodnode.name + " " + methodnode.desc); } if ( (methodnode.name.equals(nodemap.get("onUpdate.name")) || methodnode.name.equals("onUpdate")) && methodnode.desc.equals(nodemap.get("onUpdate.desc")) ) { - if (debugLog) { System.out.println("Method found!"); } + if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } int instructionIndex = 0; @@ -171,7 +169,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectedCount++; } @@ -185,7 +183,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectedCount++; } } @@ -196,12 +194,12 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } while (true); if (injectedCount != operationCount) { - System.out.println("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); + FMLLoadingPlugin.logger.info("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); } else { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); bytes = writer.toByteArray(); - System.out.println("Injection successfull!"); + FMLLoadingPlugin.logger.info("Successful injection in " + classNode.name); } return bytes; } @@ -220,11 +218,11 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } MethodNode methodnode = (MethodNode) methods.next(); - // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + // if (debugLog) { FMLLoadingPlugin.logger.info("- Method " + methodnode.name + " " + methodnode.desc); } if ( (methodnode.name.equals("update")) && methodnode.desc.equals("(Lnet/minecraft/entity/item/EntityItem;)V") ) { - if (debugLog) { System.out.println("Method found!"); } + if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } int instructionIndex = 0; @@ -244,7 +242,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectedCount++; } @@ -258,7 +256,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectedCount++; } } @@ -269,12 +267,12 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } while (true); if (injectedCount != operationCount) { - System.out.println("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); + FMLLoadingPlugin.logger.info("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); } else { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); bytes = writer.toByteArray(); - System.out.println("Injection successfull!"); + FMLLoadingPlugin.logger.info("Successful injection in " + classNode.name); } return bytes; } @@ -293,11 +291,11 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } MethodNode methodnode = (MethodNode) methods.next(); - // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + // if (debugLog) { FMLLoadingPlugin.logger.info("- Method " + methodnode.name + " " + methodnode.desc); } if ( (methodnode.name.equals(nodemap.get("func_147492_c.name")) || methodnode.name.equals("func_147492_c")) && methodnode.desc.equals(nodemap.get("func_147492_c.desc")) ) { - if (debugLog) { System.out.println("Method found!"); } + if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } int instructionIndex = 0; @@ -315,7 +313,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans "(IIILnet/minecraft/block/Block;II)Z", false); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectedCount++; } } @@ -326,12 +324,12 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } while (true); if (injectedCount != operationCount) { - System.out.println("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); + FMLLoadingPlugin.logger.info("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); } else { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); bytes = writer.toByteArray(); - System.out.println("Injection successfull!"); + FMLLoadingPlugin.logger.info("Successful injection in " + classNode.name); } return bytes; } @@ -350,11 +348,11 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } MethodNode methodnode = (MethodNode) methods.next(); - // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("- Method " + methodnode.name + " " + methodnode.desc); } if ( (methodnode.name.equals(nodemap.get("fillChunk.name")) || methodnode.name.equals("fillChunk")) && methodnode.desc.equals(nodemap.get("fillChunk.desc")) ) { - if (debugLog) { System.out.println("Method found!"); } + if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } int instructionIndex = 0; @@ -380,7 +378,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans methodnode.instructions.insertBefore(nodeAt, insertVarNode); instructionIndex++; - if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectedCount++; } } @@ -391,12 +389,12 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } while (true); if (injectedCount != operationCount) { - System.out.println("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); + FMLLoadingPlugin.logger.info("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting..."); } else { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); bytes = writer.toByteArray(); - System.out.println("Injection successfull!"); + FMLLoadingPlugin.logger.info("Successful injection in " + classNode.name); } return bytes; } @@ -404,34 +402,34 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans private static void deasm(AbstractInsnNode abstractNode) { if (abstractNode instanceof VarInsnNode) { VarInsnNode node = (VarInsnNode) abstractNode; - System.out.println(" + Var " + node.var); + FMLLoadingPlugin.logger.info(" + Var " + node.var); } else if (abstractNode instanceof LabelNode) { LabelNode node = (LabelNode) abstractNode; - System.out.println(" + Label " + node.getLabel()); + FMLLoadingPlugin.logger.info(" + Label " + node.getLabel()); } else if (abstractNode instanceof LineNumberNode) { LineNumberNode node = (LineNumberNode) abstractNode; - System.out.println(" + Line " + node.line); + FMLLoadingPlugin.logger.info(" + Line " + node.line); } else if (abstractNode instanceof InsnNode) { InsnNode node = (InsnNode) abstractNode; - System.out.println(" + Instruction " + node); + FMLLoadingPlugin.logger.info(" + Instruction " + node); } else if (abstractNode instanceof LdcInsnNode) { LdcInsnNode node = (LdcInsnNode) abstractNode; - System.out.println(" + Load " + node.cst); + FMLLoadingPlugin.logger.info(" + Load " + node.cst); } else if (abstractNode instanceof FieldInsnNode) { FieldInsnNode node = (FieldInsnNode) abstractNode; - System.out.println(" + Field " + node.owner + " " + node.name + " " + node.desc); + FMLLoadingPlugin.logger.info(" + Field " + node.owner + " " + node.name + " " + node.desc); } else if (abstractNode instanceof MethodInsnNode) { MethodInsnNode node = (MethodInsnNode) abstractNode; - System.out.println(" + Method " + node.owner + " " + node.name + " " + node.desc); + FMLLoadingPlugin.logger.info(" + Method " + node.owner + " " + node.name + " " + node.desc); } else { - System.out.println(" + Instruction " + abstractNode.getOpcode() + " " + abstractNode.getType() + " " + abstractNode.toString()); + FMLLoadingPlugin.logger.info(" + Instruction " + abstractNode.getOpcode() + " " + abstractNode.getType() + " " + abstractNode.toString()); } } diff --git a/src/main/java/cr0s/warpdrive/core/FMLLoadingPlugin.java b/src/main/java/cr0s/warpdrive/core/FMLLoadingPlugin.java index fa6e6e9f..b0f53a57 100644 --- a/src/main/java/cr0s/warpdrive/core/FMLLoadingPlugin.java +++ b/src/main/java/cr0s/warpdrive/core/FMLLoadingPlugin.java @@ -4,6 +4,9 @@ import java.io.File; import java.util.Map; import java.util.Map.Entry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import cpw.mods.fml.relauncher.IFMLCallHook; import cpw.mods.fml.relauncher.IFMLLoadingPlugin; @@ -13,6 +16,7 @@ import cpw.mods.fml.relauncher.IFMLLoadingPlugin; @IFMLLoadingPlugin.SortingIndex(value = 1001) // > 1000 to work with srg names public class FMLLoadingPlugin implements IFMLLoadingPlugin, IFMLCallHook { public static File location; + public static final Logger logger = LogManager.getLogger("WarpDriveCore"); private boolean debugLog = false; @Override @@ -34,16 +38,16 @@ public class FMLLoadingPlugin implements IFMLLoadingPlugin, IFMLCallHook { public void injectData(Map data) { location = (File) data.get("coremodLocation"); if (debugLog) { - System.out.println("injectData:"); + logger.info("injectData:"); for (Entry entry : data.entrySet()) { - System.out.println("- " + entry.getKey() + " = " + entry.getValue()); + logger.info("- " + entry.getKey() + " = " + entry.getValue()); } } } @Override public Void call() throws Exception { - if (debugLog) { System.out.println("call()"); } + if (debugLog) { logger.info("call()"); } return null; } diff --git a/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java b/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java index 9ce827f3..a2531b82 100644 --- a/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java +++ b/src/main/java/cr0s/warpdrive/world/SpaceWorldGenerator.java @@ -172,7 +172,7 @@ public class SpaceWorldGenerator implements IWorldGenerator { int aZ = (int) (z + Math.round(horizontalRange * Math.sin(bearing))); if (WarpDriveConfig.LOGGING_WORLDGEN) { - System.out.println(String.format("Big asteroid: %.3f %.3f r %.3f r makes %3d, %3d, %3d", + WarpDrive.logger.info(String.format("Big asteroid: %.3f %.3f r %.3f r makes %3d, %3d, %3d", new Object[] { Double.valueOf(binomial), Double.valueOf(bearing), Double.valueOf(yawn), Integer.valueOf(aX), Integer.valueOf(aY), Integer.valueOf(aZ) })); }