/
MultiMCLauncher.java
119 lines (104 loc) · 2.92 KB
/
MultiMCLauncher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class MultiMCLauncher
{
/**
* @param args
* The arguments you want to launch Minecraft with. New path,
* Username, Session ID.
*/
public static void main(String[] args)
{
if (args.length != 3)
{
System.out.println("Not enough arguments.");
System.exit(-1);
}
try
{
System.out.println("Loading jars...");
String[] jarFiles = new String[] {
"minecraft.jar", "lwjgl.jar", "lwjgl_util.jar", "jinput.jar"
};
URL[] urls = new URL[jarFiles.length];
for (int i = 0; i < urls.length; i++)
{
try
{
File f = new File(new File(args[0], "bin"), jarFiles[i]);
urls[i] = f.toURI().toURL();
System.out.println("Loading URL: " + urls[i].toString());
} catch (MalformedURLException e)
{
// e.printStackTrace();
System.err.println("MalformedURLException, " + e.toString());
System.exit(5);
}
}
System.out.println("Loading natives...");
String nativesDir = new File(new File(args[0], "bin"), "natives").toString();
System.setProperty("org.lwjgl.librarypath", nativesDir);
System.setProperty("net.java.games.input.librarypath", nativesDir);
System.setProperty("user.home", new File(args[0]).getParent());
URLClassLoader cl =
new URLClassLoader(urls, MultiMCLauncher.class.getClassLoader());
// Get the Minecraft Class.
Class<?> mc = cl.loadClass("net.minecraft.client.Minecraft");
Field[] fields = mc.getDeclaredFields();
for (int i = 0; i < fields.length; i++)
{
Field f = fields[i];
if (f.getType() != File.class)
{
// Has to be File
continue;
}
if (f.getModifiers() != (Modifier.PRIVATE + Modifier.STATIC))
{
// And Private Static.
continue;
}
f.setAccessible(true);
f.set(null, new File(args[0]));
// And set it.
System.out.println("Fixed Minecraft Path: Field was "
+ f.toString());
}
String[] mcArgs = new String[2];
mcArgs[0] = args[1];
mcArgs[1] = args[2];
String mcDir = mc.getMethod("a", String.class).invoke(null, (Object) "minecraft").toString();
System.out.println("MCDIR: " + mcDir);
mc.getMethod("main", String[].class).invoke(null, (Object) mcArgs);
} catch (ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
} catch (IllegalArgumentException e)
{
e.printStackTrace();
System.exit(2);
} catch (IllegalAccessException e)
{
e.printStackTrace();
System.exit(2);
} catch (InvocationTargetException e)
{
e.printStackTrace();
System.exit(3);
} catch (NoSuchMethodException e)
{
e.printStackTrace();
System.exit(3);
} catch (SecurityException e)
{
e.printStackTrace();
System.exit(4);
}
}
}