From 013701249ec4280b50bbae8a2f72751ffcdbb00f Mon Sep 17 00:00:00 2001 From: LostLuma Date: Wed, 18 Sep 2024 21:02:45 +0200 Subject: [PATCH] Fix runtime modified graphics settings potentially being saved --- .../java/dynamic_fps/impl/DynamicFPSMod.java | 4 +++ .../dynamic_fps/impl/mixin/OptionsMixin.java | 31 +++++++++++++++++++ .../resources/dynamic_fps-common.mixins.json | 3 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 platforms/common/src/main/java/dynamic_fps/impl/mixin/OptionsMixin.java diff --git a/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java b/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java index 76ce8a60..71b3d9a9 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java @@ -173,6 +173,10 @@ public static boolean shouldShowToasts() { return config.showToasts(); } + public static GraphicsState graphicsState() { + return config.graphicsState(); + } + public static boolean shouldShowLevels() { return isDisabled() || !isLevelCoveredByOverlay(); } diff --git a/platforms/common/src/main/java/dynamic_fps/impl/mixin/OptionsMixin.java b/platforms/common/src/main/java/dynamic_fps/impl/mixin/OptionsMixin.java new file mode 100644 index 00000000..e6681374 --- /dev/null +++ b/platforms/common/src/main/java/dynamic_fps/impl/mixin/OptionsMixin.java @@ -0,0 +1,31 @@ +package dynamic_fps.impl.mixin; + +import dynamic_fps.impl.DynamicFPSMod; +import dynamic_fps.impl.config.option.GraphicsState; +import dynamic_fps.impl.feature.state.OptionHolder; +import net.minecraft.client.*; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * Resets runtime modified graphics settings to the user-specified defaults during saving. + * Prevents the game from saving the reduced or minimal preset to disk and loading it again. + */ +@Mixin(Options.class) +public abstract class OptionsMixin { + @Inject(method = "save", at = @At("HEAD")) + private void save0(CallbackInfo callbackInfo) { + if (DynamicFPSMod.graphicsState() != GraphicsState.DEFAULT) { + OptionHolder.applyOptions(Minecraft.getInstance().options, GraphicsState.DEFAULT); + } + } + + @Inject(method = "save", at = @At("RETURN")) + private void save1(CallbackInfo callbackInfo) { + if (DynamicFPSMod.graphicsState() != GraphicsState.DEFAULT) { + OptionHolder.applyOptions(Minecraft.getInstance().options, DynamicFPSMod.graphicsState()); + } + } +} diff --git a/platforms/common/src/main/resources/dynamic_fps-common.mixins.json b/platforms/common/src/main/resources/dynamic_fps-common.mixins.json index 189a9c1e..f930e0a4 100644 --- a/platforms/common/src/main/resources/dynamic_fps-common.mixins.json +++ b/platforms/common/src/main/resources/dynamic_fps-common.mixins.json @@ -9,8 +9,9 @@ "GuiMixin", "LoadingOverlayMixin", "MinecraftMixin", + "OptionsMixin", "SoundEngineMixin", - "ToastManagerMixin", + "ToastManagerMixin", "bugfix.BlockableEventLoopMixin" ], "mixins": [],