aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-18 00:12:38 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-06-18 00:12:38 +0700
commitd0c8b1f7c7792f5f00d5870d9f980d0101007592 (patch)
tree19337b071103dfe5505115db18282bfd2eaa40c6 /src/main/java/cc/polyfrost
parent4db4afb9156edfd7d5485f80e18739d205e23d27 (diff)
downloadOneConfig-d0c8b1f7c7792f5f00d5870d9f980d0101007592.tar.gz
OneConfig-d0c8b1f7c7792f5f00d5870d9f980d0101007592.tar.bz2
OneConfig-d0c8b1f7c7792f5f00d5870d9f980d0101007592.zip
migrate to tweaker
Diffstat (limited to 'src/main/java/cc/polyfrost')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java56
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java108
2 files changed, 108 insertions, 56 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java
deleted file mode 100644
index cdd0d83..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java
+++ /dev/null
@@ -1,56 +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.Launch;
-import net.minecraft.launchwrapper.LaunchClassLoader;
-import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
-
-import java.lang.reflect.Field;
-import java.util.Map;
-import java.util.Set;
-
-public class LoadingPlugin implements IFMLLoadingPlugin {
-
- /**
- * 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 LoadingPlugin() {
- 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.");
- OneConfigInit.initialize(new String[]{});
- Launch.blackboard.put("oneconfig.init.initialized", true);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public String[] getASMTransformerClass() {
- Launch.blackboard.put("oneconfig.init.registered_transformer", true);
- return new String[]{ClassTransformer.class.getName()};
- }
-
- @Override
- public String getModContainerClass() {
- return null;
- }
-
- @Override
- public String getSetupClass() {
- return null;
- }
-
- @Override
- public void injectData(Map<String, Object> data) {
- }
-
- @Override
- public String getAccessTransformerClass() {
- return null;
- }
-} \ No newline at end of file
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java
new file mode 100644
index 0000000..0a709f6
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java
@@ -0,0 +1,108 @@
+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() {
+ doMagicMixinStuff();
+ }
+
+ private void doMagicMixinStuff() {
+ for (URL url : Launch.classLoader.getSources()) {
+ try {
+ URI uri = url.toURI();
+ if (Objects.equals(uri.getScheme(), "file")) {
+ File file = new File(uri);
+ if (file.exists() && file.isFile()) {
+ 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<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) {
+
+ }
+
+ @Override
+ public void injectIntoClassLoader(LaunchClassLoader classLoader) {
+ removeLWJGLException();
+ Launch.classLoader.registerTransformer(ClassTransformer.class.getName());
+ }
+
+ /**
+ * 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.");
+ 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