From 11233411826a5c92d18b175b224eff992b90af3f Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sat, 23 May 2020 20:06:18 +0200 Subject: [PATCH] Fix RM not loading another mod loads mixin first (fixes #181) --- .../com/replaymod/core/LoadingPlugin.java | 7 ++- .../core/tweaker/ReplayModTweaker.java | 62 +++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/replaymod/core/LoadingPlugin.java b/src/main/java/com/replaymod/core/LoadingPlugin.java index 35f3d178..b8f2c690 100644 --- a/src/main/java/com/replaymod/core/LoadingPlugin.java +++ b/src/main/java/com/replaymod/core/LoadingPlugin.java @@ -1,6 +1,7 @@ package com.replaymod.core; //#if MC<11400 +//$$ import net.minecraft.launchwrapper.Launch; //$$ import org.apache.logging.log4j.LogManager; //$$ import org.spongepowered.asm.launch.MixinBootstrap; //$$ import org.spongepowered.asm.mixin.Mixins; @@ -25,7 +26,11 @@ package com.replaymod.core; //$$ public class LoadingPlugin implements IFMLLoadingPlugin { //$$ //$$ public LoadingPlugin() { -//$$ MixinBootstrap.init(); +//$$ if ((Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment")) { +//$$ // Outside of the dev env, this is the job of the tweaker +//$$ MixinBootstrap.init(); +//$$ } +//$$ //$$ Mixins.addConfiguration("mixins.core.replaymod.json"); //$$ Mixins.addConfiguration("mixins.recording.replaymod.json"); //$$ Mixins.addConfiguration("mixins.render.replaymod.json"); diff --git a/src/main/java/com/replaymod/core/tweaker/ReplayModTweaker.java b/src/main/java/com/replaymod/core/tweaker/ReplayModTweaker.java index d08c7bdf..403ead3d 100644 --- a/src/main/java/com/replaymod/core/tweaker/ReplayModTweaker.java +++ b/src/main/java/com/replaymod/core/tweaker/ReplayModTweaker.java @@ -10,21 +10,75 @@ //$$ import net.minecraft.launchwrapper.ITweaker; //$$ import net.minecraft.launchwrapper.Launch; //$$ import net.minecraft.launchwrapper.LaunchClassLoader; +//$$ import org.spongepowered.asm.launch.GlobalProperties; +//$$ import org.spongepowered.asm.launch.MixinBootstrap; +//$$ import org.spongepowered.asm.launch.platform.MixinPlatformManager; //$$ //$$ import java.io.File; +//$$ import java.net.URI; +//$$ import java.net.URISyntaxException; //$$ import java.util.List; //$$ +//#if MC>=11200 +//$$ import org.spongepowered.asm.launch.platform.container.ContainerHandleURI; +//#endif +//$$ //$$ public class ReplayModTweaker implements ITweaker { +//$$ +//$$ private static final String MIXIN_TWEAKER = "org.spongepowered.asm.launch.MixinTweaker"; +//$$ +//$$ public ReplayModTweaker() { +//$$ injectMixinTweaker(); +//$$ } +//$$ +//$$ private void injectMixinTweaker() { +//$$ @SuppressWarnings("unchecked") +//$$ List tweakClasses = (List) Launch.blackboard.get("TweakClasses"); +//$$ +//$$ // If the MixinTweaker is already queued (because of another mod), then there's nothing we need to to +//$$ if (tweakClasses.contains(MIXIN_TWEAKER)) { +//$$ return; +//$$ } +//$$ +//$$ // If it is already booted, we're also good to go +//$$ if (GlobalProperties.get(GlobalProperties.Keys.INIT) != null) { +//$$ return; +//$$ } +//$$ +//$$ System.out.println("Injecting MixinTweaker from ReplayModTweaker"); +//$$ +//$$ // Otherwise, we need to take things into our own hands because the normal way to chainload a tweaker +//$$ // (by adding it to the TweakClasses list during injectIntoClassLoader) is too late for Mixin. +//$$ // Instead we instantiate the MixinTweaker on our own and add it to the current Tweaks list immediately. +//$$ Launch.classLoader.addClassLoaderExclusion(MIXIN_TWEAKER.substring(0, MIXIN_TWEAKER.lastIndexOf('.'))); +//$$ @SuppressWarnings("unchecked") +//$$ List tweaks = (List) Launch.blackboard.get("Tweaks"); +//$$ try { +//$$ tweaks.add((ITweaker) Class.forName(MIXIN_TWEAKER, true, Launch.classLoader).newInstance()); +//$$ } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { +//$$ throw new RuntimeException(e); +//$$ } +//$$ } +//$$ //$$ @Override //$$ public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { //$$ } //$$ //$$ @Override //$$ public void injectIntoClassLoader(LaunchClassLoader classLoader) { -//$$ // Inject Mixin's tweaker (cause you can only specify one tweaker in the manifest) -//$$ @SuppressWarnings("unchecked") -//$$ List tweakClasses = (List) Launch.blackboard.get("TweakClasses"); -//$$ tweakClasses.add("org.spongepowered.asm.launch.MixinTweaker"); +//$$ // Add our jar as a Mixin container (cause normally Mixin detects those via the TweakClass manifest entry) +//$$ URI uri; +//$$ try { +//$$ uri = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI(); +//$$ } catch (URISyntaxException e) { +//$$ throw new RuntimeException(e); +//$$ } +//$$ MixinPlatformManager platform = MixinBootstrap.getPlatform(); + //#if MC>=11200 + //$$ platform.addContainer(new ContainerHandleURI(uri)); + //#else + //$$ platform.addContainer(uri); + //#endif //$$ //#if MC>=11202 && MC<=11202 //$$ initModCore("1.12.2");