Skip to content

Commit

Permalink
Fix remaining LCL.getSources issues that caused e.g. broken NEI handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Feb 9, 2024
1 parent 0469e8f commit 3febafc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CoreModManager> cmmClass = (Class<CoreModManager>) 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<CoreModManager> cmmClass = (Class<CoreModManager>) 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
Expand All @@ -67,8 +88,11 @@ public void acceptOptions(List<String> args, File gameDir, File assetsDir, Strin
}
}

@SuppressWarnings("unchecked")
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {}
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
injectMyCoremod();
}

@Override
public String getLaunchTarget() {
Expand Down

0 comments on commit 3febafc

Please sign in to comment.