diff options
-rw-r--r-- | build.gradle.kts | 6 | ||||
-rw-r--r-- | gradle.properties | 2 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/internal/plugin/LoadingPlugin.java | 56 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigTweaker.java | 108 |
4 files changed, 111 insertions, 61 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 8f0aa55..fdcca6b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -45,7 +45,7 @@ loom { noServerRunConfigs() if (project.platform.isLegacyForge) { launchConfigs.named("client") { - property("fml.coreMods.load", "cc.polyfrost.oneconfig.internal.plugin.LoadingPlugin") + arg("--tweakClass", "cc.polyfrost.oneconfig.internal.plugin.OneConfigTweaker") property("mixin.debug.export", "true") property("debugBytecode", "true") } @@ -238,9 +238,7 @@ tasks { "ForceLoadAsMod" to true, "TweakOrder" to "0", "MixinConfigs" to "mixins.oneconfig.json", - "TweakClass" to "org.spongepowered.asm.launch.MixinTweaker", - //"FMLCorePlugin" to "cc.polyfrost.oneconfig.internal.plugin.LoadingPlugin", - "FMLCorePluginContainsFMLMod" to "lol" + "TweakClass" to "cc.polyfrost.oneconfig.internal.plugin.OneConfigTweaker" ) ) } diff --git a/gradle.properties b/gradle.properties index 861707a..0d0e8da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ mod_name = OneConfig mod_id = oneconfig -mod_version = 0.1.0-alpha16 +mod_version = 0.1.0-alpha17 essential.defaults.loom=0 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 |