Skip to content

Instantly share code, notes, and snippets.

@GUIpsp
Forked from Forkk/gist:1609812
Created January 14, 2012 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GUIpsp/1609821 to your computer and use it in GitHub Desktop.
Save GUIpsp/1609821 to your computer and use it in GitHub Desktop.
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"))
{URLClassLoader clazzLoader ;
string filePath = f.InsertFunctionTOTURNINTOAFUCKINGPATH
ClassLoaderUtil.addFile(filePath);
filePath = “jar:file://” + filePath + “!/”;
URL url = new File(filePath).toURL();
clazzLoader = new URLClassLoader(new URL[]{url});
clazz = clazzLoader.loadClass(name);
}
}
} 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