diff --git a/dependencies.gradle b/dependencies.gradle index 41e9015a..3d7c3b2a 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -8,7 +8,7 @@ def addGtForTesting = Boolean.parseBoolean(project.getProperties().getOrDefault( def addReikaModsForTesting = Boolean.parseBoolean(project.getProperties().getOrDefault("withReikaMods", "false")) def asmVersion = '9.6' -def rfbVersion = '0.3.6' +def rfbVersion = '0.3.7' // 100% binary compatible, 1 minor source compatibility issue (removed a throws IOException clause) def gsonVersion = '2.10.1' diff --git a/src/main/java/me/eigenraven/lwjgl3ify/relauncher/Lwjgl3ifyRelauncherTweaker.java b/src/main/java/me/eigenraven/lwjgl3ify/relauncher/Lwjgl3ifyRelauncherTweaker.java index ac314fd9..7f3daa1a 100644 --- a/src/main/java/me/eigenraven/lwjgl3ify/relauncher/Lwjgl3ifyRelauncherTweaker.java +++ b/src/main/java/me/eigenraven/lwjgl3ify/relauncher/Lwjgl3ifyRelauncherTweaker.java @@ -2,9 +2,8 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Paths; import java.util.List; @@ -21,30 +20,52 @@ public class Lwjgl3ifyRelauncherTweaker implements ITweaker { - @SuppressWarnings("unchecked") - public Lwjgl3ifyRelauncherTweaker() throws ReflectiveOperationException, MalformedURLException, URISyntaxException { - URL mySrc = Lwjgl3ifyRelauncherTweaker.class.getProtectionDomain() - .getCodeSource() - .getLocation(); - while (mySrc.getProtocol() - .equals("jar")) { - final String all = mySrc.toString(); - mySrc = new URL(all.substring("jar:".length(), all.lastIndexOf('!'))); + private static boolean coremodInjected = false; + + public Lwjgl3ifyRelauncherTweaker() { + // Load early in prod, late in dev to avoid a crash + if (FMLLaunchHandler.side() != null) { + injectMyCoremod(); } - File myFile = new File("."); - if (mySrc.getProtocol() - .equals("file")) { - myFile = Paths.get(myFile.toURI()) - .toFile(); + } + + private void injectMyCoremod() { + if (coremodInjected) { + return; + } + try { + URL mySrc = Lwjgl3ifyRelauncherTweaker.class.getProtectionDomain() + .getCodeSource() + .getLocation(); + while (mySrc.getProtocol() + .equals("jar")) { + final String all = mySrc.toString(); + mySrc = new URL(all.substring("jar:".length(), all.lastIndexOf('!'))); + } + File myFile = new File("."); + if (mySrc.getProtocol() + .equals("file")) { + myFile = Paths.get(myFile.toURI()) + .toFile(); + } + // If this tweaker is loaded, FML skips loading the coremod by default. + Launch.classLoader.addTransformerExclusion("me.eigenraven.lwjgl3ify.core.Lwjgl3ifyCoremod"); + final Class cmmClass = (Class) Class + .forName("cpw.mods.fml.relauncher.CoreModManager", true, Launch.classLoader); + final Method cmmAddCoremod = cmmClass + .getDeclaredMethod("loadCoreMod", LaunchClassLoader.class, String.class, File.class); + cmmAddCoremod.setAccessible(true); + cmmAddCoremod.invoke(null, Launch.classLoader, "me.eigenraven.lwjgl3ify.core.Lwjgl3ifyCoremod", myFile); + coremodInjected = true; + } catch (InvocationTargetException e) { + if (e.getCause() instanceof RuntimeException re) { + throw re; + } else { + throw new RuntimeException(e); + } + } catch (Exception e) { + throw new RuntimeException(e); } - // If this tweaker is loaded, FML skips loading the coremod by default. - Launch.classLoader.addTransformerExclusion("me.eigenraven.lwjgl3ify.core.Lwjgl3ifyCoremod"); - final Class cmmClass = (Class) Class - .forName("cpw.mods.fml.relauncher.CoreModManager"); - final Method cmmAddCoremod = cmmClass - .getDeclaredMethod("loadCoreMod", LaunchClassLoader.class, String.class, File.class); - cmmAddCoremod.setAccessible(true); - cmmAddCoremod.invoke(null, Launch.classLoader, "me.eigenraven.lwjgl3ify.core.Lwjgl3ifyCoremod", myFile); } @Override @@ -67,8 +88,11 @@ public void acceptOptions(List args, File gameDir, File assetsDir, Strin } } + @SuppressWarnings("unchecked") @Override - public void injectIntoClassLoader(LaunchClassLoader classLoader) {} + public void injectIntoClassLoader(LaunchClassLoader classLoader) { + injectMyCoremod(); + } @Override public String getLaunchTarget() {