xia-mc / Raven-XD

raven b4, but free.
https://wiki.client.wtf/
128 stars 33 forks source link

Attempting to use `modules.getSlider` on a ModeSetting will produce a ClassCastException [Scripting API] #631

Closed loud2pro closed 1 month ago

loud2pro commented 1 month ago

Pre-reporting checklist

Description

Hello, when I try to use your Scripting API to get a Mode Setting's current value (there is no way to get a mode setting in itself, and reading https://blowsy.gitbook.io/raven/documentation/modules tells me to use modules.getSlider), it throws a ClassCastException

Here is the code I've wrote for it:

void onEnable() {
    try {
        client.print(String.valueOf(modules.getSlider("RotationHandler", "Move fix")));
    } catch (ClassCastException e) {
        client.print(e.getMessage());
    }
}

Repro steps

  1. Make a script and put the code I've wrote there
  2. Try to load the script
  3. You will get an error in your chat

Raven XD version

v1.14

Crash report (if applicable)

No response

xia-mc commented 1 month ago

Sorry, I forgot to add the getMode() API for ModeSetting. In the next version you will be able to get the values of SliderSetting and ModeSetting via modules.getMode() or modules.getSilder().

By the way, in the current version, you can do this via reflection:

void onEnable() {
    try {
        Class<?> rotationHandlerClass = Class.forName("keystrokesmod.module.impl.other.RotationHandler");
        java.lang.reflect.Field moveFixField = rotationHandlerClass.getDeclaredField("moveFix");

        Class<?> moduleManagerClass = Class.forName("keystrokesmod.module.ModuleManager");
        java.lang.reflect.Field rotationHandlerField = moduleManagerClass.getDeclaredField("rotationHandler");
        Object rotationHandler = rotationHandlerField.get(null);

        moveFixField.setAccessible(true);
        double input = ((keystrokesmod.module.setting.impl.ModeSetting) moveFixField.get(rotationHandler)).getInput();

        client.print(String.valueOf(input));
    } catch (Exception e) {
        client.print(e.getMessage());
    }
}
loud2pro commented 1 month ago

Okay, I will try that. Thanks!