Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ScriptAPI mapping issue with method overloading #4964

Open
ayaxdev opened this issue Dec 18, 2024 · 10 comments
Open

[BUG] ScriptAPI mapping issue with method overloading #4964

ayaxdev opened this issue Dec 18, 2024 · 10 comments
Labels
🐛 bug Something isn't working 🌑 nextgen

Comments

@ayaxdev
Copy link

ayaxdev commented Dec 18, 2024

LiquidBounce Branch

Nextgen

LiquidBounce Build/Version

0.22.0

Operating System

Windows 10

Minecraft Version

1.21.1

Describe the bug

Hello, I've found out that when calling certain methods in DrawContext, other methods with the same name (but different parameters) are called.

In the provided script, I try to call method_52706 (with the parameters Identifier texture, int x, int y, int width, int height), but method_52709 (with the parameters Identifier texture, int int2, int int3, int int4, int int5, int x, int y, int z, int width, int height) gets called instead (I'm presuming this on the amount of expected arguments).

I used this version of Yarn JavaDocs for DrawContext as my reference for the methods and their parameters. I remember getting the link to this specific version somewhere in the ScriptAPI docs or possibly on the forum, but I can't say for sure as I cannot find it anymore, sorry :/

Here's my script:

const script = registerScript({
  name: "IssueExample",
  version: "1.0.0",
  authors: ["Ajax"]
});

script.registerModule({
  name: "IssueExample_drawGuiTexture",
  category: "Client",
  description: "Sausage"
}, (mod) => {

  mod.on("overlayRender", (event) => {
    if (!mc.player || !mc.world)
      return;

    // Should map to method_52706, but (probably) maps to method_52709
    // inb4 some smartass goes "oh this is because of null!1!", no
    event.context.drawGuiTexture(null, 100, 100, 200, 200);    
  })
});

script.registerModule({
  name: "IssueExample_fill",
  category: "Client",
  description: "Sausage"
}, (mod) => {

  mod.on("overlayRender", (event) => {
    if (!mc.player || !mc.world)
      return;

    // Should map to method_25294, but (probably) maps to method_51737
    event.context.fill(100, 100, 200, 200, -1);    
  })
});


Steps to reproduce

  • Try and call a method
  • Find out there exists a method with the same name but different arguments
  • Fail
  • Get depressed

Client Log

[18:45:05] [Render thread/INFO]: [CHAT] LiquidBounce ▸ Reloaded all scripts.
[18:45:07] [Render thread/INFO]: [CHAT] LiquidBounce ▸ IssueExample_fill has been enabled.
[18:45:07] [Render thread/INFO]: [CHAT] [IssueExample.js] IssueExample::IssueExample_fill::overlayRender threw [PolyglotException]: TypeError: invokeMember (fill) on net.minecraft.class_332 failed due to: Arity error - expected: 6 actual: 5
[18:45:07] [Render thread/ERROR]: IssueExample::IssueExample_fill -> Event Function overlayRender threw an error
org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (fill) on net.minecraft.class_332 failed due to: Arity error - expected: 6 actual: 5
	at <js>.:=>(IssueExample.js:35) ~[?:?]
	at knot/com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:151) ~[org_graalvm_truffle_truffle-api-24.0.2-995983b52bfdc5a1.jar:?]
	at knot/jdk.proxy2/jdk.proxy2.$Proxy61.invoke(Unknown Source) ~[?:?]
	at knot/net.ccbluex.liquidbounce.script.bindings.features.ScriptModule.callEvent(ScriptModule.kt:86) ~[LiquidBounce.jar:?]
	at knot/net.ccbluex.liquidbounce.script.bindings.features.ScriptModule.hookHandler$lambda$2(ScriptModule.kt:126) ~[LiquidBounce.jar:?]
	at knot/net.ccbluex.liquidbounce.event.EventManager.callEvent(EventManager.kt:213) ~[LiquidBounce.jar:?]
	at knot/net.ccbluex.liquidbounce.render.engine.UIRenderer.startUIOverlayDrawing(UIRenderer.kt:70) ~[LiquidBounce.jar:?]
	at knot/net.minecraft.class_329.handler$ccn000$liquidbounce$hookRenderEventStart(class_329.java:3583) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_329.method_55805(class_329.java) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55813(class_9080.java:36) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55812(class_9080.java:22) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55813(class_9080.java:36) [client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55809(class_9080.java:29) [client-intermediary.jar:?]
	at knot/net.minecraft.class_329.method_1753(class_329.java:218) [client-intermediary.jar:?]
	at knot/net.minecraft.class_757.method_3192(class_757.java:896) [client-intermediary.jar:?]
	at knot/net.minecraft.class_310.method_1523(class_310.java:1285) [client-intermediary.jar:?]
	at knot/net.minecraft.class_310.method_1514(class_310.java:882) [client-intermediary.jar:?]
	at knot/net.minecraft.client.main.Main.main(Main.java:256) [client-intermediary.jar:?]
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:480) [fabric-loader-0.16.9.jar:?]
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) [fabric-loader-0.16.9.jar:?]
	at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) [fabric-loader-0.16.9.jar:?]

[18:42:45] [Render thread/INFO]: [CHAT] LiquidBounce ▸ Reloaded all scripts.
[18:42:53] [Render thread/INFO]: [CHAT] LiquidBounce ▸ IssueExample has been enabled.
[18:42:53] [Render thread/INFO]: [CHAT] [IssueExample.js] IssueExample::IssueExample::overlayRender threw [PolyglotException]: TypeError: invokeMember (drawGuiTexture) on net.minecraft.class_332 failed due to: Arity error - expected: 10 actual: 5
[18:42:53] [Render thread/ERROR]: IssueExample::IssueExample -> Event Function overlayRender threw an error
org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (drawGuiTexture) on net.minecraft.class_332 failed due to: Arity error - expected: 10 actual: 5
	at <js>.:=>(IssueExample.js:27) ~[?:?]
	at knot/com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:151) ~[org_graalvm_truffle_truffle-api-24.0.2-995983b52bfdc5a1.jar:?]
	at knot/jdk.proxy2/jdk.proxy2.$Proxy61.invoke(Unknown Source) ~[?:?]
	at knot/net.ccbluex.liquidbounce.script.bindings.features.ScriptModule.callEvent(ScriptModule.kt:86) ~[LiquidBounce.jar:?]
	at knot/net.ccbluex.liquidbounce.script.bindings.features.ScriptModule.hookHandler$lambda$2(ScriptModule.kt:126) ~[LiquidBounce.jar:?]
	at knot/net.ccbluex.liquidbounce.event.EventManager.callEvent(EventManager.kt:213) ~[LiquidBounce.jar:?]
	at knot/net.ccbluex.liquidbounce.render.engine.UIRenderer.startUIOverlayDrawing(UIRenderer.kt:70) ~[LiquidBounce.jar:?]
	at knot/net.minecraft.class_329.handler$ccn000$liquidbounce$hookRenderEventStart(class_329.java:3583) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_329.method_55805(class_329.java) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55813(class_9080.java:36) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55812(class_9080.java:22) ~[client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55813(class_9080.java:36) [client-intermediary.jar:?]
	at knot/net.minecraft.class_9080.method_55809(class_9080.java:29) [client-intermediary.jar:?]
	at knot/net.minecraft.class_329.method_1753(class_329.java:218) [client-intermediary.jar:?]
	at knot/net.minecraft.class_757.method_3192(class_757.java:896) [client-intermediary.jar:?]
	at knot/net.minecraft.class_310.method_1523(class_310.java:1285) [client-intermediary.jar:?]
	at knot/net.minecraft.class_310.method_1514(class_310.java:882) [client-intermediary.jar:?]
	at knot/net.minecraft.client.main.Main.main(Main.java:256) [client-intermediary.jar:?]
	at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:480) [fabric-loader-0.16.9.jar:?]
	at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) [fabric-loader-0.16.9.jar:?]
	at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) [fabric-loader-0.16.9.jar:?]

