Esempio n. 1
0
  public void addTinkersDrawHoveringTextHook(
      MethodNode method,
      Class<?> hookClass,
      String hookMethod,
      String hookDesc,
      boolean isObfuscated) {
    AbstractInsnNode targetNode = null;

    // get last drawGradientRect call
    for (AbstractInsnNode instruction : method.instructions.toArray()) {
      if (instruction.getOpcode() == INVOKEVIRTUAL) {
        MethodInsnNode methodInsn = (MethodInsnNode) instruction;

        if (methodInsn.desc.equals("(IIIIII)V")) targetNode = instruction;
      }
    }
    if (targetNode == null) {
      AppleCore.Log.warn("Could not patch " + method.name + "; target node not found");
      return;
    }

    LocalVariableNode x = ASMHelper.findLocalVariableOfMethod(method, "i1", "I");
    LocalVariableNode y = ASMHelper.findLocalVariableOfMethod(method, "j1", "I");
    LocalVariableNode w = ASMHelper.findLocalVariableOfMethod(method, "k", "I");
    LocalVariableNode h = ASMHelper.findLocalVariableOfMethod(method, "k1", "I");

    if (x == null || y == null || w == null || h == null) {
      AppleCore.Log.warn("Could not patch " + method.name + "; local variables not found");
      return;
    }

    InsnList toInject = new InsnList();

    /*
    // equivalent to:
    Hooks.onDrawHoveringText(0, 0, 0, 0);
    */

    toInject.add(new VarInsnNode(ILOAD, x.index));
    toInject.add(new VarInsnNode(ILOAD, y.index));
    toInject.add(new VarInsnNode(ILOAD, w.index));
    toInject.add(new VarInsnNode(ILOAD, h.index));
    toInject.add(
        new MethodInsnNode(
            INVOKESTATIC, hookClass.getName().replace('.', '/'), hookMethod, hookDesc, false));

    method.instructions.insert(targetNode, toInject);
  }
Esempio n. 2
0
  @Override
  public byte[] transform(String name, String transformedName, byte[] bytes) {
    ClassNode classNode = ASMHelper.readClassFromBytes(bytes);

    if (transformedName.equals("net.minecraft.client.gui.GuiScreen")) {

      MethodNode methodNode =
          ASMHelper.findMethodNodeOfClass(
              classNode,
              "drawHoveringText",
              "drawHoveringText",
              "(Ljava/util/List;IILnet/minecraft/client/gui/FontRenderer;)V");

      if (methodNode != null) {
        addDrawHoveringTextHook(methodNode, Hooks.class, "onDrawHoveringText", "(IIII)V");
      } else throw new RuntimeException("GuiScreen.drawHoveringText not found");
    } else if (name.equals("codechicken.lib.gui.GuiDraw")) {
      MethodNode methodNode =
          ASMHelper.findMethodNodeOfClass(classNode, "drawTooltipBox", "drawTooltipBox", "(IIII)V");

      if (methodNode != null) {
        addCodeChickenDrawHoveringTextHook(
            methodNode, Hooks.class, "onDrawHoveringText", "(IIII)V");
      } else AppleCore.Log.error("drawTooltipBox method in codechicken.lib.gui.GuiDraw not found");
    } else if (name.equals("tconstruct.client.gui.NewContainerGui")) {
      MethodNode methodNode =
          ASMHelper.findMethodNodeOfClass(
              classNode, "func_102021_a", "func_102021_a", "(Ljava/util/List;II)V");

      if (methodNode != null) {
        addTinkersDrawHoveringTextHook(
            methodNode, Hooks.class, "onDrawHoveringText", "(IIII)V", false);
      } else
        AppleCore.Log.error(
            "func_102021_a method in tconstruct.client.gui.NewContainerGui not found");
    }

    return ASMHelper.writeClassToBytes(classNode);
  }