Advertisement
DannyK0

Untitled

Oct 1st, 2023
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.59 KB | None | 0 0
  1. //
  2. // Decompiled by Procyon v0.5.36
  3. //
  4.  
  5. package com.voidswrath.voidlauncher;
  6.  
  7. import java.util.Iterator;
  8. import java.io.IOException;
  9. import java.util.List;
  10. import java.util.regex.Pattern;
  11. import java.io.Reader;
  12. import java.io.BufferedReader;
  13. import java.io.InputStream;
  14. import java.io.InputStreamReader;
  15. import java.io.FileInputStream;
  16. import java.util.Map;
  17. import java.io.OutputStream;
  18. import java.io.BufferedOutputStream;
  19. import java.io.FileOutputStream;
  20. import java.io.BufferedInputStream;
  21. import java.net.URL;
  22. import java.util.ArrayList;
  23. import java.io.File;
  24.  
  25. public class MinecraftLauncher
  26. {
  27. private static ProcessBuilder pb;
  28. static int exitcode;
  29. static int version;
  30.  
  31. public static String urlEncode(String string) {
  32. string = string.replaceFirst("http://", "");
  33. return "http://" + string.replaceAll(" ", "%20").replaceAll("\\\\", "/");
  34. }
  35.  
  36. public static void launchMinecraft(final MinecraftLogin login, final ILaunchable modpack, final int version, final ILaunchable downloader, final String server) throws InterruptedException {
  37. if (login != null && login.accessToken != null) {
  38. final String workingDir = modpack.getWorkingDirectory().getAbsolutePath();
  39. final String binpath = workingDir + File.separator + "bin" + File.separator;
  40. if (OSInfo.getPlatform() == OSInfo.OS.MACOS) {
  41. final File natives = new File(modpack.getWorkingDirectory(), "bin" + File.separator + "natives");
  42. if (natives.exists() && natives.isDirectory()) {
  43. for (final File file : natives.listFiles()) {
  44. if (file.toString().endsWith(".jnilib")) {
  45. final File test = new File(file.getParentFile(), file.getName().replace(".jnilib", ".dylib"));
  46. if (!test.exists()) {
  47. try {
  48. Downloader.copyFile(file, test);
  49. }
  50. catch (Throwable e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. }
  55. }
  56. }
  57. else {
  58. System.out.println(natives);
  59. }
  60. }
  61. final String pathseperator = File.pathSeparator;
  62. final String separator = File.separator;
  63. final String javacommand = VoidConfig.getJavaCommand();
  64. if (VoidConfig.isJava8) {
  65. VoidLauncher.instance.cbPermFix.setEnabled(true);
  66. VoidLauncher.instance.cbPermFix.setSelected(false);
  67. VoidLauncher.instance.cbPermFix.setEnabled(false);
  68. }
  69. System.out.println("JavaCommand:" + javacommand);
  70. final StringBuilder cp = new StringBuilder();
  71. int minMem = 512;
  72. int maxMem = 1024;
  73. minMem = 1024;
  74. maxMem = Integer.parseInt(VoidLauncher.instance.tfMaxMem.getSelectedItem().toString().replace("GB", "")) * 1024;
  75. if (minMem > maxMem) {
  76. minMem = maxMem;
  77. }
  78. if (maxMem < 1222) {
  79. maxMem = 1222;
  80. }
  81. if (maxMem <= minMem) {
  82. minMem = maxMem - 1;
  83. }
  84. if (VoidLauncher.is64bit() && maxMem < 4096) {
  85. maxMem = 4096;
  86. }
  87. final ArrayList arguments = new ArrayList();
  88. arguments.add(javacommand);
  89. arguments.add("-Djava.net.preferIPv4Stack=true");
  90. arguments.add("-Dfml.ignoreInvalidMinecraftCertificates=true");
  91. arguments.add("-Dsun.net.client.defaultConnectTimeout=9999");
  92. arguments.add("-Dsun.net.client.defaultReadTimeout=9999");
  93. arguments.add("-Dsun.net.http.retryPost=true");
  94. if (server != null) {
  95. arguments.add("-Dvoidlauncher.server=" + server);
  96. }
  97. arguments.add("-Dlog4j2.formatMsgNoLookups=true");
  98. try {
  99. if (version >= 1710 || version <= 180) {
  100. arguments.add("-Dlog4j.configurationFile=log4j2_17-111.xml");
  101. final File file2 = new File(modpack.getWorkingDirectory().getAbsolutePath(), "log4j2_17-111.xml");
  102. if (!file2.exists()) {
  103. final BufferedInputStream br = new BufferedInputStream(new URL("https://vl4.voidswrath.com/releases/log4j2_17-111.xml").openConnection().getInputStream());
  104. final BufferedOutputStream bw = new BufferedOutputStream(new FileOutputStream(file2));
  105. final byte[] bytes = new byte[4095];
  106. int read = 0;
  107. while ((read = br.read(bytes)) >= 0) {
  108. bw.write(bytes, 0, read);
  109. }
  110. bw.flush();
  111. br.close();
  112. bw.close();
  113. }
  114. }
  115. else {
  116. arguments.add("-Dlog4j.configurationFile=log4j2_112-116.xml");
  117. final File file2 = new File(modpack.getWorkingDirectory().getAbsolutePath(), "log4j2_112-116.xml");
  118. if (!file2.exists()) {
  119. final BufferedInputStream br = new BufferedInputStream(new URL("https://vl4.voidswrath.com/releases/log4j2_112-116.xml").openConnection().getInputStream());
  120. final BufferedOutputStream bw = new BufferedOutputStream(new FileOutputStream(file2));
  121. final byte[] bytes = new byte[4095];
  122. int read = 0;
  123. while ((read = br.read(bytes)) >= 0) {
  124. bw.write(bytes, 0, read);
  125. }
  126. bw.flush();
  127. br.close();
  128. bw.close();
  129. }
  130. }
  131. }
  132. catch (Throwable ex) {
  133. ex.printStackTrace();
  134. }
  135. if (version < 162) {
  136. arguments.add("-Djava.library.path=" + binpath + "natives");
  137. 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);
  138. arguments.add("-Xms" + String.valueOf(minMem) + "M");
  139. arguments.add("-Xmx" + String.valueOf(maxMem) + "M");
  140. if (VoidLauncher.instance.cbPermFix.isSelected()) {
  141. arguments.add("-XX:MaxPermSize=256M");
  142. }
  143. arguments.add("-XX:+UseParallelGC");
  144. arguments.add("-XX:ParallelGCThreads=" + Math.max(1, VoidLauncher.cores / 2));
  145. arguments.add("-XX:+UseSplitVerifier");
  146. arguments.add("-XX:+FailOverToOldVerifier");
  147. arguments.add("-XX:-HeapDumpOnOutOfMemoryError");
  148. arguments.add("-XX:+UseCompressedOops");
  149. arguments.add("-XX:+ScavengeBeforeFullGC");
  150. arguments.add("-XX:+PrintCommandLineFlags");
  151. arguments.add("-cp");
  152. arguments.add(cp.toString());
  153. arguments.add("net.minecraft.client.Minecraft");
  154. arguments.add(login.ingameName);
  155. if (!login.accessToken.equals("offline")) {
  156. arguments.add(login.accessToken);
  157. }
  158. }
  159. else {
  160. arguments.add("-Djava.library.path=" + binpath + "natives");
  161. arguments.add("-Xms" + String.valueOf(minMem) + "M");
  162. arguments.add("-Xmx" + String.valueOf(maxMem) + "M");
  163. if (VoidLauncher.instance.cbPermFix.isSelected()) {
  164. arguments.add("-XX:MaxPermSize=256M");
  165. }
  166. arguments.add("-XX:+UseParallelGC");
  167. arguments.add("-XX:ParallelGCThreads=" + Math.max(1, VoidLauncher.cores / 2));
  168. arguments.add("-XX:+UseSplitVerifier");
  169. arguments.add("-XX:+FailOverToOldVerifier");
  170. arguments.add("-XX:-HeapDumpOnOutOfMemoryError");
  171. arguments.add("-XX:+UseCompressedOops");
  172. arguments.add("-XX:+ScavengeBeforeFullGC");
  173. arguments.add("-XX:+PrintCommandLineFlags");
  174. if (new File(modpack.getWorkingDirectory(), "bin").listFiles() == null) {
  175. System.out.println("Detected incomplete install...reinstalling.");
  176. VoidConfig.applyPendingInstall(modpack);
  177. if (modpack instanceof ModPack) {
  178. VoidLauncher.shared.execute(new Runnable() {
  179. @Override
  180. public void run() {
  181. try {
  182. final URL configs = new URL(MinecraftLauncher.urlEncode("https://vl4.voidswrath.com/" + ((ModPack)modpack).Mods.get("CONFIGS").get("URL").toString()));
  183. final String configMD5 = ((ModPack)modpack).Mods.get("CONFIGS").get("MD5").toString();
  184. Downloader.startModPack((ModPack)modpack, configs, configMD5, true, (String)null);
  185. }
  186. catch (Throwable ex) {
  187. ex.printStackTrace();
  188. }
  189. }
  190. });
  191. }
  192. return;
  193. }
  194. final File[] listFiles2;
  195. File[] arrayOfFile1 = listFiles2 = new File(modpack.getWorkingDirectory(), "bin").listFiles();
  196. for (final File file3 : listFiles2) {
  197. if (!file3.isDirectory() && file3.getName().endsWith(".jar")) {
  198. cp.append("bin").append(separator).append(file3.getName()).append(pathseperator);
  199. }
  200. }
  201. if (new File(modpack.getWorkingDirectory(), "bin" + separator + "lib").listFiles() == null) {
  202. System.out.println("Detected incomplete install...reinstalling.");
  203. VoidConfig.applyPendingInstall(modpack);
  204. if (modpack instanceof ModPack) {
  205. VoidLauncher.shared.execute(new Runnable() {
  206. @Override
  207. public void run() {
  208. try {
  209. final URL configs = new URL(MinecraftLauncher.urlEncode("https://vl4.voidswrath.com/" + ((ModPack)modpack).Mods.get("CONFIGS").get("URL").toString()));
  210. final String configMD5 = ((ModPack)modpack).Mods.get("CONFIGS").get("MD5").toString();
  211. Downloader.startModPack((ModPack)modpack, configs, configMD5, true, (String)null);
  212. }
  213. catch (Throwable ex) {
  214. ex.printStackTrace();
  215. }
  216. }
  217. });
  218. }
  219. return;
  220. }
  221. final File[] listFiles3;
  222. arrayOfFile1 = (listFiles3 = new File(modpack.getWorkingDirectory(), "bin" + separator + "lib").listFiles());
  223. for (final File file3 : listFiles3) {
  224. if (!file3.isDirectory() && file3.getName().endsWith(".jar")) {
  225. cp.append("bin").append(separator).append("lib").append(separator).append(file3.getName()).append(pathseperator);
  226. }
  227. else if (version == 1164 && file3.isDirectory()) {
  228. cp.append(getJars(modpack.getWorkingDirectory(), file3));
  229. }
  230. }
  231. arguments.add("-cp");
  232. 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");
  233. if (version == 1164) {
  234. arguments.add("cpw.mods.modlauncher.Launcher");
  235. }
  236. else {
  237. arguments.add("net.minecraft.launchwrapper.Launch");
  238. }
  239. arguments.add("--username");
  240. arguments.add(login.ingameName);
  241. if (version >= 1710) {
  242. arguments.add("--accessToken");
  243. if (!login.accessToken.equals("offline")) {
  244. arguments.add(login.accessToken);
  245. arguments.add("--uuid");
  246. arguments.add(login.uuid);
  247. }
  248. else {
  249. arguments.add("null");
  250. }
  251. arguments.add("--version");
  252. arguments.add("1.7.10");
  253. arguments.add("--assetIndex");
  254. arguments.add("1.7.10");
  255. arguments.add("--tweakClass");
  256. arguments.add("cpw.mods.fml.common.launcher.FMLTweaker");
  257. }
  258. else if (version >= 1164) {
  259. arguments.add("--accessToken");
  260. if (!login.accessToken.equals("offline")) {
  261. arguments.add(login.accessToken);
  262. arguments.add("--uuid");
  263. arguments.add(login.uuid);
  264. }
  265. else {
  266. arguments.add("null");
  267. }
  268. }
  269. else if (version >= 180) {
  270. arguments.add("--accessToken");
  271. if (!login.accessToken.equals("offline")) {
  272. arguments.add(login.accessToken);
  273. arguments.add("--uuid");
  274. arguments.add(login.uuid);
  275. }
  276. else {
  277. arguments.add("null");
  278. }
  279. arguments.add("--version");
  280. arguments.add("1.8");
  281. arguments.add("--assetIndex");
  282. arguments.add("1.8");
  283. arguments.add("--tweakClass");
  284. arguments.add("net.minecraftforge.fml.common.launcher.FMLTweaker");
  285. }
  286. else if (version >= 172) {
  287. arguments.add("--accessToken");
  288. if (!login.accessToken.equals("offline")) {
  289. arguments.add(login.accessToken);
  290. arguments.add("--uuid");
  291. arguments.add(login.uuid);
  292. }
  293. else {
  294. arguments.add("null");
  295. }
  296. arguments.add("--version");
  297. arguments.add("1.7.2");
  298. arguments.add("--tweakClass");
  299. arguments.add("cpw.mods.fml.common.launcher.FMLTweaker");
  300. }
  301. else {
  302. arguments.add("--session");
  303. if (!login.accessToken.equals("offline")) {
  304. arguments.add(login.accessToken);
  305. }
  306. else {
  307. arguments.add("null");
  308. }
  309. arguments.add("--version");
  310. arguments.add("minecraft");
  311. arguments.add("--tweakClass");
  312. arguments.add("cpw.mods.fml.common.launcher.FMLTweaker");
  313. }
  314. arguments.add("--gameDir");
  315. arguments.add(modpack.getWorkingDirectory().getAbsolutePath());
  316. arguments.add("--assetsDir");
  317. arguments.add(modpack.getWorkingDirectory().getAbsolutePath() + separator + "assets");
  318. }
  319. try {
  320. final File file2 = new File(modpack.getWorkingDirectory(), "additionalCmdLine.txt");
  321. if (file2.exists()) {
  322. final BufferedReader br2 = new BufferedReader(new InputStreamReader(new FileInputStream(file2)));
  323. String arg;
  324. while ((arg = br2.readLine()) != null) {
  325. arg = arg.trim();
  326. if (arg.length() > 0) {
  327. final String[] split;
  328. final String[] args = split = arg.split(Pattern.quote(" "));
  329. for (final String a : split) {
  330. arguments.add(a);
  331. }
  332. }
  333. }
  334. br2.close();
  335. }
  336. }
  337. catch (Throwable t) {}
  338. System.out.println(arguments);
  339. (MinecraftLauncher.pb = new ProcessBuilder(arguments).directory(modpack.getWorkingDirectory())).redirectErrorStream(true);
  340. try {
  341. VoidLauncher.instance.setState(1);
  342. }
  343. catch (Throwable t2) {}
  344. MinecraftLauncher.exitcode = -1337;
  345. System.currentTimeMillis();
  346. try {
  347. final Process process = MinecraftLauncher.pb.start();
  348. MinecraftLauncher.exitcode = -1337;
  349. VoidConfig.applySuccessfulModpack(modpack);
  350. System.gc();
  351. VoidLauncher.shared.execute(new Runnable() {
  352. final InputStream is = process.getInputStream();
  353. final InputStreamReader isr = new InputStreamReader(this.is);
  354. final BufferedReader br = new BufferedReader(this.isr);
  355.  
  356. @Override
  357. public void run() {
  358. VoidLauncher.shared.execute(new Runnable() {
  359. @Override
  360. public void run() {
  361. String line = "";
  362. try {
  363. do {
  364. if (!line.isEmpty()) {
  365. System.out.println(line);
  366. }
  367. try {
  368. while (MinecraftLauncher.exitcode == -1337) {
  369. if (Runnable.this.br.ready() && Runnable.this.isr.ready() && Runnable.this.is.available() != 0) {
  370. break;
  371. }
  372. }
  373. }
  374. catch (IOException ex) {
  375. if (!ex.getMessage().contains("Stream closed")) {
  376. ex.printStackTrace();
  377. }
  378. }
  379. catch (Exception ex2) {
  380. ex2.printStackTrace();
  381. }
  382. if (MinecraftLauncher.exitcode != -1337) {
  383. break;
  384. }
  385. } while ((line = Runnable.this.br.readLine()) != null);
  386. }
  387. catch (Throwable ex3) {
  388. ex3.printStackTrace();
  389. }
  390. }
  391. });
  392. while (MinecraftLauncher.exitcode == -1337) {
  393. try {
  394. Thread.sleep(2L);
  395. MinecraftLauncher.exitcode = process.exitValue();
  396. process.destroy();
  397. }
  398. catch (Exception ex) {}
  399. }
  400. try {
  401. this.br.close();
  402. }
  403. catch (IOException e) {
  404. e.printStackTrace();
  405. }
  406. }
  407. });
  408. }
  409. catch (Throwable exasdasdas) {
  410. exasdasdas.printStackTrace();
  411. }
  412. }
  413. }
  414.  
  415. private static void getJars(final File file, final List<File> list) {
  416. for (final File ff : file.listFiles()) {
  417. if (ff.isDirectory()) {
  418. getJars(ff, list);
  419. }
  420. else if (ff.getName().toLowerCase().endsWith(".jar")) {
  421. list.add(ff);
  422. }
  423. }
  424. }
  425.  
  426. private static String getJars(final File root, final File file) {
  427. String ret = "";
  428. final List<File> jars = new ArrayList<File>();
  429. getJars(file, jars);
  430. for (final File f : jars) {
  431. ret = ret + f.getPath().replace(root.getPath() + File.separator, "") + File.pathSeparator;
  432. }
  433. return ret;
  434. }
  435. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement