Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ================jarにして本チャン環境で走らせる場合はこちら================
- if (mnode != null)
- {
- System.out.println("EnumEnchantmentrClass patching");
- InsnList overrideList = new InsnList();
- LabelNode l2 = new LabelNode();
- // メソッドコールを、バイトコードであらわした例です。
- overrideList.add(new FieldInsnNode(GETSTATIC, "hogehoge/hoge", "enchaHook", "Lhogehoge/functions/FuncEnchantExtension;"));
- overrideList.add(new VarInsnNode(ALOAD, 1));
- overrideList.add(new VarInsnNode(ALOAD, 0));
- overrideList.add(new MethodInsnNode(INVOKEVIRTUAL, "hogehoge/functions/FuncEnchantExtension", "canEnchantItem", "(Ladb;Lafu;)Z"));
- overrideList.add(new JumpInsnNode(IFEQ, l2));
- overrideList.add(new InsnNode(ICONST_1));
- overrideList.add(new InsnNode(IRETURN));
- overrideList.add(l2);
- // mnode.instructions.get(1)で、対象のメソッドの先頭を取得
- // mnode.instructions.insertで、指定した位置にバイトコードを挿入します。
- mnode.instructions.insert(mnode.instructions.get(1), overrideList);
- // 改変したクラスファイルをバイト列に書き出します
- ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
- cnode.accept(cw);
- bytes = cw.toByteArray();
- System.out.println("EnumEnchantmentrClass patching success!!:");
- }
- ================eclipseからのdebug環境で走らせる場合はこちら================
- InsnList overrideList = new InsnList();
- LabelNode l2 = new LabelNode();
- //System.out.println("DEBUGLINE2:**********************************************ENCHANT***********************");
- // メソッドコールを、バイトコードであらわした例です。
- overrideList.add(new FieldInsnNode(GETSTATIC, "hogehoge/hoge", "enchaHook", "Lhogehoge/functions/FuncEnchantExtension;"));
- overrideList.add(new VarInsnNode(ALOAD, 1));
- overrideList.add(new VarInsnNode(ALOAD, 0));
- overrideList.add(new MethodInsnNode(INVOKEVIRTUAL, "hogehoge/functions/FuncEnchantExtension", "canEnchantItem", "(Lnet/minecraft/item/Item;Lnet/minecraft/enchantment/EnumEnchantmentType;)Z"));
- overrideList.add(new JumpInsnNode(IFEQ, l2));
- overrideList.add(new InsnNode(ICONST_1));
- overrideList.add(new InsnNode(IRETURN));
- overrideList.add(l2);
- mnode.instructions.insert(mnode.instructions.get(1), overrideList);
- // 改変したクラスファイルをバイト列に書き出します
- ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
- cnode.accept(cw);
- bytes = cw.toByteArray();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement