Advertisement
Guest User

Untitled

a guest
Mar 19th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. ================jarにして本チャン環境で走らせる場合はこちら================
  2.  
  3. if (mnode != null)
  4. {
  5. System.out.println("EnumEnchantmentrClass patching");
  6. InsnList overrideList = new InsnList();
  7. LabelNode l2 = new LabelNode();
  8.  
  9. // メソッドコールを、バイトコードであらわした例です。
  10. overrideList.add(new FieldInsnNode(GETSTATIC, "hogehoge/hoge", "enchaHook", "Lhogehoge/functions/FuncEnchantExtension;"));
  11. overrideList.add(new VarInsnNode(ALOAD, 1));
  12. overrideList.add(new VarInsnNode(ALOAD, 0));
  13. overrideList.add(new MethodInsnNode(INVOKEVIRTUAL, "hogehoge/functions/FuncEnchantExtension", "canEnchantItem", "(Ladb;Lafu;)Z"));
  14. overrideList.add(new JumpInsnNode(IFEQ, l2));
  15. overrideList.add(new InsnNode(ICONST_1));
  16. overrideList.add(new InsnNode(IRETURN));
  17. overrideList.add(l2);
  18.  
  19. // mnode.instructions.get(1)で、対象のメソッドの先頭を取得
  20. // mnode.instructions.insertで、指定した位置にバイトコードを挿入します。
  21.  
  22. mnode.instructions.insert(mnode.instructions.get(1), overrideList);
  23.  
  24. // 改変したクラスファイルをバイト列に書き出します
  25. ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
  26.  
  27. cnode.accept(cw);
  28. bytes = cw.toByteArray();
  29. System.out.println("EnumEnchantmentrClass patching success!!:");
  30. }
  31.  
  32.  
  33. ================eclipseからのdebug環境で走らせる場合はこちら================
  34. InsnList overrideList = new InsnList();
  35. LabelNode l2 = new LabelNode();
  36.  
  37. //System.out.println("DEBUGLINE2:**********************************************ENCHANT***********************");
  38. // メソッドコールを、バイトコードであらわした例です。
  39. overrideList.add(new FieldInsnNode(GETSTATIC, "hogehoge/hoge", "enchaHook", "Lhogehoge/functions/FuncEnchantExtension;"));
  40. overrideList.add(new VarInsnNode(ALOAD, 1));
  41. overrideList.add(new VarInsnNode(ALOAD, 0));
  42. overrideList.add(new MethodInsnNode(INVOKEVIRTUAL, "hogehoge/functions/FuncEnchantExtension", "canEnchantItem", "(Lnet/minecraft/item/Item;Lnet/minecraft/enchantment/EnumEnchantmentType;)Z"));
  43. overrideList.add(new JumpInsnNode(IFEQ, l2));
  44. overrideList.add(new InsnNode(ICONST_1));
  45. overrideList.add(new InsnNode(IRETURN));
  46. overrideList.add(l2);
  47.  
  48. mnode.instructions.insert(mnode.instructions.get(1), overrideList);
  49.  
  50. // 改変したクラスファイルをバイト列に書き出します
  51. ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
  52.  
  53. cnode.accept(cw);
  54. bytes = cw.toByteArray();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement