diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-02 06:12:23 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-02 06:12:23 +0700 |
commit | d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051 (patch) | |
tree | 9bb9b53e2823f73084780673763504f4098bae69 /src/main/java/cc/polyfrost/oneconfig/internal | |
parent | d2b1d57120bb51e76191302a58d935afe52b89df (diff) | |
download | OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.tar.gz OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.tar.bz2 OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.zip |
Separate Minecraft dependant and non-dependant code
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/internal')
23 files changed, 24 insertions, 956 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java deleted file mode 100644 index 4e531de..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -package cc.polyfrost.oneconfig.internal; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.ShutdownEvent; -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.internal.command.OneConfigCommand; -import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; -import cc.polyfrost.oneconfig.internal.config.Preferences; -import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; -import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler; -import cc.polyfrost.oneconfig.internal.gui.BlurHandler; -import cc.polyfrost.oneconfig.internal.hud.HudCore; -import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; -import cc.polyfrost.oneconfig.utils.commands.CommandManager; -import cc.polyfrost.oneconfig.utils.gui.GuiUtils; -import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.File; - -/** - * The main class of OneConfig. - */ -@net.minecraftforge.fml.common.Mod(modid = "@ID@", name = "@NAME@", version = "@VER@") -public class OneConfig { - - public OneConfig() { - EventManager.INSTANCE.register(this); - } - - public static final File oneConfigDir = new File("./OneConfig"); - public static final Logger LOGGER = LogManager.getLogger("@NAME@"); - public static OneConfigConfig config; - public static Preferences preferences; - private static boolean preLaunched = false; - private static boolean initialized = false; - private static boolean isObfuscated = true; - - /** - * Called before mods are loaded. - * <p><b>SHOULD NOT BE CALLED!</b></p> - */ - public static void preLaunch() { - if (preLaunched) return; - try { - Class.forName("net.minecraft.world.World"); - LOGGER.warn("OneConfig is NOT obfuscated!"); - isObfuscated = false; - } catch (Exception ignored) { - } - oneConfigDir.mkdirs(); - new File(oneConfigDir, "profiles").mkdirs(); - config = new OneConfigConfig(); - preferences = new Preferences(); - preLaunched = true; - } - - /** - * Called after mods are loaded. - * <p><b>SHOULD NOT BE CALLED!</b></p> - */ - @SuppressWarnings("ResultOfMethodCallIgnored") - public static void init() { - if (initialized) return; - GuiUtils.getDeltaTime(); // called to make sure static initializer is called - BlurHandler.INSTANCE.load(); - CommandManager.INSTANCE.registerCommand(OneConfigCommand.class); - EventManager.INSTANCE.register(new HudCore()); - HypixelUtils.INSTANCE.initialize(); - EventManager.INSTANCE.register(KeyBindHandler.INSTANCE); - ConfigCore.sortMods(); - - initialized = true; - } - - /** Returns weather this is an obfuscated environment, using a check for obfuscated name of net.minecraft.world.World.class. - * @return true if this is an obfuscated environment, which is normal for Minecraft or false if not. */ - public static boolean isObfuscated() { - return isObfuscated; - } - - @Subscribe - private void onShutdown(ShutdownEvent event) { - ConfigCore.saveAll(); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java index 0ed5dc2..c7b95d1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/OneConfigConfig.java @@ -1,14 +1,7 @@ package cc.polyfrost.oneconfig.internal.config; -import cc.polyfrost.oneconfig.config.Config; import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.utils.JsonUtils; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; public class OneConfigConfig extends InternalConfig { @@ -24,8 +17,15 @@ public class OneConfigConfig extends InternalConfig { public static ArrayList<OneColor> recentColors = new ArrayList<>(); public static boolean australia = false; + private static OneConfigConfig INSTANCE; + public OneConfigConfig() { super("", "OneConfig.json"); initialize(); + INSTANCE = this; + } + + public static OneConfigConfig getInstance() { + return INSTANCE == null ? (INSTANCE = new OneConfigConfig()) : INSTANCE; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java index fff8fed..f98a913 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java @@ -7,7 +7,8 @@ import cc.polyfrost.oneconfig.config.core.OneKeyBind; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.internal.gui.BlurHandler; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; -import cc.polyfrost.oneconfig.libs.universal.UMinecraft; +import cc.polyfrost.oneconfig.platform.Platform; +import cc.polyfrost.oneconfig.utils.TickDelay; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; public class Preferences extends InternalConfig { @@ -37,10 +38,17 @@ public class Preferences extends InternalConfig { ) public static float customScale = 1f; + private static Preferences INSTANCE; + public Preferences() { super("Preferences", "Preferences.json"); initialize(); - addListener("enableBlur", () -> BlurHandler.INSTANCE.reloadBlur(UMinecraft.getMinecraft().currentScreen)); - registerKeyBind(oneConfigKeyBind, () -> GuiUtils.displayScreen(OneConfigGui.create())); + addListener("enableBlur", () -> BlurHandler.INSTANCE.reloadBlur(Platform.getGuiPlatform().getCurrentScreen())); + registerKeyBind(oneConfigKeyBind, () -> new TickDelay(() -> Platform.getGuiPlatform().setCurrentScreen(OneConfigGui.create()), 1)); + INSTANCE = this; + } + + public static Preferences getInstance() { + return INSTANCE == null ? (INSTANCE = new Preferences()) : INSTANCE; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java index 4edff74..ab796c7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/ConfigCore.java @@ -40,11 +40,13 @@ public class ConfigCore { } public static void sortMods() { + ArrayList<Mod> mods = new ArrayList<>(ConfigCore.mods); ConfigCore.mods = mods.stream().filter((mod -> OneConfigConfig.favoriteMods.contains(mod.name))).sorted().collect(Collectors.toList()); mods.removeAll(ConfigCore.mods); ConfigCore.mods.addAll(mods.stream().filter(mod -> mod.modType != ModType.THIRD_PARTY).sorted().collect(Collectors.toList())); mods.removeAll(ConfigCore.mods); ConfigCore.mods.addAll(mods.stream().sorted().collect(Collectors.toList())); + OneConfigConfig.getInstance().save(); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java index dac0202..38e8406 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/gui/BlurHandler.java @@ -1,140 +1,8 @@ package cc.polyfrost.oneconfig.internal.gui; -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.RenderEvent; -import cc.polyfrost.oneconfig.events.event.ScreenOpenEvent; -import cc.polyfrost.oneconfig.events.event.Stage; -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.internal.config.Preferences; -import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor; -import cc.polyfrost.oneconfig.libs.universal.UMinecraft; -import cc.polyfrost.oneconfig.libs.universal.UScreen; -import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.shader.Shader; -import net.minecraft.client.shader.ShaderUniform; -import net.minecraft.util.ResourceLocation; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.util.ServiceLoader; -import java.util.List; - -/** - * An implementation of the BlurMC mod by tterrag1098. - * <p> - * For the original source see <a href="https://github.com/tterrag1098/Blur/blob/1.8.9/src/main/java/com/tterrag/blur/Blur.java">...</a> - * For the public license, see <a href="https://github.com/tterrag1098/Blur/blob/1.8.9/LICENSE">...</a> - * <p> - * License available under <a href="https://github.com/boomboompower/ToggleChat/blob/master/src/main/resources/licenses/BlurMC-License.txt">...</a> - * - * @author tterrag1098, boomboompower - * <p> - * Taken from ToggleChat - * <a href="https://github.com/boomboompower/ToggleChat/blob/master/LICENSE">...</a> - */ -public class BlurHandler { - public static BlurHandler INSTANCE = new BlurHandler(); - private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json"); - private final Logger logger = LogManager.getLogger("OneConfig - Blur"); - private long start; - private float progress = 0; - - /** - * Simply initializes the blur mod so events are properly handled by forge. - */ - public void load() { - EventManager.INSTANCE.register(this); - } - - @Subscribe - private void onGuiChange(ScreenOpenEvent event) { - reloadBlur(event.screen); - } - - @Subscribe - private void onRenderTick(RenderEvent event) { - if (event.stage != Stage.END) { - return; - } - - // Only blur on our own menus - if (UScreen.getCurrentScreen() == null) { - return; - } - - // Only update the shader if one is active - if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive()) { - return; - } - if (progress >= 5) return; - progress = getBlurStrengthProgress(); - - // This is hilariously bad, and could cause frame issues on low-end computers. - // Why is this being computed every tick? Surely there is a better way? - // This needs to be optimized. - try { - final List<Shader> listShaders = ((ShaderGroupAccessor) Minecraft.getMinecraft().entityRenderer.getShaderGroup()).getListShaders(); - - // Should not happen. Something bad happened. - if (listShaders == null) { - return; - } - - // Iterate through the list of shaders. - for (Shader shader : listShaders) { - ShaderUniform su = shader.getShaderManager().getShaderUniform("Progress"); - - if (su == null) { - continue; - } - - // All this for this. - su.set(progress); - } - } catch (IllegalArgumentException ex) { - this.logger.error("An error.png occurred while updating OneConfig's blur. Please report this!", ex); - } - } - - /** - * Activates/deactivates the blur in the current world if - * one of many conditions are met, such as no current other shader - * is being used, we actually have the blur setting enabled - */ - public void reloadBlur(GuiScreen gui) { - // Don't do anything if no world is loaded - if (UMinecraft.getWorld() == null) { - return; - } - - // If a shader is not already active and the UI is - // a one of ours, we should load our own blur! - if (!UMinecraft.getMinecraft().entityRenderer.isShaderActive() && gui instanceof OneConfigGui && Preferences.enableBlur) { - UMinecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); - - this.start = System.currentTimeMillis(); - this.progress = 0; - - // If a shader is active and the incoming UI is null or we have blur disabled, stop using the shader. - } else if (UMinecraft.getMinecraft().entityRenderer.isShaderActive() && (gui == null || !Preferences.enableBlur)) { - String name = UMinecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName(); - - // Only stop our specific blur ;) - if (!name.endsWith("fade_in_blur.json")) { - return; - } - - UMinecraft.getMinecraft().entityRenderer.stopUseShader(); - } - } - - /** - * Returns the strength of the blur as determined by the duration the effect of the blur. - * <p> - * The strength of the blur does not go below 5.0F. - */ - private float getBlurStrengthProgress() { - return Math.min((System.currentTimeMillis() - this.start) / 50F, 5.0F); - } +public interface BlurHandler { + BlurHandler INSTANCE = ServiceLoader.load(BlurHandler.class, BlurHandler.class.getClassLoader()).iterator().next(); + void reloadBlur(Object screen); } diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java index 86fdb1f..1f70815 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/init/OneConfigInit.java @@ -1,7 +1,5 @@ package cc.polyfrost.oneconfig.internal.init; -import net.minecraft.launchwrapper.Launch; -import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.Mixins; @SuppressWarnings("unused") diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java deleted file mode 100644 index 227b99e..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - - -import net.minecraft.client.gui.FontRenderer; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(FontRenderer.class) -public class FontRendererMixin { - - //@Inject(method = "renderDefaultChar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;bindTexture(Lnet/minecraft/util/ResourceLocation;)V", shift = At.Shift.AFTER)) - //public void whoAsked(int ch, boolean italic, CallbackInfoReturnable<Float> cir) { - // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - //} -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java deleted file mode 100644 index f08d37e..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/GuiIngameForgeMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.HudRenderEvent; -import net.minecraftforge.client.GuiIngameForge; -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; - -@Mixin(value = GuiIngameForge.class, remap = false) -public class GuiIngameForgeMixin { - @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;)V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onRenderGameOverlay(float partialTicks, CallbackInfo ci) { - EventManager.INSTANCE.post(new HudRenderEvent(partialTicks)); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java deleted file mode 100644 index 5fb40f8..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java +++ /dev/null @@ -1,98 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import cc.polyfrost.oneconfig.internal.OneConfig; -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.*; -import net.minecraft.client.Minecraft; -import net.minecraft.util.Timer; -import net.minecraftforge.client.event.GuiOpenEvent; -import net.minecraftforge.fml.common.eventhandler.Event; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Minecraft.class) -public class MinecraftMixin { - @Shadow - private Timer timer; - - @Inject(method = "shutdownMinecraftApplet", at = @At("HEAD")) - private void onShutdown(CallbackInfo ci) { - EventManager.INSTANCE.post(new PreShutdownEvent()); - } - - @Inject(method = "startGame", at = @At("HEAD")) - private void onStart(CallbackInfo ci) { - EventManager.INSTANCE.post(new StartEvent()); - Runtime.getRuntime().addShutdownHook(new Thread(() -> EventManager.INSTANCE.post(new ShutdownEvent()))); - } - - @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;beginMinecraftLoading(Lnet/minecraft/client/Minecraft;Ljava/util/List;Lnet/minecraft/client/resources/IReloadableResourceManager;)V", remap = false), remap = true) - private void onPreLaunch(CallbackInfo ci) { - OneConfig.preLaunch(); - } - - @Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/FMLClientHandler;onInitializationComplete()V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onInit(CallbackInfo ci) { - EventManager.INSTANCE.post(new InitializationEvent()); - OneConfig.init(); - } - - @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickStart(F)V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onRenderTickStart(CallbackInfo ci) { - EventManager.INSTANCE.post(new RenderEvent(Stage.START, timer.renderPartialTicks)); - } - - @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onRenderTickEnd(F)V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onRenderTickEnd(CallbackInfo ci) { - EventManager.INSTANCE.post(new RenderEvent(Stage.END, timer.renderPartialTicks)); - } - - @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPreClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onClientTickStart(CallbackInfo ci) { - EventManager.INSTANCE.post(new TickEvent(Stage.START)); - } - - @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;onPostClientTick()V", shift = At.Shift.AFTER, remap = false), remap = true) - private void onClientTickEnd(CallbackInfo ci) { - EventManager.INSTANCE.post(new TickEvent(Stage.END)); - } - - @ModifyArg(method = "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/EventBus;post(Lnet/minecraftforge/fml/common/eventhandler/Event;)Z", remap = false), remap = true) - private Event onGuiOpenEvent(Event a) { - if (a instanceof GuiOpenEvent) { - GuiOpenEvent forgeEvent = (GuiOpenEvent) a; - ScreenOpenEvent event = new ScreenOpenEvent(forgeEvent.gui); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - forgeEvent.setCanceled(true); - } - return forgeEvent; - } - return a; - } - - @Inject(method = "runGameLoop", at = @At(value = "FIELD", target = "Lnet/minecraft/util/Timer;renderPartialTicks:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER)) - private void onNonDeltaTickTimerUpdate(CallbackInfo ci) { - EventManager.INSTANCE.post(new TimerUpdateEvent(timer, false)); - } - - @Inject(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Timer;updateTimer()V", shift = At.Shift.AFTER, ordinal = 1)) - private void onDeltaTickTimerUpdate(CallbackInfo ci) { - EventManager.INSTANCE.post(new TimerUpdateEvent(timer, true)); - } - - @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;fireKeyInput()V")) - private void onKeyEvent(CallbackInfo ci) { - EventManager.INSTANCE.post(new KeyInputEvent()); - } - - @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/FMLCommonHandler;fireMouseInput()V")) - private void onMouseEvent(CallbackInfo ci) { - EventManager.INSTANCE.post(new MouseInputEvent()); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java deleted file mode 100644 index 877d540..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetHandlerPlayClientMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent; -import cc.polyfrost.oneconfig.events.event.SendPacketEvent; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S02PacketChat; -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; - -@Mixin(value = NetHandlerPlayClient.class, priority = Integer.MAX_VALUE) -public class NetHandlerPlayClientMixin { - - @Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true) - private void onSendPacket(Packet<?> p_147297_1_, CallbackInfo ci) { - SendPacketEvent event = new SendPacketEvent(p_147297_1_); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - ci.cancel(); - } - } - - @Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onClientChat(BLnet/minecraft/util/IChatComponent;)Lnet/minecraft/util/IChatComponent;", remap = false), cancellable = true, remap = true) - private void onClientChat(S02PacketChat packetIn, CallbackInfo ci) { - if (packetIn.getType() == 0) { - ChatReceiveEvent event = new ChatReceiveEvent(packetIn.getChatComponent()); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - ci.cancel(); - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java deleted file mode 100644 index 51988f2..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.ReceivePacketEvent; -import io.netty.channel.ChannelHandlerContext; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -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; - -@Mixin(value = NetworkManager.class, priority = Integer.MAX_VALUE) -public class NetworkManagerMixin { - @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true) - private void onReceivePacket(ChannelHandlerContext p_channelRead0_1_, Packet<?> p_channelRead0_2_, CallbackInfo ci) { - ReceivePacketEvent event = new ReceivePacketEvent(p_channelRead0_2_); - EventManager.INSTANCE.post(event); - if (event.isCancelled) { - ci.cancel(); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java deleted file mode 100644 index fe8c203..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import cc.polyfrost.oneconfig.internal.plugin.hooks.OptifineConfigHook; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Pseudo -@Mixin(targets = "Config", remap = false) -public class OptifineConfigMixin { - @Dynamic("OptiFine") - @Inject(method = "isFastRender", at = @At("HEAD"), cancellable = true) - private static void cancelFastRender(CallbackInfoReturnable<Boolean> cir) { - if (OptifineConfigHook.shouldNotApplyFastRender()) { - cir.setReturnValue(false); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ShaderGroupAccessor.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ShaderGroupAccessor.java deleted file mode 100644 index 8014670..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/ShaderGroupAccessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import net.minecraft.client.shader.Shader; -import net.minecraft.client.shader.ShaderGroup; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.List; - -@Mixin(ShaderGroup.class) -public interface ShaderGroupAccessor { - @Accessor("listShaders") - List<Shader> getListShaders(); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/VigilantMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/VigilantMixin.java deleted file mode 100644 index 662293c..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/VigilantMixin.java +++ /dev/null @@ -1,8 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import gg.essential.vigilance.Vigilant; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(Vigilant.class) -public class VigilantMixin { -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java deleted file mode 100644 index d1fce6a..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package cc.polyfrost.oneconfig.internal.mixin; - -import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.events.event.WorldLoadEvent; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.network.NetHandlerPlayClient; -import net.minecraft.profiler.Profiler; -import net.minecraft.world.EnumDifficulty; -import net.minecraft.world.WorldSettings; -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; - -@Mixin(WorldClient.class) -public class WorldClientMixin { - @Inject(method = "<init>", at = @At("RETURN")) - private void onWorldLoad(NetHandlerPlayClient p_i45063_1_, WorldSettings p_i45063_2_, int p_i45063_3_, EnumDifficulty p_i45063_4_, Profiler p_i45063_5_, CallbackInfo ci) { - EventManager.INSTANCE.post(new WorldLoadEvent()); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java deleted file mode 100644 index 52256ca..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java +++ /dev/null @@ -1,102 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.asm; - -import cc.polyfrost.oneconfig.internal.plugin.asm.tweakers.NanoVGGLConfigTransformer; -import cc.polyfrost.oneconfig.internal.plugin.asm.tweakers.VigilantTransformer; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import net.minecraft.launchwrapper.IClassTransformer; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.tree.ClassNode; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Collection; - -/** - * Taken from LWJGLTwoPointFive under The Unlicense - * <a href="https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/">https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/</a> - * <p>also half taken from asmworkspace by asbyth ty</p> - */ -@SuppressWarnings("unused") -public class ClassTransformer implements IClassTransformer { - private static final Logger logger = LogManager.getLogger("OneConfig ASM"); - private final Multimap<String, ITransformer> transformerMap = ArrayListMultimap.create(); - private static final boolean outputBytecode = Boolean.parseBoolean(System.getProperty("debugBytecode", "false")); - - public ClassTransformer() { - registerTransformer(new NanoVGGLConfigTransformer()); - registerTransformer(new VigilantTransformer()); - } - - private void registerTransformer(ITransformer transformer) { - // loop through names of classes - for (String cls : transformer.getClassName()) { - // put the classes into the transformer map - transformerMap.put(cls, transformer); - } - } - - @Override - public byte[] transform(String name, String transformedName, byte[] bytes) { - if (bytes == null) return null; - - Collection<ITransformer> transformers = transformerMap.get(transformedName); - if (transformers.isEmpty()) return bytes; - - ClassReader reader = new ClassReader(bytes); - ClassNode node = new ClassNode(); - reader.accept(node, ClassReader.EXPAND_FRAMES); - - for (ITransformer transformer : transformers) { - transformer.transform(transformedName, node); - } - - ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); - try { - node.accept(cw); - } catch (Throwable t) { - logger.error("Exception when transforming " + transformedName + " : " + t.getClass().getSimpleName()); - t.printStackTrace(); - } - - if (outputBytecode) { - File bytecodeDirectory = new File("bytecode"); - String transformedClassName; - - // anonymous classes - if (transformedName.contains("$")) { - transformedClassName = transformedName.replace('$', '.') + ".class"; - } else { - transformedClassName = transformedName + ".class"; - } - - if (!bytecodeDirectory.exists()) { - bytecodeDirectory.mkdirs(); - } - - File bytecodeOutput = new File(bytecodeDirectory, transformedClassName); - - try { - if (!bytecodeOutput.exists()) { - bytecodeOutput.createNewFile(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - try (FileOutputStream os = new FileOutputStream(bytecodeOutput)) { - // write to the generated class to /run/bytecode/classfile.class - // with the class bytes from transforming - os.write(cw.toByteArray()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - return cw.toByteArray(); - } -}
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ITransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ITransformer.java deleted file mode 100644 index 1bc50d1..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ITransformer.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.asm; - -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; - -public interface ITransformer { - String[] getClassName(); - - void transform(String transformedName, ClassNode node); - - default void clearInstructions(MethodNode methodNode) { - methodNode.instructions.clear(); - - // dont waste time clearing local variables if they're empty - if (!methodNode.localVariables.isEmpty()) { - methodNode.localVariables.clear(); - } - - // dont waste time clearing try-catches if they're empty - if (!methodNode.tryCatchBlocks.isEmpty()) { - methodNode.tryCatchBlocks.clear(); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java deleted file mode 100644 index d302b9d..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java +++ /dev/null @@ -1,117 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.asm; - -import cc.polyfrost.oneconfig.internal.init.OneConfigInit; -import net.minecraft.launchwrapper.ITweaker; -import net.minecraft.launchwrapper.Launch; -import net.minecraft.launchwrapper.LaunchClassLoader; -import net.minecraftforge.fml.relauncher.CoreModManager; -import org.spongepowered.asm.launch.MixinBootstrap; -import org.spongepowered.asm.launch.MixinTweaker; -import org.spongepowered.asm.mixin.Mixins; - -import java.io.File; -import java.lang.reflect.Field; -import java.net.URI; -import java.net.URL; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.jar.Attributes; -import java.util.jar.JarFile; - -public class OneConfigTweaker implements ITweaker { - - public OneConfigTweaker() { - for (URL url : Launch.classLoader.getSources()) { - doMagicMixinStuff(url); - } - } - - private void doMagicMixinStuff(URL url) { - try { - URI uri = url.toURI(); - if (Objects.equals(uri.getScheme(), "file")) { - File file = new File(uri); - if (file.exists() && file.isFile()) { - try (JarFile jarFile = new JarFile(file)) { - if (jarFile.getManifest() != null) { - Attributes attributes = jarFile.getManifest().getMainAttributes(); - String tweakerClass = attributes.getValue("TweakClass"); - if (Objects.equals(tweakerClass, "cc.polyfrost.oneconfigwrapper.OneConfigWrapper")) { - CoreModManager.getIgnoredMods().remove(file.getName()); - CoreModManager.getReparseableCoremods().add(file.getName()); - String mixinConfig = attributes.getValue("MixinConfigs"); - if (mixinConfig != null) { - try { - try { - List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses"); // tweak classes before other mod trolling - if (tweakClasses.contains("org.spongepowered.asm.launch.MixinTweaker")) { // if there's already a mixin tweaker, we'll just load it like "usual" - new MixinTweaker(); // also we might not need to make a new mixin tweawker all the time but im just making sure - } else if (!Launch.blackboard.containsKey("mixin.initialised")) { // if there isnt, we do our own trolling - List<ITweaker> tweaks = (List<ITweaker>) Launch.blackboard.get("Tweaks"); - tweaks.add(new MixinTweaker()); - } - } catch (Exception ignored) { - // if it fails i *think* we can just ignore it - } - MixinBootstrap.getPlatform().addContainer(uri); - } catch (Exception ignored) { - - } - } - } - } - } - } - } - } catch (Exception ignored) { - - } - } - - @Override - public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { - MixinBootstrap.init(); - boolean captureNext = false; - for (String arg : args) { - if (captureNext) { - Mixins.addConfiguration(arg); - } - captureNext = "--mixin".equals(arg); - } - } - - @Override - public void injectIntoClassLoader(LaunchClassLoader classLoader) { - removeLWJGLException(); - Launch.classLoader.registerTransformer(ClassTransformer.class.getName()); - OneConfigInit.initialize(new String[]{}); - Launch.blackboard.put("oneconfig.init.initialized", true); - Launch.classLoader.addClassLoaderExclusion("cc.polyfrost.oneconfig.internal.plugin.asm."); - } - - /** - * Taken from LWJGLTwoPointFive under The Unlicense - * <a href="https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/">https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/</a> - */ - private void removeLWJGLException() { - try { - Field f_exceptions = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions"); - f_exceptions.setAccessible(true); - Set<String> exceptions = (Set<String>) f_exceptions.get(Launch.classLoader); - exceptions.remove("org.lwjgl."); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public String getLaunchTarget() { - return null; - } - - @Override - public String[] getLaunchArguments() { - return new String[0]; - } -}
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java deleted file mode 100644 index bbbf4a1..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java +++ /dev/null @@ -1,47 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.asm.tweakers; - -import cc.polyfrost.oneconfig.internal.plugin.asm.ITransformer; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.*; - -/** - * Taken from LWJGLTwoPointFive under The Unlicense - * <a href="https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/">https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/</a> - */ -public class NanoVGGLConfigTransformer implements ITransformer { - @Override - public String[] getClassName() { - return new String[]{"org.lwjgl.nanovg.NanoVGGLConfig"}; - } - - @Override - public void transform(String transformedName, ClassNode node) { - for (MethodNode method : node.methods) { - if (method.name.equals("configGL")) { - InsnList list = new InsnList(); - - list.add(new VarInsnNode(Opcodes.LLOAD, 0)); - list.add(new TypeInsnNode(Opcodes.NEW, "cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider")); - list.add(new InsnNode(Opcodes.DUP)); - list.add(new MethodInsnNode( - Opcodes.INVOKESPECIAL, - "cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider", - "<init>", - "()V", - false - )); - list.add(new MethodInsnNode( - Opcodes.INVOKESTATIC, - "org/lwjgl/nanovg/NanoVGGLConfig", - "config", - "(JLorg/lwjgl/system/FunctionProvider;)V", - false - )); - list.add(new InsnNode(Opcodes.RETURN)); - - clearInstructions(method); - method.instructions.insert(list); - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java deleted file mode 100644 index 8dd60cf..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java +++ /dev/null @@ -1,89 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.asm.tweakers; - -import cc.polyfrost.oneconfig.internal.plugin.asm.ITransformer; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.*; - -import java.io.File; - -public class VigilantTransformer implements ITransformer { - - @Override - public String[] getClassName() { - return new String[]{"gg.essential.vigilance.Vigilant"}; - } - - /** - * If anything here is changed, edit the corresponding method in OneConfigMixinPlugin! - */ - @Override - public void transform(String transformedName, ClassNode node) { - if (!node.interfaces.contains("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor")) { - node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", null, null)); - node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "oneconfig$file", Type.getDescriptor(File.class), null, null)); - - node.interfaces.add("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor"); - MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null); - LabelNode labelNode = new LabelNode(); - methodNode.instructions.add(labelNode); - methodNode.instructions.add(new LineNumberNode(421421, labelNode)); - methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "propertyCollector", "Lgg/essential/vigilance/data/PropertyCollector;")); - methodNode.instructions.add(new InsnNode(Opcodes.ARETURN)); - node.methods.add(methodNode); - - MethodNode methodNode2 = new MethodNode(Opcodes.ACC_PUBLIC, "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", null, null); - LabelNode labelNode2 = new LabelNode(); - LabelNode labelNode3 = new LabelNode(); - LabelNode labelNode4 = new LabelNode(); - methodNode2.instructions.add(labelNode2); - methodNode2.instructions.add(new LineNumberNode(15636436, labelNode2)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - - methodNode2.instructions.add(new JumpInsnNode(Opcodes.IFNULL, labelNode4)); - - methodNode2.instructions.add(labelNode3); - methodNode2.instructions.add(new LineNumberNode(15636437, labelNode3)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); - methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); - methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2)); - methodNode2.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig", "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); - - methodNode2.instructions.add(labelNode4); - methodNode2.instructions.add(new LineNumberNode(15636438, labelNode4)); - methodNode2.instructions.add(new InsnNode(Opcodes.RETURN)); - node.methods.add(methodNode2); - - for (MethodNode method : node.methods) { - if (method.name.equals("initialize")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook", "returnNewConfig", "(Lgg/essential/vigilance/Vigilant;Ljava/io/File;)Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", false)); - list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } else if (method.name.equals("addDependency") && method.desc.equals("(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V")) { - InsnList list = new InsnList(); - - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new VarInsnNode(Opcodes.ALOAD, 2)); - list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "gg/essential/vigilance/Vigilant", "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); - - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } else if (method.name.equals("<init>") && method.desc.equals("(Ljava/io/File;Ljava/lang/String;Lgg/essential/vigilance/data/PropertyCollector;Lgg/essential/vigilance/data/SortingBehavior;)V")) { - InsnList list = new InsnList(); - list.add(new VarInsnNode(Opcodes.ALOAD, 0)); - list.add(new VarInsnNode(Opcodes.ALOAD, 1)); - list.add(new FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class))); - method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list); - } - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java deleted file mode 100644 index cf395ed..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java +++ /dev/null @@ -1,39 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.hooks; - -import org.lwjgl.opengl.GLContext; -import org.lwjgl.system.FunctionProvider; - -import java.lang.reflect.Method; -import java.nio.ByteBuffer; - -/** - * Taken from LWJGLTwoPointFive under The Unlicense - * <a href="https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/">https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/</a> - */ -public class Lwjgl2FunctionProvider implements FunctionProvider { - - private final Method m_getFunctionAddress; - - public Lwjgl2FunctionProvider() { - try { - m_getFunctionAddress = GLContext.class.getDeclaredMethod("getFunctionAddress", String.class); - m_getFunctionAddress.setAccessible(true); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public long getFunctionAddress(CharSequence functionName) { - try { - return (long) m_getFunctionAddress.invoke(null, functionName.toString()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public long getFunctionAddress(ByteBuffer byteBuffer) { - throw new UnsupportedOperationException(); - } -}
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java deleted file mode 100644 index bf8d675..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java +++ /dev/null @@ -1,23 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.hooks; - -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.libs.universal.UScreen; -import cc.polyfrost.oneconfig.utils.gui.GuiUtils; -import net.minecraft.client.gui.GuiScreen; - -import java.util.Optional; - -public class OptifineConfigHook { - - public static boolean shouldNotApplyFastRender() { - if (UScreen.getCurrentScreen() instanceof OneConfigGui) { - return true; - } - for (Optional<GuiScreen> screen : GuiUtils.getScreenQueue()) { - if (screen.isPresent() && screen.get() instanceof OneConfigGui) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java deleted file mode 100644 index 7b66435..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java +++ /dev/null @@ -1,27 +0,0 @@ -package cc.polyfrost.oneconfig.internal.plugin.hooks; - -import cc.polyfrost.oneconfig.config.compatibility.vigilance.VigilanceConfig; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.ModType; -import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; -import gg.essential.vigilance.Vigilant; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.Loader; - -import java.io.File; - -@SuppressWarnings("unused") -public class VigilantHook { - public static VigilanceConfig returnNewConfig(Vigilant vigilant, File file) { - if (vigilant != null && Minecraft.getMinecraft().isCallingFromMinecraftThread()) { - String name = !vigilant.getGuiTitle().equals("Settings") ? vigilant.getGuiTitle() : Loader.instance().activeModContainer() == null ? "Unknown" : Loader.instance().activeModContainer().getName(); - if (name.equals("OneConfig")) name = "Essential"; - String finalName = name; - // duplicate fix - if (ConfigCore.mods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null; - return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant); - } else { - return null; - } - } -} |