Launch through the applet launcher too

This commit is contained in:
Christian committed 2012-07-06 01:04:33 -04:00
1 parent b1ca21a161
commit df6bbaa7c5
3 files changed
+133 -11

No files matched your search

@@ -1,5 +1,7 @@
package cpw.mods.fml.relauncher;
import java.applet.Applet;
import java.applet.AppletStub;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -13,11 +15,22 @@ public class FMLEmbeddingRelauncher
{
private static FMLEmbeddingRelauncher INSTANCE;
private RelaunchClassLoader clientLoader;
private Object newApplet;
private Class<? super Object> appletClass;
public static void relaunch(ArgsWrapper wrap)
{
INSTANCE = new FMLEmbeddingRelauncher();
INSTANCE.relaunchClient(wrap);
instance().relaunchClient(wrap);
}
private static FMLEmbeddingRelauncher instance()
{
if (INSTANCE == null)
{
INSTANCE = new FMLEmbeddingRelauncher();
System.out.println("FML relaunch active");
}
return INSTANCE;
}
private FMLEmbeddingRelauncher()
@@ -28,6 +41,24 @@ public class FMLEmbeddingRelauncher
}
private void relaunchClient(ArgsWrapper wrap)
{
File minecraftHome = setupHome();
// Now we re-inject the home into the "new" minecraft under our control
Class<? super Object> client = ReflectionHelper.getClass(clientLoader, "net.minecraft.client.Minecraft");
ReflectionHelper.setPrivateValue(client, null, minecraftHome, "field_6275_Z", "ap", "minecraftDir");
try
{
ReflectionHelper.findMethod(client, null, new String[] { "fmlReentry" }, ArgsWrapper.class).invoke(null, wrap);
}
catch (Exception e)
{
// Hmmm
}
}
private File setupHome()
{
Class<? super Object> mcMaster = ReflectionHelper.getClass(getClass().getClassLoader(), "net.minecraft.client.Minecraft");
// We force minecraft to setup it's homedir very early on so we can inject stuff into it
@@ -43,18 +74,76 @@ public class FMLEmbeddingRelauncher
File minecraftHome = ReflectionHelper.getPrivateValue(mcMaster, null, "field_6275_Z", "ap", "minecraftDir");
RelaunchLibraryManager.handleLaunch(minecraftHome, clientLoader);
return minecraftHome;
}
// Now we re-inject the home into the "new" minecraft under our control
Class<? super Object> client = ReflectionHelper.getClass(clientLoader, "net.minecraft.client.Minecraft");
ReflectionHelper.setPrivateValue(client, null, minecraftHome, "field_6275_Z", "ap", "minecraftDir");
public static void appletEntry(Applet minecraftApplet)
{
instance().relaunchApplet(minecraftApplet);
}
private void relaunchApplet(Applet minecraftApplet)
{
appletClass = ReflectionHelper.getClass(clientLoader, "net.minecraft.client.MinecraftApplet");
if (minecraftApplet.getClass().getClassLoader() == clientLoader)
{
try
{
newApplet = minecraftApplet;
ReflectionHelper.findMethod(appletClass, newApplet, new String[] {"fmlInitReentry"}).invoke(newApplet);
return;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
setupHome();
Class<? super Object> parentAppletClass = ReflectionHelper.getClass(getClass().getClassLoader(), "java.applet.Applet");
try
{
ReflectionHelper.findMethod(client, null, new String[] { "fmlReentry" }, ArgsWrapper.class).invoke(null, wrap);
newApplet = appletClass.newInstance();
Object appletContainer = ReflectionHelper.getPrivateValue(ReflectionHelper.getClass(getClass().getClassLoader(), "java.awt.Component"), minecraftApplet, "parent");
Class<? super Object> launcherClass = ReflectionHelper.getClass(getClass().getClassLoader(), "net.minecraft.Launcher");
if (launcherClass.isInstance(appletContainer))
{
ReflectionHelper.findMethod(ReflectionHelper.getClass(getClass().getClassLoader(), "java.awt.Container"), minecraftApplet, new String[] { "removeAll" }).invoke(appletContainer);
ReflectionHelper.findMethod(launcherClass, appletContainer, new String[] { "replace" }, parentAppletClass).invoke(appletContainer, newApplet);
}
else
{
System.out.printf("Found unknown applet parent %s, unable to inject!\n", launcherClass);
throw new RuntimeException();
}
}
catch (Exception e)
{
// Hmmm
throw new RuntimeException(e);
}
}
public static void appletStart(Applet applet)
{
instance().startApplet(applet);
}
private void startApplet(Applet applet)
{
if (applet.getClass().getClassLoader() == clientLoader)
{
try
{
ReflectionHelper.findMethod(appletClass, newApplet, new String[] {"fmlStartReentry"}).invoke(newApplet);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
return;
}
}
@@ -9,7 +9,6 @@ public class RelaunchClassLoader extends URLClassLoader
public RelaunchClassLoader(URL[] sources)
{
super(sources);
System.out.println(Arrays.toString(sources));
}
@Override
@@ -17,7 +16,7 @@ public class RelaunchClassLoader extends URLClassLoader
{
if (name.startsWith("cpw.mods.fml.relauncher"))
{
return super.loadClass(name);
return getClass().getClassLoader().loadClass(name);
}
try
{
@@ -25,7 +24,7 @@ public class RelaunchClassLoader extends URLClassLoader
}
catch (ClassNotFoundException cnfe)
{
return super.loadClass(name);
return getClass().getClassLoader().loadClass(name);
}
}
@@ -33,6 +32,5 @@ public class RelaunchClassLoader extends URLClassLoader
protected void addURL(URL url)
{
super.addURL(url);
System.out.println(Arrays.toString(getURLs()));
}
}
@@ -0,0 +1,35 @@
--- ../src-base/minecraft/net/minecraft/client/MinecraftApplet.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src-work/minecraft/net/minecraft/client/MinecraftApplet.java 0000-00-00 00:00:00.000000000 -0000
@@ -4,6 +4,8 @@
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.io.File;
+
+import cpw.mods.fml.relauncher.FMLEmbeddingRelauncher;
import net.minecraft.src.CanvasMinecraftApplet;
import net.minecraft.src.MinecraftAppletImpl;
import net.minecraft.src.Session;
@@ -16,6 +18,11 @@
public void init()
{
+ FMLEmbeddingRelauncher.appletEntry(this);
+ }
+
+ public void fmlInitReentry()
+ {
this.field_6235_a = new CanvasMinecraftApplet(this);
boolean var1 = "true".equalsIgnoreCase(this.getParameter("fullscreen"));
this.field_6234_b = new MinecraftAppletImpl(this, this.field_6235_a, this, this.getWidth(), this.getHeight(), var1);
@@ -72,6 +79,11 @@
public void start()
{
+ FMLEmbeddingRelauncher.appletStart(this);
+ }
+
+ public void fmlStartReentry()
+ {
if (this.field_6234_b != null)
{
this.field_6234_b.field_6316_m = false;