aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-19 21:03:59 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-19 21:03:59 +0700
commitbda6a119108d238e3c7d85e82f37f5d6da3b9b5e (patch)
treee8c0fbc71689294506a99e3e1f119abe88724211 /src/main/java/cc/polyfrost/oneconfig
parentbb6f1318a8d8f4b11c0648304317f4bf02c0f85c (diff)
downloadOneConfig-bda6a119108d238e3c7d85e82f37f5d6da3b9b5e.tar.gz
OneConfig-bda6a119108d238e3c7d85e82f37f5d6da3b9b5e.tar.bz2
OneConfig-bda6a119108d238e3c7d85e82f37f5d6da3b9b5e.zip
use ITweakers properly
move hooks out of transformers
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/mixin/OptifineConfigMixin.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java80
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java (renamed from src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java)6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/NanoVGGLConfigTransformer.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java114
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java (renamed from src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java)2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java (renamed from src/main/java/cc/polyfrost/oneconfig/internal/plugin/OptifineConfigHook.java)2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/VigilantHook.java27
8 files changed, 127 insertions, 114 deletions
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/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("<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/OneConfigTweaker.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
index 5c57ca7..49a0197 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
@@ -1,7 +1,6 @@
-package cc.polyfrost.oneconfig.internal.plugin;
+package cc.polyfrost.oneconfig.internal.plugin.asm;
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;
@@ -38,9 +37,9 @@ public class OneConfigTweaker implements ITweaker {
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());
+ String mixinConfig = attributes.getValue("MixinConfigs");
if (mixinConfig != null) {
try {
try {
@@ -78,6 +77,7 @@ public class OneConfigTweaker implements ITweaker {
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
removeLWJGLException();
Launch.classLoader.registerTransformer(ClassTransformer.class.getName());
+ Launch.classLoader.addClassLoaderExclusion("cc.polyfrost.oneconfig.internal.plugin.asm.");
}
/**
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
+ * <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() {
@@ -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",
"<init>",
"()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("<init>") && 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/Lwjgl2FunctionProvider.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java
index 105afa2..cf395ed 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/Lwjgl2FunctionProvider.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/Lwjgl2FunctionProvider.java
@@ -1,4 +1,4 @@
-package cc.polyfrost.oneconfig.internal.plugin;
+package cc.polyfrost.oneconfig.internal.plugin.hooks;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.system.FunctionProvider;
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OptifineConfigHook.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java
index 69d1f2e..bf8d675 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OptifineConfigHook.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java
@@ -1,4 +1,4 @@
-package cc.polyfrost.oneconfig.internal.plugin;
+package cc.polyfrost.oneconfig.internal.plugin.hooks;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.libs.universal.UScreen;
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;
+ }
+ }
+}