From bda6a119108d238e3c7d85e82f37f5d6da3b9b5e Mon Sep 17 00:00:00 2001
From: Wyvest <45589059+Wyvest@users.noreply.github.com>
Date: Sun, 19 Jun 2022 21:03:59 +0700
Subject: use ITweakers properly move hooks out of transformers
---
.../internal/mixin/OptifineConfigMixin.java | 2 +-
.../internal/plugin/Lwjgl2FunctionProvider.java | 39 -------
.../internal/plugin/OneConfigMixinPlugin.java | 80 ++++++++++++++-
.../internal/plugin/OneConfigTweaker.java | 109 --------------------
.../internal/plugin/OptifineConfigHook.java | 23 -----
.../internal/plugin/asm/OneConfigTweaker.java | 109 ++++++++++++++++++++
.../asm/tweakers/NanoVGGLConfigTransformer.java | 8 +-
.../plugin/asm/tweakers/VigilantTransformer.java | 114 ++-------------------
.../plugin/hooks/Lwjgl2FunctionProvider.java | 39 +++++++
.../internal/plugin/hooks/OptifineConfigHook.java | 23 +++++
.../internal/plugin/hooks/VigilantHook.java | 27 +++++
11 files changed, 293 insertions(+), 280 deletions(-)
delete mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java
delete mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java
delete mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/OptifineConfigHook.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java
create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java
(limited to 'src/main/java')
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java
index bc1d400..fe8c203 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java
@@ -1,6 +1,6 @@
package cc.polyfrost.oneconfig.internal.mixin;
-import cc.polyfrost.oneconfig.internal.plugin.OptifineConfigHook;
+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;
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java
deleted file mode 100644
index 105afa2..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package cc.polyfrost.oneconfig.internal.plugin;
-
-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
- * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
- */
-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/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
index 1e0d432..0ef2c58 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
@@ -1,10 +1,12 @@
package cc.polyfrost.oneconfig.internal.plugin;
-import cc.polyfrost.oneconfig.internal.plugin.asm.tweakers.VigilantTransformer;
-import org.spongepowered.asm.lib.tree.ClassNode;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.spongepowered.asm.lib.tree.*;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+import java.io.File;
import java.util.List;
import java.util.Set;
@@ -49,7 +51,79 @@ public class OneConfigMixinPlugin implements IMixinConfigPlugin {
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
if (mixinClassName.equals("cc.polyfrost.oneconfig.internal.mixin.VigilantMixin")) {
- VigilantTransformer.transform(targetClass);
+ transform(targetClass);
+ }
+ }
+
+ /**
+ * If anything here is changed, edit the corresponding method in OneConfigMixinPlugin!
+ */
+ private void transform(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("") && 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/OneConfigTweaker.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java
deleted file mode 100644
index 5c57ca7..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package cc.polyfrost.oneconfig.internal.plugin;
-
-import cc.polyfrost.oneconfig.internal.init.OneConfigInit;
-import cc.polyfrost.oneconfig.internal.plugin.asm.ClassTransformer;
-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 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")) {
- String mixinConfig = attributes.getValue("MixinConfigs");
- CoreModManager.getIgnoredMods().remove(file.getName());
- CoreModManager.getReparseableCoremods().add(file.getName());
- if (mixinConfig != null) {
- try {
- try {
- List tweakClasses = (List) 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 tweaks = (List) 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 args, File gameDir, File assetsDir, String profile) {
-
- }
-
- @Override
- public void injectIntoClassLoader(LaunchClassLoader classLoader) {
- removeLWJGLException();
- Launch.classLoader.registerTransformer(ClassTransformer.class.getName());
- }
-
- /**
- * Taken from LWJGLTwoPointFive under The Unlicense
- * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
- */
- private void removeLWJGLException() {
- try {
- Field f_exceptions = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions");
- f_exceptions.setAccessible(true);
- Set exceptions = (Set) f_exceptions.get(Launch.classLoader);
- exceptions.remove("org.lwjgl.");
- OneConfigInit.initialize(new String[]{});
- Launch.blackboard.put("oneconfig.init.initialized", true);
- } 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/OptifineConfigHook.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OptifineConfigHook.java
deleted file mode 100644
index 69d1f2e..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OptifineConfigHook.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package cc.polyfrost.oneconfig.internal.plugin;
-
-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 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/asm/OneConfigTweaker.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
new file mode 100644
index 0000000..49a0197
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
@@ -0,0 +1,109 @@
+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 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 tweakClasses = (List) 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 tweaks = (List) 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 args, File gameDir, File assetsDir, String profile) {
+
+ }
+
+ @Override
+ public void injectIntoClassLoader(LaunchClassLoader classLoader) {
+ removeLWJGLException();
+ Launch.classLoader.registerTransformer(ClassTransformer.class.getName());
+ Launch.classLoader.addClassLoaderExclusion("cc.polyfrost.oneconfig.internal.plugin.asm.");
+ }
+
+ /**
+ * Taken from LWJGLTwoPointFive under The Unlicense
+ * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
+ */
+ private void removeLWJGLException() {
+ try {
+ Field f_exceptions = LaunchClassLoader.class.getDeclaredField("classLoaderExceptions");
+ f_exceptions.setAccessible(true);
+ Set exceptions = (Set) f_exceptions.get(Launch.classLoader);
+ exceptions.remove("org.lwjgl.");
+ OneConfigInit.initialize(new String[]{});
+ Launch.blackboard.put("oneconfig.init.initialized", true);
+ } 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
index 2410f4b..bbbf4a1 100644
--- 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
@@ -4,6 +4,10 @@ import cc.polyfrost.oneconfig.internal.plugin.asm.ITransformer;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
+/**
+ * Taken from LWJGLTwoPointFive under The Unlicense
+ * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
+ */
public class NanoVGGLConfigTransformer implements ITransformer {
@Override
public String[] getClassName() {
@@ -17,11 +21,11 @@ public class NanoVGGLConfigTransformer implements ITransformer {
InsnList list = new InsnList();
list.add(new VarInsnNode(Opcodes.LLOAD, 0));
- list.add(new TypeInsnNode(Opcodes.NEW, "cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider"));
+ 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/Lwjgl2FunctionProvider",
+ "cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider",
"",
"()V",
false
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
index bc87e4c..8dd60cf 100644
--- 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
@@ -1,14 +1,6 @@
package cc.polyfrost.oneconfig.internal.plugin.asm.tweakers;
-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 cc.polyfrost.oneconfig.internal.plugin.asm.ITransformer;
-import gg.essential.vigilance.Vigilant;
-import gg.essential.vigilance.data.PropertyCollector;
-import net.minecraft.client.Minecraft;
-import net.minecraftforge.fml.common.Loader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
@@ -16,31 +8,19 @@ import org.objectweb.asm.tree.*;
import java.io.File;
public class VigilantTransformer implements ITransformer {
- private static boolean didASM = false;
- private static boolean didMixin = false;
- @SuppressWarnings("unused")
- 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.oneConfigMods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null;
- return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant);
- } else {
- return null;
- }
- }
@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 (!didMixin && !node.interfaces.contains("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor")) {
- node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", Type.getDescriptor(VigilanceConfig.class), null, null));
+ 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");
@@ -49,7 +29,7 @@ public class VigilantTransformer implements ITransformer {
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", Type.getDescriptor(PropertyCollector.class)));
+ 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);
@@ -60,17 +40,17 @@ public class VigilantTransformer implements ITransformer {
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", Type.getDescriptor(VigilanceConfig.class)));
+ 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", Type.getDescriptor(VigilanceConfig.class)));
+ 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, Type.getInternalName(VigilanceConfig.class), "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false));
+ 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));
@@ -84,8 +64,8 @@ public class VigilantTransformer implements ITransformer {
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, Type.getInternalName(getClass()), "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", Type.getDescriptor(VigilanceConfig.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();
@@ -104,78 +84,6 @@ public class VigilantTransformer implements ITransformer {
method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list);
}
}
- didASM = true;
- }
- }
-
- // this is the method above but using spongemixin's stupid relocate asm and static
- public static void transform(org.spongepowered.asm.lib.tree.ClassNode node) {
- if (!didASM && !node.interfaces.contains("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor")) {
- node.fields.add(new org.spongepowered.asm.lib.tree.FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", Type.getDescriptor(VigilanceConfig.class), null, null));
- node.fields.add(new org.spongepowered.asm.lib.tree.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");
- org.spongepowered.asm.lib.tree.MethodNode methodNode = new org.spongepowered.asm.lib.tree.MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null);
- org.spongepowered.asm.lib.tree.LabelNode labelNode = new org.spongepowered.asm.lib.tree.LabelNode();
- methodNode.instructions.add(labelNode);
- methodNode.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(421421, labelNode));
- methodNode.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- methodNode.instructions.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "propertyCollector", Type.getDescriptor(PropertyCollector.class)));
- methodNode.instructions.add(new org.spongepowered.asm.lib.tree.InsnNode(Opcodes.ARETURN));
- node.methods.add(methodNode);
-
- org.spongepowered.asm.lib.tree.MethodNode methodNode2 = new org.spongepowered.asm.lib.tree.MethodNode(Opcodes.ACC_PUBLIC, "handleOneConfigDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", null, null);
- org.spongepowered.asm.lib.tree.LabelNode labelNode2 = new org.spongepowered.asm.lib.tree.LabelNode();
- org.spongepowered.asm.lib.tree.LabelNode labelNode3 = new org.spongepowered.asm.lib.tree.LabelNode();
- org.spongepowered.asm.lib.tree.LabelNode labelNode4 = new org.spongepowered.asm.lib.tree.LabelNode();
- methodNode2.instructions.add(labelNode2);
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(15636436, labelNode2));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class)));
-
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.JumpInsnNode(Opcodes.IFNULL, labelNode4));
-
- methodNode2.instructions.add(labelNode3);
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(15636437, labelNode3));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class)));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 1));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 2));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(VigilanceConfig.class), "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false));
-
- methodNode2.instructions.add(labelNode4);
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.LineNumberNode(15636438, labelNode4));
- methodNode2.instructions.add(new org.spongepowered.asm.lib.tree.InsnNode(Opcodes.RETURN));
- node.methods.add(methodNode2);
-
- for (org.spongepowered.asm.lib.tree.MethodNode method : node.methods) {
- if (method.name.equals("initialize")) {
- org.spongepowered.asm.lib.tree.InsnList list = new org.spongepowered.asm.lib.tree.InsnList();
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- list.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class)));
- list.add(new org.spongepowered.asm.lib.tree.MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(VigilantTransformer.class), "returnNewConfig", "(Lgg/essential/vigilance/Vigilant;Ljava/io/File;)Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", false));
- list.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", Type.getDescriptor(VigilanceConfig.class)));
- 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")) {
- org.spongepowered.asm.lib.tree.InsnList list = new org.spongepowered.asm.lib.tree.InsnList();
-
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 1));
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 2));
- list.add(new org.spongepowered.asm.lib.tree.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("") && method.desc.equals("(Ljava/io/File;Ljava/lang/String;Lgg/essential/vigilance/data/PropertyCollector;Lgg/essential/vigilance/data/SortingBehavior;)V")) {
- org.spongepowered.asm.lib.tree.InsnList list = new org.spongepowered.asm.lib.tree.InsnList();
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 0));
- list.add(new org.spongepowered.asm.lib.tree.VarInsnNode(Opcodes.ALOAD, 1));
- list.add(new org.spongepowered.asm.lib.tree.FieldInsnNode(Opcodes.PUTFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$file", Type.getDescriptor(File.class)));
- method.instructions.insertBefore(method.instructions.getLast().getPrevious(), list);
- }
- }
- didMixin = true;
}
}
}
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
new file mode 100644
index 0000000..cf395ed
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java
@@ -0,0 +1,39 @@
+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
+ * https://github.com/DJtheRedstoner/LWJGLTwoPointFive/blob/master/LICENSE/
+ */
+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
new file mode 100644
index 0000000..bf8d675
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java
@@ -0,0 +1,23 @@
+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 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
new file mode 100644
index 0000000..59aebca
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java
@@ -0,0 +1,27 @@
+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.oneConfigMods.stream().anyMatch(mod -> mod.name.equals(finalName))) return null;
+ return new VigilanceConfig(new Mod(name, ModType.THIRD_PARTY), file.getAbsolutePath(), vigilant);
+ } else {
+ return null;
+ }
+ }
+}
--
cgit