Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Now entirely working
Browse files Browse the repository at this point in the history
  • Loading branch information
Litarvan committed Dec 13, 2015
1 parent 4352599 commit b3dc187
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import fr.theshark34.openlauncherlib.LaunchException;
import fr.theshark34.openlauncherlib.util.LogUtil;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Date;

Expand Down Expand Up @@ -99,11 +101,9 @@ public Object launch() throws LaunchException
}

Class<?> theClass;
Object initClass;
try
{
theClass = ClassLoader.getSystemClassLoader().loadClass(profile.getTargetClass());
initClass = initializer.init(theClass);
}
catch (Exception e)
{
Expand Down Expand Up @@ -137,6 +137,20 @@ public Object launch() throws LaunchException
throw e instanceof UnknownMethodException ? (UnknownMethodException) e : new UnknownMethodException(profile.getTargetMethod(), e);
}


Object initClass = null;
if (!Modifier.isStatic(method.getModifiers()))
try
{
initClass = initializer.init(theClass);
}
catch (Throwable t)
{
throw new LaunchException("Can't initialize the main class", t);
}

method.setAccessible(true);

long totalTime = System.currentTimeMillis() - start;
int seconds = (int) (totalTime / 1000) % 60;
int minutes = (int) ((totalTime / (1000 * 60)) % 60);
Expand All @@ -150,9 +164,19 @@ public Object launch() throws LaunchException
{
return method.invoke(initClass, profile.getParameters());
}
catch (Exception e)
catch (InvocationTargetException e)
{
Throwable thrown = e.getTargetException();
if (thrown instanceof ExceptionInInitializerError)
{
ExceptionInInitializerError initError = (ExceptionInInitializerError) thrown;
thrown = initError.getException();
}
throw new LaunchException("Invoked method returned an exception", thrown);
}
catch (IllegalAccessException e)
{
throw new LaunchException("Invoked method returned an exception", e);
throw new LaunchException("This is not supposed to happen", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import fr.theshark34.openlauncherlib.util.LogUtil;
import fr.theshark34.openlauncherlib.util.explorer.Explorer;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -65,12 +67,21 @@ public static InternalLaunchProfile createInternalProfile(GameInfos infos, GameF

List<String> arguments = infos.getGameVersion().getGameType().getLaunchArgs(infos, folder, authInfos);

if(infos.getGameTweaks() != null)
for (GameTweak tweak : infos.getGameTweaks())
{
arguments.add("--tweakClass");
arguments.add(tweak.getTweakClass(infos));
}

String mainClass = infos.getGameTweaks() == null || infos.getGameTweaks().length == 0 ? infos.getGameVersion().getGameType().getMainClass(infos) : GameTweak.LAUNCHWRAPPER_MAIN_CLASS;
String[] args = arguments.toArray(new String[arguments.size()]);

InternalLaunchProfile profile = new InternalLaunchProfile(mainClass, args);
profile.setClasspath(libs);

System.setProperty("fml.ignoreInvalidMinecraftCertificates", "true");

LogUtil.info("nat");
try
{
Expand Down Expand Up @@ -99,7 +110,7 @@ public static InternalLaunchProfile createInternalProfile(GameInfos infos, GameF
*/
public static ExternalLaunchProfile createExternalProfile(GameInfos infos, GameFolder folder, AuthInfos authInfos) throws LaunchException
{
LogUtil.info("mc-int", infos.getGameVersion().getName());
LogUtil.info("mc-ext", infos.getGameVersion().getName());
LogUtil.info("mc-check", infos.getGameDir().getAbsolutePath());

checkFolder(folder, infos.getGameDir());
Expand All @@ -110,10 +121,19 @@ public static ExternalLaunchProfile createExternalProfile(GameInfos infos, GameF
constructor.add(Explorer.dir(infos.getGameDir()).sub(folder.getLibsFolder()).allRecursive().files().match("^(.*\\.((jar)$))*$").get());
constructor.add(Explorer.dir(infos.getGameDir()).get(folder.getMainJar()));

String mainClass = infos.getGameVersion().getGameType().getMainClass(infos);
String mainClass = infos.getGameTweaks() == null || infos.getGameTweaks().length == 0 ? infos.getGameVersion().getGameType().getMainClass(infos) : GameTweak.LAUNCHWRAPPER_MAIN_CLASS;
String classpath = constructor.make();
List<String> args = infos.getGameVersion().getGameType().getLaunchArgs(infos, folder, authInfos);
List<String> vmArgs = Collections.singletonList("-Djava.library.path=" + Explorer.dir(infos.getGameDir()).sub(folder.getNativesFolder()).get().getAbsolutePath());
List<String> vmArgs = new ArrayList<String>();
vmArgs.add("-Djava.library.path=" + Explorer.dir(infos.getGameDir()).sub(folder.getNativesFolder()).get().getAbsolutePath());
vmArgs.add("-Dfml.ignoreInvalidMinecraftCertificates=true");

if(infos.getGameTweaks() != null)
for (GameTweak tweak : infos.getGameTweaks())
{
args.add("--tweakClass");
args.add(tweak.getTweakClass(infos));
}

ExternalLaunchProfile profile = new ExternalLaunchProfile(mainClass, classpath, vmArgs, args, true, infos.getServerName(), infos.getGameDir());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public class CrashReporter
/**
* Basic constructor
*
* @param name The project name
* @param dir The directory to write the crashes
*/
public CrashReporter(File dir)
public CrashReporter(String name, File dir)
{
this.name = name;
this.dir = dir;
}

Expand Down Expand Up @@ -113,28 +115,43 @@ public File writeError(Exception e) throws IOException
FileWriter fw = new FileWriter(file);

fw.write(makeCrashReport(name, e));
fw.write(e.toString());

fw.close();

return file;
}

/**
* Return the crash directory
* @return The crash dir
*/
public File getDir()
{
return dir;
}

/**
* Set the directory where are the crashes
* @param dir The crash dir
*/
public void setDir(File dir)
{
this.dir = dir;
}

/**
* Return the reporter name
* @return The name
*/
public String getName()
{
return name;
}

/**
* Set the reporter name
* @param name The new name
*/
public void setName(String name)
{
this.name = name;
Expand All @@ -153,17 +170,27 @@ public static String makeCrashReport(String projectName, Exception e)
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();

String report = "# " + projectName + " Crash Report\n" +
"#\n" +
"# At : " + dateFormat.format(date) + "\n" +
"#\n" +
"# Exception : " + e.getClass().getSimpleName() + "\n";
String report = "# " + projectName + " Crash Report\n\r" +
"#\n\r" +
"# At : " + dateFormat.format(date) + "\n\r" +
"#\n\r" +
"# Exception : " + e.getClass().getSimpleName() + "\n\r";

report += "\n# " + e.toString();
report += "\n\r# " + e.toString();

StackTraceElement[] stackTrace = e.getStackTrace();
for (StackTraceElement element : stackTrace)
report += "\n# " + element;
report += "\n\r# " + element;

Throwable cause = e.getCause();
if (cause != null)
{
report += "\n\r# Caused by: " + cause.toString();

StackTraceElement[] causeStackTrace = cause.getStackTrace();
for (StackTraceElement element : causeStackTrace)
report += "\n\r# " + element;
}

return report;
}
Expand Down
Loading

0 comments on commit b3dc187

Please sign in to comment.