diff --git a/src/cr0s/WarpDriveCore/WCClassTransformer.java b/src/cr0s/WarpDriveCore/WCClassTransformer.java index 1a95b06b..91fc1227 100644 --- a/src/cr0s/WarpDriveCore/WCClassTransformer.java +++ b/src/cr0s/WarpDriveCore/WCClassTransformer.java @@ -17,203 +17,179 @@ import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; -public class WCClassTransformer implements net.minecraft.launchwrapper.IClassTransformer -{ - private HashMap nodemap = new HashMap(); +public class WCClassTransformer implements net.minecraft.launchwrapper.IClassTransformer { + private HashMap nodemap = new HashMap(); - private final String GRAVITY_MANAGER_CLASS = "cr0s/WarpDrive/GravityManager"; + private final String GRAVITY_MANAGER_CLASS = "cr0s/WarpDrive/GravityManager"; - public WCClassTransformer() - { - nodemap.put("worldClass", "abw"); - nodemap.put("playerMP", "jv"); - nodemap.put("netLoginHandler", "jy"); - nodemap.put("confManagerClass", "hn"); - nodemap.put("createPlayerMethod", "a"); - nodemap.put("createPlayerDesc", "(Ljava/lang/String;)L" + nodemap.get("playerMP") + ";"); - nodemap.put("respawnPlayerMethod", "a"); - nodemap.put("respawnPlayerDesc", "(L" + nodemap.get("playerMP") + ";IZ)L" + nodemap.get("playerMP") + ";"); - nodemap.put("itemInWorldManagerClass", "jw"); - nodemap.put("attemptLoginMethodBukkit", "attemptLogin"); - nodemap.put("attemptLoginDescBukkit", "(L" + nodemap.get("netLoginHandler") + ";Ljava/lang/String;Ljava/lang/String;)L" + nodemap.get("playerMP") + ";"); - nodemap.put("playerControllerClass", "bdc"); - nodemap.put("playerClient", "bdi"); - nodemap.put("netClientHandler", "bcw"); - nodemap.put("createClientPlayerMethod", "a"); - nodemap.put("createClientPlayerDesc", "(L" + nodemap.get("worldClass") + ";)L" + nodemap.get("playerClient") + ";"); - nodemap.put("entityLivingBaseClass", "of"); - nodemap.put("moveEntityMethod", "e"); - nodemap.put("moveEntityDesc", "(FF)V"); - nodemap.put("entityItemClass", "ss"); - nodemap.put("onUpdateMethod", "l_"); - nodemap.put("onUpdateDesc", "()V"); - nodemap.put("entityRendererClass", "bfe"); - nodemap.put("updateLightmapMethod", "h"); - nodemap.put("updateLightmapDesc", "(F)V"); - nodemap.put("player", "uf"); - nodemap.put("containerPlayer", "vv"); - nodemap.put("invPlayerClass", "ud"); - nodemap.put("minecraft", "atv"); - nodemap.put("session", "aus"); - nodemap.put("guiPlayer", "axv"); - nodemap.put("thePlayer", "h"); - nodemap.put("displayGui", "a"); - nodemap.put("guiScreen", "awe"); - nodemap.put("displayGuiDesc", "(L" + nodemap.get("guiScreen") + ";)V"); - nodemap.put("runTick", "k"); - nodemap.put("runTickDesc", "()V"); - nodemap.put("clickMiddleMouseButton", "W"); - nodemap.put("clickMiddleMouseButtonDesc", "()V"); - nodemap.put("itemRendererClass", "bfj"); - nodemap.put("renderOverlaysMethod", "b"); - nodemap.put("renderOverlaysDesc", "(F)V"); - nodemap.put("updateFogColorMethod", "i"); - nodemap.put("updateFogColorDesc", "(F)V"); - nodemap.put("getFogColorMethod", "f"); - nodemap.put("getSkyColorMethod", "a"); - nodemap.put("vecClass", "atc"); - nodemap.put("entityClass", "nn"); - nodemap.put("getFogColorDesc", "(F)L" + nodemap.get("vecClass") + ";"); - nodemap.put("getSkyColorDesc", "(L" + nodemap.get("entityClass") + ";F)L" + nodemap.get("vecClass") + ";"); - nodemap.put("guiSleepClass", "avm"); - nodemap.put("wakeEntityMethod", "g"); - nodemap.put("wakeEntityDesc", "()V"); - nodemap.put("orientCameraDesc", "(L" + nodemap.get("minecraft") + ";L" + nodemap.get("entityLivingBaseClass") + ";)V"); - } + public WCClassTransformer() { + nodemap.put("worldClass", "abw"); + nodemap.put("playerMP", "jv"); + nodemap.put("netLoginHandler", "jy"); + nodemap.put("confManagerClass", "hn"); + nodemap.put("createPlayerMethod", "a"); + nodemap.put("createPlayerDesc", "(Ljava/lang/String;)L" + nodemap.get("playerMP") + ";"); + nodemap.put("respawnPlayerMethod", "a"); + nodemap.put("respawnPlayerDesc", "(L" + nodemap.get("playerMP") + ";IZ)L" + nodemap.get("playerMP") + ";"); + nodemap.put("itemInWorldManagerClass", "jw"); + nodemap.put("attemptLoginMethodBukkit", "attemptLogin"); + nodemap.put("attemptLoginDescBukkit", "(L" + nodemap.get("netLoginHandler") + ";Ljava/lang/String;Ljava/lang/String;)L" + nodemap.get("playerMP") + ";"); + nodemap.put("playerControllerClass", "bdc"); + nodemap.put("playerClient", "bdi"); + nodemap.put("netClientHandler", "bcw"); + nodemap.put("createClientPlayerMethod", "a"); + nodemap.put("createClientPlayerDesc", "(L" + nodemap.get("worldClass") + ";)L" + nodemap.get("playerClient") + ";"); + nodemap.put("entityLivingBaseClass", "of"); + nodemap.put("moveEntityMethod", "e"); + nodemap.put("moveEntityDesc", "(FF)V"); + nodemap.put("entityItemClass", "ss"); + nodemap.put("onUpdateMethod", "l_"); + nodemap.put("onUpdateDesc", "()V"); + nodemap.put("entityRendererClass", "bfe"); + nodemap.put("updateLightmapMethod", "h"); + nodemap.put("updateLightmapDesc", "(F)V"); + nodemap.put("player", "uf"); + nodemap.put("containerPlayer", "vv"); + nodemap.put("invPlayerClass", "ud"); + nodemap.put("minecraft", "atv"); + nodemap.put("session", "aus"); + nodemap.put("guiPlayer", "axv"); + nodemap.put("thePlayer", "h"); + nodemap.put("displayGui", "a"); + nodemap.put("guiScreen", "awe"); + nodemap.put("displayGuiDesc", "(L" + nodemap.get("guiScreen") + ";)V"); + nodemap.put("runTick", "k"); + nodemap.put("runTickDesc", "()V"); + nodemap.put("clickMiddleMouseButton", "W"); + nodemap.put("clickMiddleMouseButtonDesc", "()V"); + nodemap.put("itemRendererClass", "bfj"); + nodemap.put("renderOverlaysMethod", "b"); + nodemap.put("renderOverlaysDesc", "(F)V"); + nodemap.put("updateFogColorMethod", "i"); + nodemap.put("updateFogColorDesc", "(F)V"); + nodemap.put("getFogColorMethod", "f"); + nodemap.put("getSkyColorMethod", "a"); + nodemap.put("vecClass", "atc"); + nodemap.put("entityClass", "nn"); + nodemap.put("getFogColorDesc", "(F)L" + nodemap.get("vecClass") + ";"); + nodemap.put("getSkyColorDesc", "(L" + nodemap.get("entityClass") + ";F)L" + nodemap.get("vecClass") + ";"); + nodemap.put("guiSleepClass", "avm"); + nodemap.put("wakeEntityMethod", "g"); + nodemap.put("wakeEntityDesc", "()V"); + nodemap.put("orientCameraDesc", "(L" + nodemap.get("minecraft") + ";L" + nodemap.get("entityLivingBaseClass") + ";)V"); + } - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) - { - if (nodemap == null) - { - System.out.println("========= NODEMAP IS NULL!!! ========"); - return bytes; - } + @Override + public byte[] transform(String name, String transformedName, byte[] bytes) { + if (nodemap == null) { + System.out.println("========= NODEMAP IS NULL!!! ========"); + return bytes; + } - if (name.replace('.', '/').equals(nodemap.get("entityLivingBaseClass"))) - { - bytes = transformEntityLivingBase(bytes); - } - else if (name.replace('.', '/').equals(nodemap.get("entityItemClass"))) - { - bytes = transformEntityItem(bytes); - } + if (name.replace('.', '/').equals(nodemap.get("entityLivingBaseClass"))) { + bytes = transformEntityLivingBase(bytes); + } else if (name.replace('.', '/').equals(nodemap.get("entityItemClass"))) { + bytes = transformEntityItem(bytes); + } - return bytes; - } + return bytes; + } - private byte[] transformEntityItem(byte[] bytes) - { - ClassNode node = new ClassNode(); - ClassReader reader = new ClassReader(bytes); - reader.accept(node, 0); - int operationCount = 2; - int injectionCount = 0; - Iterator methods = node.methods.iterator(); + private byte[] transformEntityItem(byte[] bytes) { + ClassNode node = new ClassNode(); + ClassReader reader = new ClassReader(bytes); + reader.accept(node, 0); + int operationCount = 2; + int injectionCount = 0; + Iterator methods = node.methods.iterator(); - do - { - if (!methods.hasNext()) - { - break; - } + do { + if (!methods.hasNext()) { + break; + } - MethodNode methodnode = (MethodNode)methods.next(); + MethodNode methodnode = (MethodNode) methods.next(); - if (methodnode.name.equals(nodemap.get("onUpdateMethod")) && methodnode.desc.equals(nodemap.get("onUpdateDesc"))) - { - int count = 0; + if (methodnode.name.equals(nodemap.get("onUpdateMethod")) && methodnode.desc.equals(nodemap.get("onUpdateDesc"))) { + int count = 0; - while (count < methodnode.instructions.size()) - { - AbstractInsnNode list = methodnode.instructions.get(count); + while (count < methodnode.instructions.size()) { + AbstractInsnNode list = methodnode.instructions.get(count); - if (list instanceof LdcInsnNode) - { - LdcInsnNode nodeAt = (LdcInsnNode)list; + if (list instanceof LdcInsnNode) { + LdcInsnNode nodeAt = (LdcInsnNode) list; - if (nodeAt.cst.equals(Double.valueOf(0.039999999105930328D))) - { - VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); - MethodInsnNode overwriteNode = new MethodInsnNode(Opcodes.INVOKESTATIC, GRAVITY_MANAGER_CLASS, "getItemGravity", "(L" + nodemap.get("entityItemClass") + ";)D"); - methodnode.instructions.insertBefore(nodeAt, beforeNode); - methodnode.instructions.set(nodeAt, overwriteNode); - injectionCount++; - } + if (nodeAt.cst.equals(Double.valueOf(0.039999999105930328D))) { + VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); + MethodInsnNode overwriteNode = new MethodInsnNode(Opcodes.INVOKESTATIC, GRAVITY_MANAGER_CLASS, "getItemGravity", "(L" + nodemap.get("entityItemClass") + ";)D"); + methodnode.instructions.insertBefore(nodeAt, beforeNode); + methodnode.instructions.set(nodeAt, overwriteNode); + injectionCount++; + } - if (nodeAt.cst.equals(Double.valueOf(0.98000001907348633D))) - { - VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); - MethodInsnNode overwriteNode = new MethodInsnNode(Opcodes.INVOKESTATIC, GRAVITY_MANAGER_CLASS, "getItemGravity2", "(L" + nodemap.get("entityItemClass") + ";)D"); - methodnode.instructions.insertBefore(nodeAt, beforeNode); - methodnode.instructions.set(nodeAt, overwriteNode); - injectionCount++; - } - } + if (nodeAt.cst.equals(Double.valueOf(0.98000001907348633D))) { + VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); + MethodInsnNode overwriteNode = new MethodInsnNode(Opcodes.INVOKESTATIC, GRAVITY_MANAGER_CLASS, "getItemGravity2", "(L" + nodemap.get("entityItemClass") + ";)D"); + methodnode.instructions.insertBefore(nodeAt, beforeNode); + methodnode.instructions.set(nodeAt, overwriteNode); + injectionCount++; + } + } - count++; - } - } - } - while (true); + count++; + } + } + } while (true); - ClassWriter writer = new ClassWriter(1); - node.accept(writer); - bytes = writer.toByteArray(); - System.out.println("[WDCore] WarpDrive successfully injected bytecode into: " + node.name + " (" + injectionCount + " / " + operationCount + ")"); - return bytes; - } + ClassWriter writer = new ClassWriter(1); + node.accept(writer); + bytes = writer.toByteArray(); + System.out.println("[WDCore] WarpDrive successfully injected bytecode into: " + node.name + " (" + injectionCount + " / " + operationCount + ")"); + return bytes; + } - private byte[] transformEntityLivingBase(byte[] bytes) - { - ClassNode node = new ClassNode(); - ClassReader reader = new ClassReader(bytes); - reader.accept(node, 0); - int operationCount = 1; - int injectionCount = 0; - Iterator methods = node.methods.iterator(); + private byte[] transformEntityLivingBase(byte[] bytes) { + ClassNode node = new ClassNode(); + ClassReader reader = new ClassReader(bytes); + reader.accept(node, 0); + int operationCount = 1; + int injectionCount = 0; + Iterator methods = node.methods.iterator(); - do - { - if (!methods.hasNext()) - { - break; - } + do { + if (!methods.hasNext()) { + break; + } - MethodNode methodnode = (MethodNode)methods.next(); + MethodNode methodnode = (MethodNode) methods.next(); - if (methodnode.name.equals(nodemap.get("moveEntityMethod")) && methodnode.desc.equals(nodemap.get("moveEntityDesc"))) - { - int count = 0; + if (methodnode.name.equals(nodemap.get("moveEntityMethod")) && methodnode.desc.equals(nodemap.get("moveEntityDesc"))) { + int count = 0; - while (count < methodnode.instructions.size()) - { - AbstractInsnNode list = methodnode.instructions.get(count); + while (count < methodnode.instructions.size()) { + AbstractInsnNode list = methodnode.instructions.get(count); - if (list instanceof LdcInsnNode) - { - LdcInsnNode nodeAt = (LdcInsnNode)list; + if (list instanceof LdcInsnNode) { + LdcInsnNode nodeAt = (LdcInsnNode) list; - if (nodeAt.cst.equals(Double.valueOf(0.080000000000000002D))) - { - VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); - MethodInsnNode overwriteNode = new MethodInsnNode(Opcodes.INVOKESTATIC, GRAVITY_MANAGER_CLASS, "getGravityForEntity", "(L" + nodemap.get("entityLivingBaseClass") + ";)D"); - methodnode.instructions.insertBefore(nodeAt, beforeNode); - methodnode.instructions.set(nodeAt, overwriteNode); - injectionCount++; - } - } + if (nodeAt.cst.equals(Double.valueOf(0.080000000000000002D))) { + VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); + MethodInsnNode overwriteNode = new MethodInsnNode(Opcodes.INVOKESTATIC, GRAVITY_MANAGER_CLASS, "getGravityForEntity", "(L" + nodemap.get("entityLivingBaseClass") + ";)D"); + methodnode.instructions.insertBefore(nodeAt, beforeNode); + methodnode.instructions.set(nodeAt, overwriteNode); + injectionCount++; + } + } - count++; - } - } - } - while (true); + count++; + } + } + } while (true); - ClassWriter writer = new ClassWriter(1); - node.accept(writer); - bytes = writer.toByteArray(); - System.out.println("[WDCore] WarpDrive successfully injected bytecode into: " + node.name + " (" + injectionCount + " / " + operationCount + ")"); - return bytes; - } + ClassWriter writer = new ClassWriter(1); + node.accept(writer); + bytes = writer.toByteArray(); + System.out.println("[WDCore] WarpDrive successfully injected bytecode into: " + node.name + " (" + injectionCount + " / " + operationCount + ")"); + return bytes; + } } diff --git a/src/cr0s/WarpDriveCore/WCDummyContainer.java b/src/cr0s/WarpDriveCore/WCDummyContainer.java index 04cc9653..578ebe9d 100644 --- a/src/cr0s/WarpDriveCore/WCDummyContainer.java +++ b/src/cr0s/WarpDriveCore/WCDummyContainer.java @@ -13,48 +13,41 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -public class WCDummyContainer extends DummyModContainer -{ - public WCDummyContainer() - { - super(new ModMetadata()); - ModMetadata meta = getMetadata(); - meta.modId = "WarpDriveCore"; - meta.name = "WarpDriveCore"; - meta.version = "1.0.0.3"; - meta.credits = "Cr0s"; - meta.authorList = Arrays.asList("cr0s"); - meta.description = ""; - meta.url = ""; - meta.updateUrl = ""; - meta.screenshots = new String[0]; - meta.logoFile = ""; - } +public class WCDummyContainer extends DummyModContainer { + public WCDummyContainer() { + super(new ModMetadata()); + ModMetadata meta = getMetadata(); + meta.modId = "WarpDriveCore"; + meta.name = "WarpDriveCore"; + meta.version = "1.0.0.4"; + meta.credits = "Cr0s"; + meta.authorList = Arrays.asList("cr0s"); + meta.description = ""; + meta.url = ""; + meta.updateUrl = ""; + meta.screenshots = new String[0]; + meta.logoFile = ""; + } - @Override - public boolean registerBus(EventBus bus, LoadController controller) - { - bus.register(this); - return true; - } + @Override + public boolean registerBus(EventBus bus, LoadController controller) { + bus.register(this); + return true; + } - @Subscribe - public void modConstruction(FMLConstructionEvent evt) - { - } + @Subscribe + public void modConstruction(FMLConstructionEvent evt) { + } - @Subscribe - public void init(FMLInitializationEvent evt) - { - } + @Subscribe + public void init(FMLInitializationEvent evt) { + } - @Subscribe - public void preInit(FMLPreInitializationEvent evt) - { - } + @Subscribe + public void preInit(FMLPreInitializationEvent evt) { + } - @Subscribe - public void postInit(FMLPostInitializationEvent evt) - { - } + @Subscribe + public void postInit(FMLPostInitializationEvent evt) { + } } diff --git a/src/cr0s/WarpDriveCore/WCFMLLoadingPlugin.java b/src/cr0s/WarpDriveCore/WCFMLLoadingPlugin.java index f58ce428..37f8f9c2 100644 --- a/src/cr0s/WarpDriveCore/WCFMLLoadingPlugin.java +++ b/src/cr0s/WarpDriveCore/WCFMLLoadingPlugin.java @@ -8,45 +8,38 @@ import cpw.mods.fml.relauncher.IFMLLoadingPlugin; import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion; @MCVersion(value = "1.6.4") -public class WCFMLLoadingPlugin implements IFMLLoadingPlugin, IFMLCallHook -{ - public static File location; +public class WCFMLLoadingPlugin implements IFMLLoadingPlugin, IFMLCallHook { + public static File location; - @Override - public String[] getLibraryRequestClass() - { - return null; - } + @Override + public String[] getLibraryRequestClass() { + return null; + } - @Override - public String[] getASMTransformerClass() - { - return new String[] { WCClassTransformer.class.getName() }; - } + @Override + public String[] getASMTransformerClass() { + return new String[] { WCClassTransformer.class.getName() }; + } - @Override - public String getModContainerClass() - { - return WCDummyContainer.class.getName(); - } + @Override + public String getModContainerClass() { + return WCDummyContainer.class.getName(); + } - @Override - public String getSetupClass() - { - return getClass().getName(); - } + @Override + public String getSetupClass() { + return getClass().getName(); + } - @Override - public void injectData(Map data) - { - location = (File) data.get("coremodLocation"); - System.out.println("*** Transformer jar location location.getName: " + location.getName()); - } + @Override + public void injectData(Map data) { + location = (File) data.get("coremodLocation"); + System.out.println("*** Transformer jar location location.getName: " + location.getName()); + } - @Override - public Void call() throws Exception - { - System.out.println("[WCD] call()"); - return null; - } + @Override + public Void call() throws Exception { + System.out.println("[WCD] call()"); + return null; + } } \ No newline at end of file