List of usage examples for org.objectweb.asm Opcodes GETFIELD
int GETFIELD
To view the source code for org.objectweb.asm Opcodes GETFIELD.
Click Source Link
From source file:com.yahoo.yqlplus.engine.internal.bytecode.InstanceFieldExpression.java
@Override public void generate(CodeEmitter code) { target.generate(code);//from w w w. j a va 2 s . c o m code.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, ownerName, name, getType().getJVMType().getDescriptor()); }
From source file:de.sanandrew.core.manpack.transformer.TransformBadPotionsATN.java
License:Creative Commons License
private byte[] transformPotion(byte[] bytes) { ClassNode cn = ASMHelper.createClassNode(bytes); if (ASMHelper.hasClassMethodName(cn, ASMNames.M_isBadEffect)) { return bytes; }// www .j a va 2 s . co m MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, ASMNames.M_isBadEffect, "()Z", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/potion/Potion", ASMNames.F_isBadEffect, "Z"); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/potion/Potion;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); cn.methods.add(method); bytes = ASMHelper.createBytes(cn, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformELBAttackingPlayer.java
License:Creative Commons License
private static byte[] transformAttackingPlayer(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); /** ADD GETTER FOR ATTACKING PLAYER **/ {//from w w w.jav a 2 s . com MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getAttackingPlayer", "()Lnet/minecraft/entity/player/EntityPlayer;", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR ATTACKING PLAYER **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setAttackingPlayer", "(Lnet/minecraft/entity/player/EntityPlayer;)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_attackingPlayer, "Lnet/minecraft/entity/player/EntityPlayer;"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("player", "Lnet/minecraft/entity/player/EntityPlayer;", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD GETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_getRecentlyHit", "()I", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitFieldInsn(Opcodes.GETFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); method.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l1, 0); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } /** ADD SETTER FOR RECENTLY HIT **/ { MethodNode method = new MethodNode(Opcodes.ACC_PUBLIC, "_SAP_setRecentlyHit", "(I)V", null, null); method.visitCode(); Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ILOAD, 1); method.visitFieldInsn(Opcodes.PUTFIELD, "net/minecraft/entity/EntityLivingBase", ASMNames.F_recentlyHit, "I"); Label l1 = new Label(); method.visitLabel(l1); method.visitInsn(Opcodes.RETURN); Label l2 = new Label(); method.visitLabel(l2); method.visitLocalVariable("this", "Lnet/minecraft/entity/EntityLivingBase;", null, l0, l2, 0); method.visitLocalVariable("hit", "I", null, l0, l2, 1); method.visitMaxs(0, 0); method.visitEnd(); clazz.methods.add(method); } bytes = ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); return bytes; }
From source file:de.sanandrew.core.manpack.transformer.TransformEnderman.java
License:Creative Commons License
private static byte[] transformEnderman(byte[] bytes) { ClassNode clazz = ASMHelper.createClassNode(bytes); MethodNode method = ASMHelper.findMethod(clazz, ASMNames.MD_ENDERMAN_SHOULD_ATTACK_PLAYER); InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 1)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_PLAYER_INVENTORY)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_INVPLAYER_ARMOR_INVENTORY)); needle.add(new InsnNode(Opcodes.ICONST_3)); needle.add(new InsnNode(Opcodes.AALOAD)); needle.add(new VarInsnNode(Opcodes.ASTORE, 2)); AbstractInsnNode insertPt = ASMHelper.findFirstNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_SAPUTILS_EVENT_BUS)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_ENDER_FACING_EVENT)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 1)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_ENDERFACINGEVENT_INIT, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_EVENT_BUS_POST, false)); LabelNode l1 = new LabelNode(); newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l1)); newInstr.add(new InsnNode(Opcodes.ICONST_0)); newInstr.add(new InsnNode(Opcodes.IRETURN)); newInstr.add(l1);/*from w w w . j a va 2 s . c om*/ method.instructions.insertBefore(insertPt, newInstr); return ASMHelper.createBytes(clazz, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); }
From source file:de.sanandrew.core.manpack.transformer.TransformEntityThrowable.java
License:Creative Commons License
private static byte[] transformLqThrowable(byte[] bytes) { ClassNode classNode = ASMHelper.createClassNode(bytes); MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PUBLIC, ASMNames.MD_SAP_CAN_IMPACT_ON_LIQUID); method.visitCode();/*from ww w. ja v a2 s.co m*/ Label label1 = new Label(); method.visitLabel(label1); method.visitInsn(Opcodes.ICONST_0); method.visitInsn(Opcodes.IRETURN); Label label2 = new Label(); method.visitLabel(label2); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_THROWABLE, null, label1, label2, 0); method.visitMaxs(0, 0); method.visitEnd(); classNode.methods.add(method); method = ASMHelper.findMethod(classNode, ASMNames.MD_THROWABLE_ON_UPDATE); InsnList needle = new InsnList(); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_MOTION_Z)); needle.add(new InsnNode(Opcodes.DADD)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_VEC3_CREATE_VECTOR_HELPER, false)); needle.add(new VarInsnNode(Opcodes.ASTORE, 2)); needle.add(new LabelNode()); needle.add(new LineNumberNode(-1, new LabelNode())); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_WORLD_OBJ)); needle.add(new VarInsnNode(Opcodes.ALOAD, 1)); needle.add(new VarInsnNode(Opcodes.ALOAD, 2)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_WORLD_RAY_TRACE_BLOCKS, false)); needle.add(new VarInsnNode(Opcodes.ASTORE, -1)); VarInsnNode insertPoint = (VarInsnNode) ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList injectList = new InsnList(); injectList.add(new LabelNode()); injectList.add(new VarInsnNode(Opcodes.ALOAD, 0)); injectList.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_THROWABLE_WORLD_OBJ)); injectList.add(new VarInsnNode(Opcodes.ALOAD, 1)); injectList.add(new VarInsnNode(Opcodes.ALOAD, 2)); injectList.add(new VarInsnNode(Opcodes.ALOAD, 0)); injectList.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_CAN_IMPACT_ON_LIQUID, false)); injectList.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_WORLD_RAY_TRACE_BLOCKS_Z, false)); injectList.add(new VarInsnNode(Opcodes.ASTORE, insertPoint.var)); method.instructions.insert(insertPoint, injectList); return ASMHelper.createBytes(classNode, /*ClassWriter.COMPUTE_FRAMES |*/ ClassWriter.COMPUTE_MAXS); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static MethodNode injectMethodGetCustomArmorItem() { MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM); method.visitCode();//from w ww.j a v a 2 s. c o m Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 0); ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER); method.visitIntInsn(Opcodes.BIPUSH, 23); ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_GET_OBJ_STACK, false); method.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); method.visitLabel(l1); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l1, 0); method.visitMaxs(2, 1); method.visitEnd(); return method; }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static MethodNode injectMethodSetCustomArmorItem() { MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM); method.visitCode();/*from w ww . ja va2 s . c o m*/ Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 1); Label l1 = new Label(); method.visitJumpInsn(Opcodes.IFNONNULL, l1); method.visitTypeInsn(Opcodes.NEW, ASMNames.CL_ITEM_STACK); method.visitInsn(Opcodes.DUP); ASMHelper.visitFieldInsn(method, Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL); method.visitInsn(Opcodes.ICONST_0); ASMHelper.visitMethodInsn(method, Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false); method.visitVarInsn(Opcodes.ASTORE, 1); method.visitLabel(l1); method.visitFrame(Opcodes.F_SAME, 0, null, 0, null); method.visitVarInsn(Opcodes.ALOAD, 0); ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER); method.visitIntInsn(Opcodes.BIPUSH, 23); method.visitVarInsn(Opcodes.ALOAD, 1); ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_UPDATE_OBJ, false); Label l3 = new Label(); method.visitLabel(l3); method.visitInsn(Opcodes.RETURN); Label l4 = new Label(); method.visitLabel(l4); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l3, 0); method.visitLocalVariable("stack", ASMNames.CL_T_ITEM_STACK, null, l0, l3, 1); method.visitMaxs(5, 2); method.visitEnd(); return method; }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformArmorTexture(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_HORSE_FUNC110241CB, false)); needle.add(new VarInsnNode(Opcodes.ISTORE, 3)); AbstractInsnNode node = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); LabelNode l17 = new LabelNode(); newInstr.add(l17);/*from ww w.ja v a2 s . c om*/ newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM, false)); newInstr.add(new VarInsnNode(Opcodes.ASTORE, 4)); LabelNode l18 = new LabelNode(); newInstr.add(l18); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.INSTANCEOF, ASMNames.CL_ITEM_HORSE_ARMOR)); LabelNode l19 = new LabelNode(); newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l19)); LabelNode l20 = new LabelNode(); newInstr.add(l20); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110280BR)); newInstr.add(new InsnNode(Opcodes.ICONST_2)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.CHECKCAST, ASMNames.CL_ITEM_HORSE_ARMOR)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_GET_ARMOR_TEXTURE, false)); newInstr.add(new InsnNode(Opcodes.AASTORE)); LabelNode l21 = new LabelNode(); newInstr.add(l21); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_STRING_BUILDER)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_STRING_VALUE_OF, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_STRINGBUILDER_INIT, false)); newInstr.add(new LdcInsnNode("cst-")); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_UNLOC_NAME, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false)); newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_TO_STRING, false)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.PUTFIELD, ASMNames.FD_HORSE_FIELD110286BQ)); newInstr.add(new InsnNode(Opcodes.RETURN)); newInstr.add(l19); method.instructions.insert(node, newInstr); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformUpdateHorseSlots(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_CHEST)); needle.add(new InsnNode(Opcodes.ICONST_1)); AbstractInsnNode pointer = ASMHelper.findFirstNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_CHEST)); newInstr.add(new InsnNode(Opcodes.ICONST_1)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ANIMALCHEST_GET_STACK_IN_SLOT, false));//from w w w . j av a 2 s.com newInstr.add( ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM, false)); newInstr.add(new LabelNode()); method.instructions.insertBefore(pointer, newInstr); }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformEntityInit(MethodNode method) { InsnList needle = new InsnList(); needle.add(new VarInsnNode(Opcodes.ALOAD, 0)); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER)); needle.add(new IntInsnNode(Opcodes.BIPUSH, 22)); needle.add(new InsnNode(Opcodes.ICONST_0)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_INTEGER_VALUE_OF, false)); needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false)); AbstractInsnNode pointer = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(new LabelNode()); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER)); newInstr.add(new IntInsnNode(Opcodes.BIPUSH, 23)); newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_ITEM_STACK)); newInstr.add(new InsnNode(Opcodes.DUP)); newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL)); newInstr.add(new InsnNode(Opcodes.ICONST_0)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false)); method.instructions.insert(pointer, newInstr); }