Advertisement
PaleoCrafter

Untitled

Mar 25th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 4.22 KB | None | 0 0
  1. val m = ASMUtil.getMappedMethod(clazz, MUpdateRendererMcp, MUpdateRendererSrg)
  2. val insnsPre = new InsnList()
  3. // Call the pre render hook, if it returns true, return the method
  4. val lblTrue = new LabelNode() // Label for if-statement
  5. val lblFalse = new LabelNode()
  6. insnsPre.add(new VarInsnNode(Opcodes.ALOAD, 16)) // Pass 'renderer' as argument to onRenderByTypePost
  7. insnsPre.add(new VarInsnNode(Opcodes.ALOAD, 16)) // Pass 'renderer' as argument to getfield
  8. insnsPre.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/renderer/RenderBlocks", ASMUtil.validateName(FBlockAccessMcp, FBlockAccessSrg), "Lnet/minecraft/world/IBlockAccess;")) // Pass 'blockAccess' as argument to onRenderByTypePost
  9. insnsPre.add(new VarInsnNode(Opcodes.ILOAD, 23)) // Pass 'x' as argument to onRenderByTypePost
  10. insnsPre.add(new VarInsnNode(Opcodes.ILOAD, 21)) // Pass 'y' as argument to onRenderByTypePost
  11. insnsPre.add(new VarInsnNode(Opcodes.ILOAD, 22)) // Pass 'z' as argument to onRenderByTypePost
  12. insnsPre.add(new VarInsnNode(Opcodes.ALOAD, 24)) // Pass 'block' as argument to onRenderByTypePost
  13. insnsPre.add(new VarInsnNode(Opcodes.ILOAD, 17)) // Pass 'renderPass' as argument to onRenderByTypePost
  14. val name = "onRenderByTypePre"
  15. val desc = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getObjectType("net/minecraft/client/renderer/RenderBlocks"), Type.getObjectType("net/minecraft/world/IBlockAccess"), Type.INT_TYPE, Type.INT_TYPE, Type.INT_TYPE, Type.getObjectType("net/minecraft/block/Block"), Type.INT_TYPE) // Method descriptor for onRenderByTypePre
  16. insnsPre.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "de/mineformers/core/impl/asm/ASMHooks", name, desc)) // Invoke onRenderByTypePre
  17. insnsPre.add(new JumpInsnNode(Opcodes.IFEQ, lblTrue)) // Use the result as if jump
  18. insnsPre.add(new InsnNode(Opcodes.ICONST_1))
  19. insnsPre.add(new VarInsnNode(Opcodes.ISTORE, 19))
  20. insnsPre.add(new JumpInsnNode(Opcodes.GOTO, lblFalse))
  21. insnsPre.add(lblTrue)
  22.  
  23. val insnsPost = new InsnList()
  24. // Call the post render hook
  25. insnsPost.add(new VarInsnNode(Opcodes.ALOAD, 16)) // Pass 'renderer' as argument to onRenderByTypePost
  26. insnsPost.add(new VarInsnNode(Opcodes.ALOAD, 16)) // Pass 'renderer' as argument to getfield
  27. insnsPost.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/renderer/RenderBlocks", ASMUtil.validateName(FBlockAccessMcp, FBlockAccessSrg), "Lnet/minecraft/world/IBlockAccess;")) // Pass 'blockAccess' as argument to onRenderByTypePost
  28. insnsPost.add(new VarInsnNode(Opcodes.ILOAD, 23)) // Pass 'x' as argument to onRenderByTypePost
  29. insnsPost.add(new VarInsnNode(Opcodes.ILOAD, 21)) // Pass 'y' as argument to onRenderByTypePost
  30. insnsPost.add(new VarInsnNode(Opcodes.ILOAD, 22)) // Pass 'z' as argument to onRenderByTypePost
  31. insnsPost.add(new VarInsnNode(Opcodes.ALOAD, 24)) // Pass 'block' as argument to onRenderByTypePost
  32. insnsPre.add(new VarInsnNode(Opcodes.ILOAD, 17)) // Pass 'renderPass' as argument to onRenderByTypePost
  33. val namePost = "onRenderByTypePost"
  34. val descPost = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getObjectType("net/minecraft/client/renderer/RenderBlocks"), Type.getObjectType("net/minecraft/world/IBlockAccess"), Type.INT_TYPE, Type.INT_TYPE, Type.INT_TYPE, Type.getObjectType("net/minecraft/block/Block"), Type.INT_TYPE) // Method descriptor for onRenderByTypePost
  35. insnsPost.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "de/mineformers/core/impl/asm/ASMHooks", namePost, descPost)) // Invoke onRenderByTypePost
  36.  
  37. val loop = new Breaks
  38. var visitedPre = false
  39. loop.breakable(for (i <- 0 until m.instructions.size()) {
  40.   m.instructions.get(i) match {
  41.     case v: VarInsnNode => if (v.`var` == 24) {
  42.       if (v.getOpcode == Opcodes.ALOAD && v.getNext.getOpcode == Opcodes.ILOAD &&
  43.         v.getNext.getNext.getOpcode == Opcodes.INVOKEVIRTUAL && v.getNext.getNext.getNext.getOpcode == Opcodes.IFNE &&
  44.         !visitedPre) {
  45.         visitedPre = true
  46.         m.instructions.insertBefore(v.getPrevious.getPrevious.getPrevious, insnsPre)
  47.       }
  48.     }
  49.     case i: IincInsnNode => if(i.getOpcode == Opcodes.IINC) {
  50.       if(i.`var` == 23 && i.getNext.getOpcode == Opcodes.GOTO) {
  51.         m.instructions.insertBefore(i, insnsPost)
  52.         m.instructions.insertBefore(i, lblFalse)
  53.         loop.break()
  54.       }
  55.     }
  56.     case _ =>
  57.   }
  58. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement