aboutsummaryrefslogtreecommitdiff
path: root/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-07-05 23:39:40 +0900
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-07-05 23:39:40 +0900
commitd3f5df5e56d27394b6e1e246e4114a8f40236b60 (patch)
treef5952503eb3bc095914f4f77b81531ab2c050d90 /versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin
parent6cafd268d486a930c7e8bec229c30eb6a50fe436 (diff)
parent54d915940ee0856bc7cac4a37687cb7783e07cee (diff)
downloadOneConfig-d3f5df5e56d27394b6e1e246e4114a8f40236b60.tar.gz
OneConfig-d3f5df5e56d27394b6e1e246e4114a8f40236b60.tar.bz2
OneConfig-d3f5df5e56d27394b6e1e246e4114a8f40236b60.zip
Merge branch 'nextdaydelivery-self'
Diffstat (limited to 'versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin')
-rw-r--r--versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java140
-rw-r--r--versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java5
-rw-r--r--versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java4
3 files changed, 146 insertions, 3 deletions
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
new file mode 100644
index 0000000..0063d1b
--- /dev/null
+++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java
@@ -0,0 +1,140 @@
+package cc.polyfrost.oneconfig.internal.plugin;
+
+import cc.polyfrost.oneconfig.platform.Platform;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
+import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class OneConfigMixinPlugin implements IMixinConfigPlugin {
+ private static boolean isVigilance = false;
+
+ @Override
+ public void onLoad(String mixinPackage) {
+ try {
+ Class.forName("gg.essential.vigilance.Vigilant");
+ isVigilance = true;
+ } catch (Exception e) {
+ isVigilance = false;
+ }
+ }
+
+ @Override
+ public String getRefMapperConfig() {
+ return null;
+ }
+
+ @Override
+ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
+ return !targetClassName.contains("vigilance") || isVigilance;
+ }
+
+ @Override
+ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
+
+ }
+
+ @Override
+ public List<String> getMixins() {
+ if (Platform.getInstance().getMinecraftVersion() >= 11600) {
+ ArrayList<String> mixins = new ArrayList<>();
+ mixins.add("ClientModLoaderMixin");
+ mixins.add("KeyboardListenerMixin");
+ mixins.add("MouseHelperAccessor");
+ mixins.add("MouseHelperMixin");
+ mixins.add("TimeTrackerMixin");
+ return mixins;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void preApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+
+ }
+
+ @Override
+ public void postApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+ if (mixinClassName.equals("cc.polyfrost.oneconfig.internal.mixin.VigilantMixin")) {
+ transform(targetClass);
+ }
+ }
+
+ /**
+ * If anything here is changed, edit the corresponding method in OneConfigMixinPlugin!
+ */
+ private void transform(org.spongepowered.asm.lib.tree.ClassNode node) {
+ if (!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", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", 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", "Lgg/essential/vigilance/data/PropertyCollector;"));
+ 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", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;"));
+
+ 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", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;"));
+ 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, "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 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, "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 org.spongepowered.asm.lib.tree.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")) {
+ 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);
+ }
+ }
+ }
+ }
+}
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java
index 52256ca..bbd47ac 100644
--- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java
+++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/ClassTransformer.java
@@ -1,3 +1,4 @@
+//#if MC<=11202
package cc.polyfrost.oneconfig.internal.plugin.asm;
import cc.polyfrost.oneconfig.internal.plugin.asm.tweakers.NanoVGGLConfigTransformer;
@@ -39,7 +40,6 @@ public class ClassTransformer implements IClassTransformer {
transformerMap.put(cls, transformer);
}
}
-
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (bytes == null) return null;
@@ -99,4 +99,5 @@ public class ClassTransformer implements IClassTransformer {
return cw.toByteArray();
}
-} \ No newline at end of file
+}
+//#endif \ No newline at end of file
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
index d302b9d..b1f3eb2 100644
--- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
+++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/OneConfigTweaker.java
@@ -1,3 +1,4 @@
+//#if MC<=11202
package cc.polyfrost.oneconfig.internal.plugin.asm;
import cc.polyfrost.oneconfig.internal.init.OneConfigInit;
@@ -114,4 +115,5 @@ public class OneConfigTweaker implements ITweaker {
public String[] getLaunchArguments() {
return new String[0];
}
-} \ No newline at end of file
+}
+//#endif \ No newline at end of file