Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Decompiled by Procyon v0.5.36
- //
- package com.voidswrath.voidlauncher;
- import java.util.Iterator;
- import java.io.IOException;
- import java.util.List;
- import java.util.regex.Pattern;
- import java.io.Reader;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.FileInputStream;
- import java.util.Map;
- import java.io.OutputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileOutputStream;
- import java.io.BufferedInputStream;
- import java.net.URL;
- import java.util.ArrayList;
- import java.io.File;
- public class MinecraftLauncher
- {
- private static ProcessBuilder pb;
- static int exitcode;
- static int version;
- public static String urlEncode(String string) {
- string = string.replaceFirst("http://", "");
- return "http://" + string.replaceAll(" ", "%20").replaceAll("\\\\", "/");
- }
- public static void launchMinecraft(final MinecraftLogin login, final ILaunchable modpack, final int version, final ILaunchable downloader, final String server) throws InterruptedException {
- if (login != null && login.accessToken != null) {
- final String workingDir = modpack.getWorkingDirectory().getAbsolutePath();
- final String binpath = workingDir + File.separator + "bin" + File.separator;
- if (OSInfo.getPlatform() == OSInfo.OS.MACOS) {
- final File natives = new File(modpack.getWorkingDirectory(), "bin" + File.separator + "natives");
- if (natives.exists() && natives.isDirectory()) {
- for (final File file : natives.listFiles()) {
- if (file.toString().endsWith(".jnilib")) {
- final File test = new File(file.getParentFile(), file.getName().replace(".jnilib", ".dylib"));
- if (!test.exists()) {
- try {
- Downloader.copyFile(file, test);
- }
- catch (Throwable e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- else {
- System.out.println(natives);
- }
- }
- final String pathseperator = File.pathSeparator;
- final String separator = File.separator;
- final String javacommand = VoidConfig.getJavaCommand();
- if (VoidConfig.isJava8) {
- VoidLauncher.instance.cbPermFix.setEnabled(true);
- VoidLauncher.instance.cbPermFix.setSelected(false);
- VoidLauncher.instance.cbPermFix.setEnabled(false);
- }
- System.out.println("JavaCommand:" + javacommand);
- final StringBuilder cp = new StringBuilder();
- int minMem = 512;
- int maxMem = 1024;
- minMem = 1024;
- maxMem = Integer.parseInt(VoidLauncher.instance.tfMaxMem.getSelectedItem().toString().replace("GB", "")) * 1024;
- if (minMem > maxMem) {
- minMem = maxMem;
- }
- if (maxMem < 1222) {
- maxMem = 1222;
- }
- if (maxMem <= minMem) {
- minMem = maxMem - 1;
- }
- if (VoidLauncher.is64bit() && maxMem < 4096) {
- maxMem = 4096;
- }
- final ArrayList arguments = new ArrayList();
- arguments.add(javacommand);
- arguments.add("-Djava.net.preferIPv4Stack=true");
- arguments.add("-Dfml.ignoreInvalidMinecraftCertificates=true");
- arguments.add("-Dsun.net.client.defaultConnectTimeout=9999");
- arguments.add("-Dsun.net.client.defaultReadTimeout=9999");
- arguments.add("-Dsun.net.http.retryPost=true");
- if (server != null) {
- arguments.add("-Dvoidlauncher.server=" + server);
- }
- arguments.add("-Dlog4j2.formatMsgNoLookups=true");
- try {
- if (version >= 1710 || version <= 180) {
- arguments.add("-Dlog4j.configurationFile=log4j2_17-111.xml");
- final File file2 = new File(modpack.getWorkingDirectory().getAbsolutePath(), "log4j2_17-111.xml");
- if (!file2.exists()) {
- final BufferedInputStream br = new BufferedInputStream(new URL("https://vl4.voidswrath.com/releases/log4j2_17-111.xml").openConnection().getInputStream());
- final BufferedOutputStream bw = new BufferedOutputStream(new FileOutputStream(file2));
- final byte[] bytes = new byte[4095];
- int read = 0;
- while ((read = br.read(bytes)) >= 0) {
- bw.write(bytes, 0, read);
- }
- bw.flush();
- br.close();
- bw.close();
- }
- }
- else {
- arguments.add("-Dlog4j.configurationFile=log4j2_112-116.xml");
- final File file2 = new File(modpack.getWorkingDirectory().getAbsolutePath(), "log4j2_112-116.xml");
- if (!file2.exists()) {
- final BufferedInputStream br = new BufferedInputStream(new URL("https://vl4.voidswrath.com/releases/log4j2_112-116.xml").openConnection().getInputStream());
- final BufferedOutputStream bw = new BufferedOutputStream(new FileOutputStream(file2));
- final byte[] bytes = new byte[4095];
- int read = 0;
- while ((read = br.read(bytes)) >= 0) {
- bw.write(bytes, 0, read);
- }
- bw.flush();
- br.close();
- bw.close();
- }
- }
- }
- catch (Throwable ex) {
- ex.printStackTrace();
- }
- if (version < 162) {
- arguments.add("-Djava.library.path=" + binpath + "natives");
- cp.append("bin").append(separator).append(separator).append("minecraft.jar").append(pathseperator).append("bin").append(separator).append(separator).append("lwjgl.jar").append(pathseperator).append("bin").append(separator).append(separator).append("lwjgl_util.jar").append(pathseperator).append("bin").append(separator).append(separator).append("jinput.jar").append(pathseperator);
- arguments.add("-Xms" + String.valueOf(minMem) + "M");
- arguments.add("-Xmx" + String.valueOf(maxMem) + "M");
- if (VoidLauncher.instance.cbPermFix.isSelected()) {
- arguments.add("-XX:MaxPermSize=256M");
- }
- arguments.add("-XX:+UseParallelGC");
- arguments.add("-XX:ParallelGCThreads=" + Math.max(1, VoidLauncher.cores / 2));
- arguments.add("-XX:+UseSplitVerifier");
- arguments.add("-XX:+FailOverToOldVerifier");
- arguments.add("-XX:-HeapDumpOnOutOfMemoryError");
- arguments.add("-XX:+UseCompressedOops");
- arguments.add("-XX:+ScavengeBeforeFullGC");
- arguments.add("-XX:+PrintCommandLineFlags");
- arguments.add("-cp");
- arguments.add(cp.toString());
- arguments.add("net.minecraft.client.Minecraft");
- arguments.add(login.ingameName);
- if (!login.accessToken.equals("offline")) {
- arguments.add(login.accessToken);
- }
- }
- else {
- arguments.add("-Djava.library.path=" + binpath + "natives");
- arguments.add("-Xms" + String.valueOf(minMem) + "M");
- arguments.add("-Xmx" + String.valueOf(maxMem) + "M");
- if (VoidLauncher.instance.cbPermFix.isSelected()) {
- arguments.add("-XX:MaxPermSize=256M");
- }
- arguments.add("-XX:+UseParallelGC");
- arguments.add("-XX:ParallelGCThreads=" + Math.max(1, VoidLauncher.cores / 2));
- arguments.add("-XX:+UseSplitVerifier");
- arguments.add("-XX:+FailOverToOldVerifier");
- arguments.add("-XX:-HeapDumpOnOutOfMemoryError");
- arguments.add("-XX:+UseCompressedOops");
- arguments.add("-XX:+ScavengeBeforeFullGC");
- arguments.add("-XX:+PrintCommandLineFlags");
- if (new File(modpack.getWorkingDirectory(), "bin").listFiles() == null) {
- System.out.println("Detected incomplete install...reinstalling.");
- VoidConfig.applyPendingInstall(modpack);
- if (modpack instanceof ModPack) {
- VoidLauncher.shared.execute(new Runnable() {
- @Override
- public void run() {
- try {
- final URL configs = new URL(MinecraftLauncher.urlEncode("https://vl4.voidswrath.com/" + ((ModPack)modpack).Mods.get("CONFIGS").get("URL").toString()));
- final String configMD5 = ((ModPack)modpack).Mods.get("CONFIGS").get("MD5").toString();
- Downloader.startModPack((ModPack)modpack, configs, configMD5, true, (String)null);
- }
- catch (Throwable ex) {
- ex.printStackTrace();
- }
- }
- });
- }
- return;
- }
- final File[] listFiles2;
- File[] arrayOfFile1 = listFiles2 = new File(modpack.getWorkingDirectory(), "bin").listFiles();
- for (final File file3 : listFiles2) {
- if (!file3.isDirectory() && file3.getName().endsWith(".jar")) {
- cp.append("bin").append(separator).append(file3.getName()).append(pathseperator);
- }
- }
- if (new File(modpack.getWorkingDirectory(), "bin" + separator + "lib").listFiles() == null) {
- System.out.println("Detected incomplete install...reinstalling.");
- VoidConfig.applyPendingInstall(modpack);
- if (modpack instanceof ModPack) {
- VoidLauncher.shared.execute(new Runnable() {
- @Override
- public void run() {
- try {
- final URL configs = new URL(MinecraftLauncher.urlEncode("https://vl4.voidswrath.com/" + ((ModPack)modpack).Mods.get("CONFIGS").get("URL").toString()));
- final String configMD5 = ((ModPack)modpack).Mods.get("CONFIGS").get("MD5").toString();
- Downloader.startModPack((ModPack)modpack, configs, configMD5, true, (String)null);
- }
- catch (Throwable ex) {
- ex.printStackTrace();
- }
- }
- });
- }
- return;
- }
- final File[] listFiles3;
- arrayOfFile1 = (listFiles3 = new File(modpack.getWorkingDirectory(), "bin" + separator + "lib").listFiles());
- for (final File file3 : listFiles3) {
- if (!file3.isDirectory() && file3.getName().endsWith(".jar")) {
- cp.append("bin").append(separator).append("lib").append(separator).append(file3.getName()).append(pathseperator);
- }
- else if (version == 1164 && file3.isDirectory()) {
- cp.append(getJars(modpack.getWorkingDirectory(), file3));
- }
- }
- arguments.add("-cp");
- arguments.add(cp.toString() + File.pathSeparator + "bin" + File.separator + "lib" + File.separator + "org" + File.separator + "ow2" + File.separator + "asm" + File.separator + "asm" + File.separator + "7.2" + File.separator + "asm-7.2.jar");
- if (version == 1164) {
- arguments.add("cpw.mods.modlauncher.Launcher");
- }
- else {
- arguments.add("net.minecraft.launchwrapper.Launch");
- }
- arguments.add("--username");
- arguments.add(login.ingameName);
- if (version >= 1710) {
- arguments.add("--accessToken");
- if (!login.accessToken.equals("offline")) {
- arguments.add(login.accessToken);
- arguments.add("--uuid");
- arguments.add(login.uuid);
- }
- else {
- arguments.add("null");
- }
- arguments.add("--version");
- arguments.add("1.7.10");
- arguments.add("--assetIndex");
- arguments.add("1.7.10");
- arguments.add("--tweakClass");
- arguments.add("cpw.mods.fml.common.launcher.FMLTweaker");
- }
- else if (version >= 1164) {
- arguments.add("--accessToken");
- if (!login.accessToken.equals("offline")) {
- arguments.add(login.accessToken);
- arguments.add("--uuid");
- arguments.add(login.uuid);
- }
- else {
- arguments.add("null");
- }
- }
- else if (version >= 180) {
- arguments.add("--accessToken");
- if (!login.accessToken.equals("offline")) {
- arguments.add(login.accessToken);
- arguments.add("--uuid");
- arguments.add(login.uuid);
- }
- else {
- arguments.add("null");
- }
- arguments.add("--version");
- arguments.add("1.8");
- arguments.add("--assetIndex");
- arguments.add("1.8");
- arguments.add("--tweakClass");
- arguments.add("net.minecraftforge.fml.common.launcher.FMLTweaker");
- }
- else if (version >= 172) {
- arguments.add("--accessToken");
- if (!login.accessToken.equals("offline")) {
- arguments.add(login.accessToken);
- arguments.add("--uuid");
- arguments.add(login.uuid);
- }
- else {
- arguments.add("null");
- }
- arguments.add("--version");
- arguments.add("1.7.2");
- arguments.add("--tweakClass");
- arguments.add("cpw.mods.fml.common.launcher.FMLTweaker");
- }
- else {
- arguments.add("--session");
- if (!login.accessToken.equals("offline")) {
- arguments.add(login.accessToken);
- }
- else {
- arguments.add("null");
- }
- arguments.add("--version");
- arguments.add("minecraft");
- arguments.add("--tweakClass");
- arguments.add("cpw.mods.fml.common.launcher.FMLTweaker");
- }
- arguments.add("--gameDir");
- arguments.add(modpack.getWorkingDirectory().getAbsolutePath());
- arguments.add("--assetsDir");
- arguments.add(modpack.getWorkingDirectory().getAbsolutePath() + separator + "assets");
- }
- try {
- final File file2 = new File(modpack.getWorkingDirectory(), "additionalCmdLine.txt");
- if (file2.exists()) {
- final BufferedReader br2 = new BufferedReader(new InputStreamReader(new FileInputStream(file2)));
- String arg;
- while ((arg = br2.readLine()) != null) {
- arg = arg.trim();
- if (arg.length() > 0) {
- final String[] split;
- final String[] args = split = arg.split(Pattern.quote(" "));
- for (final String a : split) {
- arguments.add(a);
- }
- }
- }
- br2.close();
- }
- }
- catch (Throwable t) {}
- System.out.println(arguments);
- (MinecraftLauncher.pb = new ProcessBuilder(arguments).directory(modpack.getWorkingDirectory())).redirectErrorStream(true);
- try {
- VoidLauncher.instance.setState(1);
- }
- catch (Throwable t2) {}
- MinecraftLauncher.exitcode = -1337;
- System.currentTimeMillis();
- try {
- final Process process = MinecraftLauncher.pb.start();
- MinecraftLauncher.exitcode = -1337;
- VoidConfig.applySuccessfulModpack(modpack);
- System.gc();
- VoidLauncher.shared.execute(new Runnable() {
- final InputStream is = process.getInputStream();
- final InputStreamReader isr = new InputStreamReader(this.is);
- final BufferedReader br = new BufferedReader(this.isr);
- @Override
- public void run() {
- VoidLauncher.shared.execute(new Runnable() {
- @Override
- public void run() {
- String line = "";
- try {
- do {
- if (!line.isEmpty()) {
- System.out.println(line);
- }
- try {
- while (MinecraftLauncher.exitcode == -1337) {
- if (Runnable.this.br.ready() && Runnable.this.isr.ready() && Runnable.this.is.available() != 0) {
- break;
- }
- }
- }
- catch (IOException ex) {
- if (!ex.getMessage().contains("Stream closed")) {
- ex.printStackTrace();
- }
- }
- catch (Exception ex2) {
- ex2.printStackTrace();
- }
- if (MinecraftLauncher.exitcode != -1337) {
- break;
- }
- } while ((line = Runnable.this.br.readLine()) != null);
- }
- catch (Throwable ex3) {
- ex3.printStackTrace();
- }
- }
- });
- while (MinecraftLauncher.exitcode == -1337) {
- try {
- Thread.sleep(2L);
- MinecraftLauncher.exitcode = process.exitValue();
- process.destroy();
- }
- catch (Exception ex) {}
- }
- try {
- this.br.close();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- }
- catch (Throwable exasdasdas) {
- exasdasdas.printStackTrace();
- }
- }
- }
- private static void getJars(final File file, final List<File> list) {
- for (final File ff : file.listFiles()) {
- if (ff.isDirectory()) {
- getJars(ff, list);
- }
- else if (ff.getName().toLowerCase().endsWith(".jar")) {
- list.add(ff);
- }
- }
- }
- private static String getJars(final File root, final File file) {
- String ret = "";
- final List<File> jars = new ArrayList<File>();
- getJars(file, jars);
- for (final File f : jars) {
- ret = ret + f.getPath().replace(root.getPath() + File.separator, "") + File.pathSeparator;
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement