Created
January 14, 2012 01:45
-
-
Save Forkk/1609812 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Applet createApplet() throws ClassNotFoundException, | |
InstantiationException, IllegalAccessException | |
{ | |
Class<?> appletClass = classLoader | |
.loadClass("net.minecraft.client.MinecraftApplet"); | |
try | |
{ | |
Class<?> mcClass = classLoader.loadClass("net.minecraft.client.Minecraft"); | |
Field mcDirField = null; | |
for (Field f : mcClass.getDeclaredFields()) | |
{ | |
// If it is a file | |
if (f.getType() == File.class) | |
{ | |
f.setAccessible(true); | |
// Make sure it's static | |
try { f.get(null); } catch (NullPointerException e) { continue; } | |
mcDirField = f; | |
System.out.println("Found mcDir field. Name: " + f.getName() + | |
" Value: " + f.get(null)); | |
} | |
} | |
if (mcDirField != null) | |
{ | |
mcDirField.set(null, PathUtils.getMCDir()); | |
} | |
} catch (SecurityException e) | |
{ | |
e.printStackTrace(); | |
JOptionPane.showMessageDialog(null, "Couldn't launch in custom " + | |
"directory. " + e.toString(), "Error Launching", | |
JOptionPane.ERROR_MESSAGE); | |
// } catch (NoSuchFieldException e) | |
// { | |
// e.printStackTrace(); | |
// JOptionPane.showMessageDialog(null, "Couldn't launch in custom " + | |
// "directory because the minecraftDir field was not found. " + | |
// "The launcher will launch the game in the default " + | |
// "directory instead.", | |
// "Error Launching", | |
// JOptionPane.ERROR_MESSAGE); | |
} finally | |
{ | |
} | |
// Load mods | |
System.out.println("Loading mods..."); | |
try | |
{ | |
ArrayList<URL> urlAL = new ArrayList<URL>(); | |
int i = 0; | |
for (File f : PathUtils.getJarMods().listFiles()) | |
{ | |
URL url = f.toURI().toURL(); | |
urlList[i] = url; | |
i++; | |
} | |
URL[] urlList = urlAL.toArray(new URL[0]); | |
URLClassLoader urlCL = new URLClassLoader(urlList, classLoader); | |
for (File f : PathUtils.getJarMods().listFiles()) | |
{ | |
if (FileUtils.getExtension(f).equals(".zip")) | |
{ | |
ZipFile zf = new ZipFile(f); | |
Enumeration<? extends ZipEntry> entries = zf.entries(); | |
while (entries.hasMoreElements()) | |
{ | |
ZipEntry entry = entries.nextElement(); | |
if (entry.getName().endsWith(".class")) | |
{ | |
boolean loaded = true; | |
try | |
{ | |
urlCL.loadClass(entry.getName(). | |
substring(0, entry.getName().lastIndexOf('.'))); | |
} catch (ClassNotFoundException e) | |
{ | |
loaded = false; | |
System.err.println(entry.getName() + " could not be loaded."); | |
} | |
if (loaded) | |
System.out.println("Loaded " + entry.getName()); | |
} | |
} | |
} | |
} | |
} catch (MalformedURLException e) | |
{ | |
e.printStackTrace(); | |
} catch (ZipException e) | |
{ | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (IOException e) | |
{ | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return (Applet) appletClass.newInstance(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment