aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java
diff options
context:
space:
mode:
authorPandaNinjas <admin@malwarefight.gq>2023-02-08 09:25:37 -0800
committerPandaNinjas <admin@malwarefight.gq>2023-02-08 09:25:37 -0800
commit0579088389caf554624787fcfae910a1d7bede71 (patch)
tree230e14d815cc23b65cf8e265e4d76d1538437b9b /src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java
parentfd51baf3f06141a151fde7ad1ecdd80b8093351f (diff)
downloadNoSession-0579088389caf554624787fcfae910a1d7bede71.tar.gz
NoSession-0579088389caf554624787fcfae910a1d7bede71.tar.bz2
NoSession-0579088389caf554624787fcfae910a1d7bede71.zip
More nightly trolling (it launches)
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java')
-rw-r--r--src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java b/src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java
index 55e907c..e712254 100644
--- a/src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java
+++ b/src/main/java/gq/malwarefight/nosession/relaunch/Relaunch.java
@@ -1,6 +1,6 @@
package gq.malwarefight.nosession.relaunch;
-import gq.malwarefight.nosession.tweaks.CleanupTweaker;
+import gq.malwarefight.nosession.tweaks.cleanup.CleanupTweaker;
import gq.malwarefight.nosession.utils.Utils;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.client.FMLClientHandler;
@@ -17,6 +17,8 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
@@ -32,17 +34,14 @@ public class Relaunch {
setToNull(FMLClientHandler.class, "INSTANCE");
setToNull(Loader.class, "injectedContainers");
Utils.setStaticValue(FMLInjectionData.class, "containers", new ArrayList<String>());
- resetClass(ASMTransformerWrapper.class);
- URLClassLoader originalClassLoader = (URLClassLoader) Launch.class.getClassLoader();
- URL[] newURLS = new URL[originalClassLoader.getURLs().length + 1];
- URLClassLoader lcl = new URLClassLoader(newURLS, originalClassLoader);
- //noinspection unchecked
- Class<Launch> innerLaunch = (Class<Launch>) Class.forName("net.minecraft.launchwrapper.Launch", false, lcl);
+ resetTransformerWrapper();
+ addSelfToClassloader();
+ Class<Launch> innerLaunch = Launch.class;
Method launch = innerLaunch.getDeclaredMethod("main", String[].class);
launch.invoke(null, (Object) constructArgs(args, gameDir, assetsDir, version));
}
- public static String[] constructArgs(ArrayList<String> initial, File gameDir, File assetDir, String version) {
+ private static String[] constructArgs(ArrayList<String> initial, File gameDir, File assetDir, String version) {
initial.add("--version");
initial.add(version);
initial.add("--gameDir");
@@ -50,11 +49,11 @@ public class Relaunch {
initial.add("--assetsDir");
initial.add(assetDir.getAbsolutePath());
initial.add("--tweakClass");
- initial.add("gq.malwarefight.nosession.tweaks.CleanupTweaker");
+ initial.add(CleanupTweaker.class.getName());
return initial.toArray(new String[0]);
}
- public static void resetSecurityManager() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
+ private static void resetSecurityManager() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Method m = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
m.setAccessible(true);
Field[] fields = (Field[]) m.invoke(System.class, false);
@@ -67,8 +66,8 @@ public class Relaunch {
}
- public static void resetClass(Class<?> cls) throws IllegalAccessException, NoSuchFieldException {
- Field[] fields = cls.getDeclaredFields();
+ private static void resetTransformerWrapper() throws IllegalAccessException, NoSuchFieldException {
+ Field[] fields = ASMTransformerWrapper.class.getDeclaredFields();
for (Field field: fields) {
if ((field.getModifiers() & Modifier.STATIC) != 0) {
setToNull(field);
@@ -76,12 +75,12 @@ public class Relaunch {
}
}
- public static void setToNull(Class<?> cls, String fieldname) throws NoSuchFieldException, IllegalAccessException {
+ private static void setToNull(Class<?> cls, String fieldname) throws NoSuchFieldException, IllegalAccessException {
Field f = cls.getDeclaredField(fieldname);
setToNull(f);
}
- public static void setToNull(Field f) throws IllegalAccessException, NoSuchFieldException {
+ private static void setToNull(Field f) throws IllegalAccessException, NoSuchFieldException {
f.setAccessible(true);
if ((f.getModifiers() & Modifier.FINAL) != 0) { // if it is final
Field modifiers = Field.class.getDeclaredField("modifiers");
@@ -97,4 +96,10 @@ public class Relaunch {
}
}
+ private static void addSelfToClassloader() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, URISyntaxException, MalformedURLException {
+ URLClassLoader ucl = (URLClassLoader) Launch.class.getClassLoader();
+ Method addUrl = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+ addUrl.setAccessible(true);
+ addUrl.invoke(ucl, Utils.getLibraryPathAsFile(CleanupTweaker.class).toURI().toURL());
+ }
}