mirror of
https://github.com/GTNewHorizons/lwjgl3ify.git
synced 2026-11-24 22:14:36 +00:00
Patch CoreModManager and FMLSecurityManager to fix crashes under Java 11
This commit is contained in:
1 parent
aeb1a06ebc
commit
8a4bc55eb6
4 files changed
+71
-6
No files matched your search
@@ -36,6 +36,7 @@ dependencies {
|
||||
tasks.register(forgePatchesSet.jarTaskName, Jar) {
|
||||
from(forgePatchesSet.output)
|
||||
archiveClassifier.set("forgePatches")
|
||||
archiveVersion.set("1.0") // TODO
|
||||
}
|
||||
|
||||
tasks.named("assemble").configure {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"name": "Forge-J9-Patches",
|
||||
"uid": "me.eigenraven.lwjgl3ify.forgepatches",
|
||||
"version": "1",
|
||||
"order": 3,
|
||||
"libraries": [
|
||||
{
|
||||
"name": "com.gtnewhorizons:lwjgl3ify:1.0:forgePatches",
|
||||
"MMC-hint": "local"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@@ -383,13 +384,24 @@ public class CoreModManager {
|
||||
File coreMod, JarFile jar, String cascadedTweaker, LaunchClassLoader classLoader, Integer sortingOrder) {
|
||||
try {
|
||||
// Have to manually stuff the tweaker into the parent classloader
|
||||
if (ADDURL == null) {
|
||||
ADDURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
ADDURL.setAccessible(true);
|
||||
// PATCHED BEGIN
|
||||
URL coreModUrl = coreMod.toURI().toURL();
|
||||
ClassLoader myLoader = classLoader.getClass().getClassLoader();
|
||||
if (myLoader instanceof URLClassLoader) {
|
||||
if (ADDURL == null) {
|
||||
ADDURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
ADDURL.setAccessible(true);
|
||||
}
|
||||
ADDURL.invoke(myLoader, coreModUrl);
|
||||
} else {
|
||||
final Field ucpField = myLoader.getClass().getDeclaredField("ucp");
|
||||
ucpField.setAccessible(true);
|
||||
final Object ucp = ucpField.get(myLoader);
|
||||
final Method urlAdder = ucp.getClass().getDeclaredMethod("addURL", URL.class);
|
||||
urlAdder.invoke(ucp, coreModUrl);
|
||||
}
|
||||
ADDURL.invoke(
|
||||
classLoader.getClass().getClassLoader(), coreMod.toURI().toURL());
|
||||
classLoader.addURL(coreMod.toURI().toURL());
|
||||
classLoader.addURL(coreModUrl);
|
||||
// PATCHED END
|
||||
CoreModManager.tweaker.injectCascadingTweak(cascadedTweaker);
|
||||
tweakSorting.put(cascadedTweaker, sortingOrder);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package cpw.mods.fml.relauncher;
|
||||
|
||||
import java.security.Permission;
|
||||
|
||||
/**
|
||||
* A custom security manager stopping certain events from happening
|
||||
* unexpectedly.
|
||||
*
|
||||
* @author cpw
|
||||
*
|
||||
* @author eigenraven Patch ArrayIndexOutOfBoundsException - the length condition were 1-off
|
||||
*
|
||||
*/
|
||||
public class FMLSecurityManager extends SecurityManager {
|
||||
@Override
|
||||
public void checkPermission(Permission perm) {
|
||||
String permName = perm.getName() != null ? perm.getName() : "missing";
|
||||
if (permName.startsWith("exitVM")) {
|
||||
Class<?>[] classContexts = getClassContext();
|
||||
String callingClass = classContexts.length > 4 ? classContexts[4].getName() : "none"; // PATCHED
|
||||
String callingParent = classContexts.length > 5 ? classContexts[5].getName() : "none"; // PATCHED
|
||||
// FML is allowed to call system exit and the Minecraft applet (from the quit button)
|
||||
if (!(callingClass.startsWith("cpw.mods.fml.")
|
||||
|| ("net.minecraft.client.Minecraft".equals(callingClass)
|
||||
&& "net.minecraft.client.Minecraft".equals(callingParent))
|
||||
|| ("net.minecraft.server.dedicated.DedicatedServer".equals(callingClass)
|
||||
&& "net.minecraft.server.MinecraftServer".equals(callingParent)))) {
|
||||
throw new ExitTrappedException();
|
||||
}
|
||||
} else if ("setSecurityManager".equals(permName)) {
|
||||
throw new SecurityException("Cannot replace the FML security manager");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static class ExitTrappedException extends SecurityException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user