Search code examples
javascriptjavaminecraftnashornminecraft-forge

Remap Java calls in JavaScript Nashorn


I am currently trying to make JavaScript support for the game "Minecraft" using Nashorn. My goal is to give users the ability to create their own commands and features. For the most part it is working fine so far but the problem is that Minecraft's code is obfuscated when using it with Forge.

For that reason all field and method calls have to be re-mapped with their corresponding srg names.

Example: mc.thePlayer.swingItem(); to mc.field_71439_g.func_71038_i();

I am able to inject code into the Nashorn library using Mixin and I have already made a parser for the srg file. In a nutshell, what I need is the method I can use to replace thePlayer with field_71439_g or swingItem()V with func_71038_i()V before actually executing the code.

I have already tried finding the proper methods for hours.

https://github.com/CCBlueX/LiquidBounce1.8-Issues/issues/2649


Solution

  • Solution

    Just inject into this methods of "jdk.internal.dynalink.beans.AbstractJavaLinker"

    Remap methods:

    addMember(Ljava/lang/String;Ljava/lang/reflect/AccessibleObject;Ljava/util/Map;)V

    Remap fields:

    addMember(Ljava/lang/String;Ljdk/internal/dynalink/beans/SingleDynamicMethod;Ljava/util/Map;)V

    setPropertyGetter(Ljava/lang/String;Ljdk/internal/dynalink/beans/SingleDynamicMethod;Ljdk/internal/dynalink/beans/GuardedInvocationComponent$ValidationType;)V