List of usage examples for org.objectweb.asm Opcodes ICONST_1
int ICONST_1
To view the source code for org.objectweb.asm Opcodes ICONST_1.
Click Source Link
From source file:uk.co.mysterymayhem.tessellatorfix.Transformer.java
private static byte[] patchTessellatorClass(byte[] bytes) { String targetMethodName;/* w w w . j a va 2 s . c om*/ if (Plugin.runtimeDeobfEnabled) { targetMethodName = "func_147564_a"; } else { targetMethodName = "getVertexState"; } ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(bytes); classReader.accept(classNode, 0); Iterator<MethodNode> methods = classNode.methods.iterator(); while (methods.hasNext()) { MethodNode m = methods.next(); if ((m.name.equals(targetMethodName) && m.desc.equals("(FFF)Lnet/minecraft/client/shader/TesselatorVertexState;"))) { FMLLog.info("Inside target Tessellator method"); InsnList toInject = new InsnList(); // Insertion of "if (this.rawBufferIndex < 1) return" LabelNode labelNode = new LabelNode(); toInject.add(new VarInsnNode(Opcodes.ALOAD, 0)); String fieldName; if (Plugin.runtimeDeobfEnabled) { fieldName = "field_147569_p"; } else { fieldName = "rawBufferIndex"; } toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/renderer/Tessellator", fieldName, "I")); toInject.add(new InsnNode(Opcodes.ICONST_1)); toInject.add(new JumpInsnNode(Opcodes.IF_ICMPGE, labelNode)); toInject.add(new InsnNode(Opcodes.ACONST_NULL)); toInject.add(new InsnNode(Opcodes.ARETURN)); toInject.add(labelNode); // Insert after m.instructions.insert(toInject); ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); classNode.accept(writer); FMLLog.info("Exiting target Tessellator method"); return writer.toByteArray(); } } FMLLog.warning("Could not find Tessellator method out of:"); StringBuilder builder = new StringBuilder(); for (MethodNode methodNode : classNode.methods) { builder.append(methodNode.name).append(":").append(methodNode.desc).append("\n"); } FMLLog.info(builder.toString()); return bytes; }
From source file:vazkii.quark.base.asm.ClassTransformer.java
License:Creative Commons License
private static byte[] transformWorldServer(byte[] basicClass) { log("Transforming WorldServer"); MethodSignature sig = new MethodSignature("areAllPlayersAsleep", "func_73056_e", "g", "()Z"); return transform(basicClass, Pair.of(sig, combine((AbstractInsnNode node) -> { // Filter return true; }, (MethodNode method, AbstractInsnNode node) -> { // Action InsnList newInstructions = new InsnList(); newInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); newInstructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, ASM_HOOKS, "isEveryoneAsleep", "(Lnet/minecraft/world/World;)I")); newInstructions.add(new InsnNode(Opcodes.DUP)); LabelNode label = new LabelNode(); newInstructions.add(new JumpInsnNode(Opcodes.IFEQ, label)); newInstructions.add(new InsnNode(Opcodes.ICONST_1)); newInstructions.add(new InsnNode(Opcodes.ISUB)); newInstructions.add(new InsnNode(Opcodes.IRETURN)); newInstructions.add(label);//from w w w. j av a2s . c om method.instructions.insertBefore(node, newInstructions); return true; }))); }