Exemple #1
0
  // <editor-fold defaultstate="collapsed" desc="Game Launch">
  void genLaunchCode(final Consumer<GameLauncher> listener) {
    if (isLaunching) return;
    isLaunching = true;
    HMCLog.log("Start generating launching command...");
    File file = getCurrentProfile().getCanonicalGameDirFile();
    if (!file.exists()) {
      HMCLog.warn("The minecraft path is wrong, please check it yourself.");
      MessageBox.Show(C.i18n("minecraft.wrong_path"));
      return;
    }
    final String name = (String) cboProfiles.getSelectedItem();
    if (StrUtils.isBlank(name) || getCurrentProfile().getSelectedMinecraftVersion() == null) {
      HMCLog.warn("There's no selected version, rechoose a version.");
      MessageBox.Show(C.i18n("minecraft.no_selected_version"));
      return;
    }

    final int index = cboLoginMode.getSelectedIndex();
    if (index < 0 || index >= IAuthenticator.LOGINS.size()) {
      HMCLog.warn("There's no login method.");
      MessageBox.Show(C.i18n("login.methods.no_method"));
      return;
    }
    final IAuthenticator l = IAuthenticator.LOGINS.get(index);
    final LoginInfo li =
        new LoginInfo(
            Settings.getInstance().getUsername(),
            l.isLoggedIn() || l.isHidePasswordBox() ? null : new String(txtPassword.getPassword()));
    Thread t =
        new Thread() {
          @Override
          public void run() {
            Thread.currentThread().setName("Game Launcher");
            DefaultGameLauncher gl =
                new DefaultGameLauncher(
                    getCurrentProfile(), li, l, Settings.getInstance().getDownloadSource());
            gl.failEvent.register(
                (sender, s) -> {
                  if (s != null) MessageBox.Show(s);
                  MainFrame.instance.closeMessage();
                  isLaunching = false;
                  return true;
                });
            gl.successEvent.register(
                (sender, s) -> {
                  isLaunching = false;
                  return true;
                });
            listener.accept(gl);
            gl.makeLaunchCommand();
          }
        };
    t.start();
  }
Exemple #2
0
 void loadMinecraftVersions() {
   isLoading = true;
   cboVersions.removeAllItems();
   int index = 0, i = 0;
   if (getCurrentProfile() != null) {
     getCurrentProfile().getMinecraftProvider().refreshVersions();
     MinecraftVersion selVersion = getCurrentProfile().getSelectedMinecraftVersion();
     String selectedMC = selVersion == null ? null : selVersion.id;
     if (getCurrentProfile().getMinecraftProvider().getVersions().isEmpty()) {
       if (!showedNoVersion)
         SwingUtilities.invokeLater(
             () -> {
               if (MessageBox.Show(C.i18n("mainwindow.no_version"), MessageBox.YES_NO_OPTION)
                   == MessageBox.YES_OPTION) {
                 MainFrame.instance.selectTab("game");
                 MainFrame.instance.gamePanel.showGameDownloads();
               }
               showedNoVersion = true;
             });
     } else {
       for (MinecraftVersion mcVersion :
           getCurrentProfile().getMinecraftProvider().getVersions()) {
         if (mcVersion.hidden) continue;
         cboVersions.addItem(mcVersion.id);
         if (mcVersion.id.equals(selectedMC)) index = i;
         i++;
       }
       if (index < cboVersions.getItemCount()) cboVersions.setSelectedIndex(index);
     }
   }
   isLoading = false;
 }
Exemple #3
0
  public static void main(String[] args) {
    Thread.currentThread().setName("launcher");
    println("*** " + Main.makeTitle() + " ***");

    LogWindow.instance.setTerminateGame(Utils::shutdownForcely);

    boolean showInfo = false;
    String classPath = "";
    String mainClass = "net.minecraft.client.Minecraft";

    ArrayList<String> cmdList = new ArrayList<>();

    for (String s : args)
      if (s.startsWith("-cp=")) classPath = classPath.concat(s.substring("-cp=".length()));
      else if (s.startsWith("-mainClass=")) mainClass = s.substring("-mainClass=".length());
      else if (s.equals("-debug")) showInfo = true;
      else cmdList.add(s);

    String[] cmds = (String[]) cmdList.toArray(new String[cmdList.size()]);

    String[] tokenized = StrUtils.tokenize(classPath, File.pathSeparator);
    int len = tokenized.length;

    if (showInfo) {
      try {
        File logFile = new File("hmclmc.log");
        if (!logFile.exists()) logFile.createNewFile();
        FileOutputStream tc = new FileOutputStream(logFile);
        DoubleOutputStream out = new DoubleOutputStream(tc, System.out);
        System.setOut(new LauncherPrintStream(out));
        DoubleOutputStream err = new DoubleOutputStream(tc, System.err);
        System.setErr(new LauncherPrintStream(err));
      } catch (Exception e) {
        println("Failed to add log file appender.");
        e.printStackTrace();
      }

      println("Arguments: {\n" + StrUtils.parseParams("    ", args, "\n") + "\n}");
      println("Main Class: " + mainClass);
      println("Class Path: {\n" + StrUtils.parseParams("    ", tokenized, "\n") + "\n}");
      SwingUtilities.invokeLater(() -> LogWindow.instance.setVisible(true));
    }

    URL[] urls = new URL[len];

    try {
      for (int j = 0; j < len; j++) urls[j] = new File(tokenized[j]).toURI().toURL();
    } catch (Throwable e) {
      MessageBox.Show(C.i18n("crash.main_class_not_found"));
      println("Failed to get classpath.");
      e.printStackTrace();
      return;
    }

    if (!JdkVersion.isJava64Bit() && Platform.getPlatform() == Platform.BIT_64)
      MessageBox.Show(C.i18n("advice.os64butjdk32"));

    Method minecraftMain;
    try {
      minecraftMain =
          new URLClassLoader(urls).loadClass(mainClass).getMethod("main", String[].class);
    } catch (ClassNotFoundException | NoSuchMethodException | SecurityException t) {
      MessageBox.Show(C.i18n("crash.main_class_not_found"));
      println("Minecraft main class not found.");
      t.printStackTrace();
      return;
    }

    println("*** Launching Game ***");

    try {
      minecraftMain.invoke(null, new Object[] {cmds});
    } catch (Throwable throwable) {
      HMCLog.err("Cought exception!");
      String trace = StrUtils.getStackTrace(throwable);
      final String advice = MinecraftCrashAdvicer.getAdvice(trace);
      MessageBox.Show(C.i18n("crash.minecraft") + ": " + advice);

      LogWindow.instance.log(C.i18n("crash.minecraft"));
      LogWindow.instance.log(advice);
      LogWindow.instance.log(trace);
      LogWindow.instance.setExit(TrueFunction.instance);
      LogWindow.instance.setVisible(true);
    }

    println("*** Game Exited ***");
  }