Boosted Brightness

Boosted Brightness

642k Downloads

Incompatibility with Sodium Extra

FlashyReese opened this issue ยท 4 comments

commented

Hello, due to people reporting issues about Boosted Brightness completely breaking with Sodium Extra. I did a little bit of investigating a figured out the reflection hack to modify Sodium's Brightness Slider completely breaks due to the addition of an option group in the general page which adds back the resolution slider in Sodium Extra.

List<?> options = (List<?>) get(optionGroups.get(0), "me.jellysquid.mods.sodium.client.gui.options.OptionGroup", "options");

Suggestion to fix this issue

List<?> options = (List<?>) get(FabricLoader.getInstance().isModLoaded("sodium-extra") ? optionGroups.get(1) : optionGroups.get(0), "me.jellysquid.mods.sodium.client.gui.options.OptionGroup", "options"); 
commented

In case that a 1.16.5 version might be released in the future, this is the fixed code.
I haven't tested the following code for 1.17.1.

BoostedBrightness/src/main/java/net/boostedbrightness/mixin/MixinMinecraftClient.java
Line 35 in e0c09e2

// manipulate the sodium mods custom options screen right when it gets opened but before it gets displayed
@Inject(at = @At("HEAD"), method = "openScreen")
private void openScreen(Screen screen, CallbackInfo info) {
    if (screen instanceof GameMenuScreen && System.currentTimeMillis() - lastSaveTime > SAVE_INTERVAL) {
        saveConfig();
        lastSaveTime = System.currentTimeMillis();
    }

    if (screen == null)
        return;

    boolean hasSodiumExtra = FabricLoader.getInstance().isModLoaded("sodium-extra");
    String optionsClassName;
    int optionsGroupID;
    if (hasSodiumExtra) {
        optionsClassName = "me.flashyreese.mods.reeses_sodium_options.client.gui.SodiumVideoOptionsScreen";
        optionsGroupID = 1;
    }
    else {
        optionsClassName = "me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI";
        optionsGroupID = 0;
    }

    String screenClassName = screen.getClass().getName();
    if (!screenClassName.equals(optionsClassName))
        return;

    try {
        // screen -> pages -> 1st page (general) -> groups -> 1st group -> options -> 2nd option (gamma) -> control (slider) -> overwrite min and max
        List<?> optionPages = (List<?>) get(screen, optionsClassName, "pages");
        List<?> optionGroups = (List<?>) get(optionPages.get(0), "me.jellysquid.mods.sodium.client.gui.options.OptionPage", "groups");
        List<?> options = (List<?>) get(optionGroups.get(optionsGroupID), "me.jellysquid.mods.sodium.client.gui.options.OptionGroup", "options");
        Object sliderControl = get(options.get(1), "me.jellysquid.mods.sodium.client.gui.options.OptionImpl", "control");
        Class<?> sliderControlClass = Class.forName("me.jellysquid.mods.sodium.client.gui.options.control.SliderControl");
        setInt(sliderControl, sliderControlClass, "min", (int) (BoostedBrightness.minBrightness * 100));
        setInt(sliderControl, sliderControlClass, "max", (int) (BoostedBrightness.maxBrightness * 100));
    }
    catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException ex) {
        logException(ex, "an exception occurred during the manipulation of the sodium options gui");
    }
}
commented
        optionsClassName = "me.flashyreese.mods.reeses_sodium_options.client.gui.SodiumVideoOptionsScreen";

This might cause issues since the GUI replacement is done with a JiJ mod which can be removed on 1.16.x version and is removed in 1.17.x, I would suggest changing it to

boolean hasRSO = FabricLoader.getInstance().isModLoaded("reeses-sodium-options");
commented

It's also probably possible to simply add a dependency for sodium and sodium-extra and use their classes normally, right? It would make it much easier to modify the GUI and to check if things have changed after an update and fix them. I didn't think of that back when I added sodium compatibility, that's why I used reflection, I was still new to modding at that time.

commented

This issue should be fixed!