List of usage examples for org.objectweb.asm.tree InsnList InsnList
InsnList
From source file:net.lyonlancer5.mcmp.karasu.asm.KarasuTransformer.java
License:Apache License
private static void transformEntityLivingBase(ClassNode classNode) { Constants.LOGGER.info("======== Project Karasu ~ Water Walking Enchantment Patch ========"); Constants.LOGGER.info("Patching net.minecraft.entity.EntityLivingBase"); for (MethodNode method : classNode.methods) { if (method.desc.equals("(FF)V")) { AbstractInsnNode movefNode = null; AbstractInsnNode motionxNode = null; AbstractInsnNode motionzNode = null; AbstractInsnNode motionyNode = null; AbstractInsnNode[] moveList = method.instructions.toArray(); int var11 = moveList.length; for (int var12 = 0; var12 < var11; ++var12) { AbstractInsnNode instruction = moveList[var12]; if (instruction.getOpcode() == Opcodes.ALOAD) { if (((VarInsnNode) instruction).var == 0 && instruction.getNext().getOpcode() == Opcodes.DUP && motionxNode == null) { motionxNode = instruction; } else if (((VarInsnNode) instruction).var == 0 && instruction.getNext().getOpcode() == Opcodes.DUP && motionyNode == null) { motionyNode = instruction; } else if (((VarInsnNode) instruction).var == 0 && instruction.getNext().getOpcode() == Opcodes.DUP && motionzNode == null) { motionzNode = instruction; } else if (movefNode == null && ((VarInsnNode) instruction).var == 0 && instruction.getNext().getOpcode() == Opcodes.FLOAD && ((VarInsnNode) instruction.getNext()).var == 1) { movefNode = instruction; }/*from w w w . j a v a2s . c om*/ } } int var14; InsnList var15; if (method.name.equals("e")) { Constants.LOGGER.info("Found matching method: " + method.name + " " + method.desc + " - (Obf)"); if (motionxNode != null) { for (var14 = 0; var14 < 6; ++var14) { motionxNode = motionxNode.getNext(); method.instructions.remove(motionxNode.getPrevious()); } Constants.LOGGER.info("Patching sv.w"); var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new InsnNode(Opcodes.DUP)); var15.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", "w", "D")); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyHorizontalVel", "()D", false)); var15.add(new InsnNode(Opcodes.DMUL)); var15.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", "w", "D")); method.instructions.insertBefore(motionxNode, var15); Constants.LOGGER.info("Patched sv.w"); } if (motionzNode != null) { for (var14 = 0; var14 < 6; ++var14) { motionzNode = motionzNode.getNext(); method.instructions.remove(motionzNode.getPrevious()); } Constants.LOGGER.info("Patching sv.y"); var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new InsnNode(Opcodes.DUP)); var15.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", "y", "D")); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyHorizontalVel", "()D", false)); var15.add(new InsnNode(Opcodes.DMUL)); var15.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", "y", "D")); method.instructions.insertBefore(motionzNode, var15); Constants.LOGGER.info("Patched sv.y"); } if (movefNode != null) { for (var14 = 0; var14 < 14; ++var14) { movefNode = movefNode.getNext(); method.instructions.remove(movefNode.getPrevious()); } var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new VarInsnNode(Opcodes.FLOAD, 1)); var15.add(new VarInsnNode(Opcodes.FLOAD, 2)); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyVerticalVel", "()F", false)); var15.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/EntityLivingBase", "a", "(FFF)V", false)); method.instructions.insertBefore(movefNode, var15); Constants.LOGGER.info("Patching method -- sv.a (FFF)V"); } Constants.LOGGER.info("Patch success!"); return; } else if (method.name.equals("moveEntityWithHeading")) { Constants.LOGGER .info("Found matching method: " + method.name + " " + method.desc + " - (Deobf)"); if (motionxNode != null) { for (var14 = 0; var14 < 6; ++var14) { motionxNode = motionxNode.getNext(); method.instructions.remove(motionxNode.getPrevious()); } Constants.LOGGER.info("Patching EntityLivingBase.motionX"); var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new InsnNode(Opcodes.DUP)); var15.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", "motionX", "D")); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyHorizontalVel", "()D", false)); var15.add(new InsnNode(Opcodes.DMUL)); var15.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", "motionX", "D")); method.instructions.insertBefore(motionxNode, var15); Constants.LOGGER.info("Patched EntityLivingBase.motionX"); } if (motionzNode != null) { for (var14 = 0; var14 < 6; ++var14) { motionzNode = motionzNode.getNext(); method.instructions.remove(motionzNode.getPrevious()); } Constants.LOGGER.info("Patching EntityLivingBase.motionZ"); var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new InsnNode(Opcodes.DUP)); var15.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", "motionZ", "D")); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyHorizontalVel", "()D", false)); var15.add(new InsnNode(Opcodes.DMUL)); var15.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", "motionZ", "D")); method.instructions.insertBefore(motionzNode, var15); Constants.LOGGER.info("Patched EntityLivingBase.motionZ"); } if (movefNode != null) { for (var14 = 0; var14 < 14; ++var14) { movefNode = movefNode.getNext(); method.instructions.remove(movefNode.getPrevious()); } var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new VarInsnNode(Opcodes.FLOAD, 1)); var15.add(new VarInsnNode(Opcodes.FLOAD, 2)); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyVerticalVel", "()F", false)); var15.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/EntityLivingBase", "moveFlying", "(FFF)V", false)); method.instructions.insertBefore(movefNode, var15); Constants.LOGGER.info("Patched method - EntityLivingBase.moveFlying (FFF)V"); } Constants.LOGGER.info("Patch success!"); return; } else if (method.name.equals("func_70612_e")) { Constants.LOGGER.info("Found matching method: " + method.name + " " + method.desc + " - (srg)"); if (motionxNode != null) { for (var14 = 0; var14 < 6; ++var14) { motionxNode = motionxNode.getNext(); method.instructions.remove(motionxNode.getPrevious()); } Constants.LOGGER.info("Patching EntityLivingBase.field_70159_w"); var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new InsnNode(Opcodes.DUP)); var15.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", "field_70159_w", "D")); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyHorizontalVel", "()D", false)); var15.add(new InsnNode(Opcodes.DMUL)); var15.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", "field_70159_w", "D")); method.instructions.insertBefore(motionxNode, var15); Constants.LOGGER.info("Patched EntityLivingBase.field_70159_w"); } if (motionzNode != null) { for (var14 = 0; var14 < 6; ++var14) { motionzNode = motionzNode.getNext(); method.instructions.remove(motionzNode.getPrevious()); } Constants.LOGGER.info("Patching EntityLivingBase.field_70179_y"); var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new InsnNode(Opcodes.DUP)); var15.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", "field_70179_y", "D")); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyHorizontalVel", "()D", false)); var15.add(new InsnNode(Opcodes.DMUL)); var15.add(new FieldInsnNode(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", "field_70179_y", "D")); method.instructions.insertBefore(motionzNode, var15); Constants.LOGGER.info("Patched EntityLivingBase.field_70179_y"); } if (movefNode != null) { for (var14 = 0; var14 < 14; ++var14) { movefNode = movefNode.getNext(); method.instructions.remove(movefNode.getPrevious()); } var15 = new InsnList(); var15.add(new VarInsnNode(Opcodes.ALOAD, 0)); var15.add(new VarInsnNode(Opcodes.FLOAD, 1)); var15.add(new VarInsnNode(Opcodes.FLOAD, 2)); var15.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/lyonlancer5/mcmp/karasu/asm/KarasuFeatherMetadata", "modifyVerticalVel", "()F", false)); var15.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/entity/EntityLivingBase", "func_70060_a", "(FFF)V", false)); method.instructions.insertBefore(movefNode, var15); Constants.LOGGER.info("Patched method - EntityLivingBase.func_70060_a (FFF)V"); } Constants.LOGGER.info("Patch success!"); return; } } } // #OVERKILL throw new RuntimeException("Patch FAILED -- No matching method found"); }
From source file:net.malisis.core.asm.AsmHook.java
License:Open Source License
public AsmHook insert(AbstractInsnNode insert) { InsnList list = new InsnList(); list.add(insert); return insert(list); }
From source file:net.malisis.core.asm.MalisisCoreTransformer.java
License:Open Source License
@SuppressWarnings("deprecation") public AsmHook userAttackEntityEventHook() { McpMethodMapping attackEntity = new McpMethodMapping("attackEntity", "func_78764_a", "net.minecraft.client.multiplayer.PlayerControllerMP", "(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/entity/Entity;)V"); AsmHook ah = new AsmHook(attackEntity); LabelNode falseLabel = new LabelNode(); InsnList insert1 = new InsnList(); insert1.add(new TypeInsnNode(NEW, "net/malisis/core/event/user/UserAttackEvent")); insert1.add(new InsnNode(DUP)); insert1.add(new VarInsnNode(ALOAD, 1)); insert1.add(new VarInsnNode(ALOAD, 2)); insert1.add(new MethodInsnNode(INVOKESPECIAL, "net/malisis/core/event/user/UserAttackEvent", "<init>", "(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/entity/Entity;)V")); insert1.add(//from w w w . java2s . c o m new MethodInsnNode(INVOKEVIRTUAL, "net/malisis/core/event/user/UserAttackEvent", "post", "()Z")); insert1.add(new JumpInsnNode(IFEQ, falseLabel)); insert1.add(new InsnNode(RETURN)); insert1.add(falseLabel); ah.insert(insert1); return ah; }
From source file:net.malisis.core.asm.MalisisCoreTransformer.java
License:Open Source License
@SuppressWarnings("deprecation") public AsmHook keyboardEventHook() { McpMethodMapping runTick = new McpMethodMapping("runTick", "func_71407_l", "net.minecraft.client.Minecraft", "()V"); McpMethodMapping setKeyBindState = new McpMethodMapping("setKeyBindState", "func_74510_a", "net/minecraft/client/settings/KeyBinding", "(IZ)V"); AsmHook ah = new AsmHook(runTick); LabelNode falseLabel = new LabelNode(); // if(new KeyboardEvent().post()) InsnList insert1 = new InsnList(); insert1.add(new TypeInsnNode(NEW, "net/malisis/core/event/user/KeyboardEvent")); insert1.add(new InsnNode(DUP)); insert1.add(/*from w w w . jav a 2 s . co m*/ new MethodInsnNode(INVOKESPECIAL, "net/malisis/core/event/user/KeyboardEvent", "<init>", "()V")); insert1.add(new MethodInsnNode(INVOKEVIRTUAL, "net/malisis/core/event/user/KeyboardEvent", "post", "()Z")); insert1.add(new JumpInsnNode(IFNE, falseLabel)); // L1844: KeyBinding.setKeyBindState(Keyboard.getEventKey(), Keyboard.getEventKeyState()); InsnList match1 = new InsnList(); match1.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/input/Keyboard", "getEventKey", "()I")); match1.add(new MethodInsnNode(INVOKESTATIC, "org/lwjgl/input/Keyboard", "getEventKeyState", "()Z")); match1.add(setKeyBindState.getInsnNode(INVOKESTATIC)); // L1973: FMLCommonHandler.instance().fireKeyInput() InsnList match2 = new InsnList(); match2.add(new MethodInsnNode(INVOKESTATIC, "cpw/mods/fml/common/FMLCommonHandler", "instance", "()Lcpw/mods/fml/common/FMLCommonHandler;")); match2.add( new MethodInsnNode(INVOKEVIRTUAL, "cpw/mods/fml/common/FMLCommonHandler", "fireKeyInput", "()V")); ah.jumpAfter(match1).insert(insert1).jumpAfter(match2).insert(falseLabel); return ah; }
From source file:net.malisis.mdt.asm.MDTTransformer.java
License:Open Source License
private AsmHook autoWorldLoadHook() { McpMethodMapping startMethod = new McpMethodMapping("startGame", "func_71384_a", "net.minecraft.client.Minecraft", "()V"); AsmHook ah = new AsmHook(startMethod); //NEW AutoWorldLoader //INVOKESPECIAL AutoWorldLoader.<init> () : void InsnList insert = new InsnList(); insert.add(new TypeInsnNode(NEW, "net/malisis/mdt/AutoWorldLoader")); insert.add(new MethodInsnNode(INVOKESPECIAL, "net/malisis/mdt/AutoWorldLoader", "<init>", "()V")); ah.jumpToEnd().jump(-2).insert(insert); return ah;//from ww w .j a va 2s.c om }
From source file:net.malisis.switches.asm.MalisisSwitchesTransformer.java
License:Open Source License
private AsmHook getRedstonePower() { McpMethodMapping getRedstonePower = new McpMethodMapping("getRedstonePower", "func_175651_c", "net.minecraft.world.World", "(Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;)I"); AsmHook ah = new AsmHook(getRedstonePower); //return PowerManager.getRedstonePower(this, pos, side) //ALOAD 0/*from w w w . j a v a 2s . c o m*/ //ALOAD 1 //ALOAD 2 //INVOKESTATIC net/malisis/switches/PowerManager.getRedstonePower (Lnet/minecraft/world/World;Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;)I //IRETURN InsnList insert = new InsnList(); insert.add(new VarInsnNode(ALOAD, 0)); insert.add(new VarInsnNode(ALOAD, 1)); insert.add(new VarInsnNode(ALOAD, 2)); insert.add(new MethodInsnNode(INVOKESTATIC, "net/malisis/switches/PowerManager", "getRedstonePower", "(Lnet/minecraft/world/World;Lnet/minecraft/util/BlockPos;Lnet/minecraft/util/EnumFacing;)I", false)); insert.add(new InsnNode(IRETURN)); ah.insert(insert); return ah; }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
public BytecodeEmitVisitor(ASMBytecodeEmitter context, RunMethod runMethod, SlotAllocInfo slots, TypeInfo types, List<RunMethod.ClosureFieldInstance> instanceLevelClosures, List<RunMethod.ConstFieldInstance> constFields, int segmentIdx, RunMethod.LabelResolver resolver) { this.context = Objects.requireNonNull(context); this.runMethod = Objects.requireNonNull(runMethod); this.slots = Objects.requireNonNull(slots); this.types = Objects.requireNonNull(types); this.segmentIdx = segmentIdx; this.resolver = Objects.requireNonNull(resolver); this.labels = new HashMap<>(); this.resumptionPoints = new ArrayList<>(); this.il = new InsnList(); this.locals = new ArrayList<>(); this.instanceLevelClosures = Objects.requireNonNull(instanceLevelClosures); this.constFields = Objects.requireNonNull(constFields); }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
private static InsnList newByteString(ByteString value) { InsnList il = new InsnList(); il.add(new LdcInsnNode(value.toRawString())); il.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(ByteString.class), "fromRaw", Type.getMethodDescriptor(Type.getType(ByteString.class), Type.getType(String.class)), false)); return il;//from w w w . j ava 2 s. co m }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
public InsnList retrieve_0() { InsnList il = new InsnList(); il.add(loadExecutionContext()); il.add(loadReturnBuffer()); il.add(ReturnBufferMethods.get(0)); return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
public InsnList loadUpvalueRef(UpVar uv) { InsnList il = new InsnList(); il.add(new VarInsnNode(ALOAD, 0)); il.add(new FieldInsnNode(GETFIELD, context.thisClassType().getInternalName(), context.getUpvalueFieldName(uv), Type.getDescriptor(Variable.class))); return il;//from w w w . j a v a2 s. com }