(There is nothing more unexpected in the logs other than these exceptions' stacktraces)

Screenshots

image

@github-actions github-actions bot added 🌑 nextgen 🐛 bug Something isn't working labels Dec 18, 2024
@ayaxdev
Copy link
Author

ayaxdev commented Dec 18, 2024

(I was asked to ping @commandblock2 here)

@ayaxdev
Copy link
Author

ayaxdev commented Dec 18, 2024

Also, I forgot to mention that it usually seems to "want" the method with most parameters.

@ayaxdev ayaxdev changed the title [BUG] [BUG] ScriptAPI mapping issue with method overloading Dec 18, 2024
@commandblock2
Copy link
Contributor

commandblock2 commented Dec 19, 2024

I do remember seeing this a few days ago, Method Selection for graaljs. I am not sure if this will help u, because the problem may involve remapping and the error is not found in the following doc. I will try this as soon as I build and run LiquidBounce.

@ayaxdev
Copy link
Author

ayaxdev commented Dec 19, 2024

I do remember seeing this a few days ago, Method Selection for graaljs. I am not sure if this will help u, because the problem may involve remapping and the error is not found in the following doc. I will try this as soon as I build and run LiquidBounce.

Haha, I can't get this syntax to even work, no matter how many arguments I specify. ¯\(ツ)

image

@commandblock2
Copy link
Contributor

commandblock2 commented Dec 19, 2024

I modified a bit of your script

    console.log(event);
    console.log(event.context);
    console.log(event.context.drawGuiTexture);

and found that the problem cannot be fully reproduced in a develop envrionment (LiquidBounce launched with gradle/idea), because the mapping might not be the same as the production environment? not sure at the moment.

For the first IssueExample_drawGuiTexture module, I was able to see a white squre on the screen but for the second IssueExample_fill I got a different exception.

[00:36:56] [Render thread/INFO] (LiquidBounce) Successfully saved config 'modules'.
net.ccbluex.liquidbounce.event.events.OverlayRenderEvent@5eac67c9
net.minecraft.client.gui.DrawContext@1d86f20b
function () { [native code] }
[00:36:56] [Render thread/INFO] (Minecraft) [System] [CHAT] [method-selecting.js] IssueExample::IssueExample_drawGuiTexture::overlayRender threw [PolyglotException]: 
[00:36:56] [Render thread/ERROR] (LiquidBounce) IssueExample::IssueExample_drawGuiTexture -> Event Function overlayRender threw an error
 org.graalvm.polyglot.PolyglotException: null

I will try if I can reproduce this later tomorrow if I launch LB from a normal environment. btw I am using openjdk not the new default graalvm for this one, so not sure what what is happening. Hope this information could be useful for further deep dive.

@commandblock2
Copy link
Contributor

commandblock2 commented Dec 19, 2024

Also a bit for the workaround, you can use the reflection api hack to try to call those functions, I have some old scripts, they are not built for the current api but the reflection code should function the same (didn't try tho). For example in this old script made for script api v1 1.8.9 with out-dated Core.lib, the code uses getDeclaredField() but should also be ok to use getDeclaredMethod()

@CzechHek
Copy link
Contributor

Core has an utility called Reflector which remaps calls and calls methods which have matching parameter types, might be useful.

@ayaxdev
Copy link
Author

ayaxdev commented Dec 20, 2024

Welp, I can see that I can get around this, but isn't it still a bug? So, shall I close the issue?

@commandblock2
Copy link
Contributor

Also a correction, for IssueExample_drawGuiTexture in development environment I was able to get an Exception and the second IssueExample_fill I was able to see a white square on the screen, I thought one was the other and vice versa .

Later now that I can totally reproduce 2/2 of your problems in the production environment with the LBNG I just compiled. And your comment is indeed very right.

image
image

There might be a workaround but I would treat it as a bug or something, if I were u I would keep it open. Going to take a look at the remapper implementation and see if I could do anything.

@commandblock2
Copy link
Contributor

commandblock2 commented Dec 22, 2024

Just in these two days I found there is indeed a built-in RelfectionUtil just made for scripting right now in LB. Before I was going to suggest using ReflectionUtil.invokeMethod(event.context, "fill", 100, 100, 200, 200, -1); I figured out that it's probably not working as indented right now as it

  • probably can't match the null value
  • filter the overload by parameter as intended

see https://github.com/CCBlueX/LiquidBounce/blob/1199618a72206fe7606a9e92212a5651c4d66876/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/api/ScriptReflectionUtil.kt#L71-77
Will open a separated issue for that tomorrow and possibly a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🌑 nextgen
Projects
None yet
Development

No branches or pull requests

3 participants