private string BuildArgs(GameVersion MC, string sPackName, Dictionary <string, string> ClassPath)
        {
            string               args      = null;
            string               classpath = null;
            Configuration        C         = new Configuration();
            Manager              U         = new Manager();
            MCUserAccount        Acc       = U.GetAccount(U.GetDefault());
            MCUserAccountProfile Profile   = U.GetActiveProfile(Acc);

            // Garbage Collector
            if (C.UseGC == 1)
            {
                args += " -XX:SurvivorRatio=2 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts";
            }

            // force 64bit
            if (C.GetJavaArch() == "64")
            {
                args += " -d64";
            }

            // Java Memory
            args += string.Format(" -Xms{0}m -Xmx{1}m -Xmn128m", C.MinimumMemory, C.MaximumMemory);

            if (MC.Arguments != null)
            {
                // JVM
                foreach (JvmElement jvme in MC.Arguments.Jvm)
                {
                    if (jvme.JvmClass != null)
                    {
                        // skip non windows libraries
                        if (jvme.JvmClass.Rules != null)
                        {
                            bool bWindows = false;
                            foreach (JvmRule Rule in jvme.JvmClass.Rules)
                            {
                                if (Rule.Action == "allow")
                                {
                                    if (Rule.Os == null)
                                    {
                                        bWindows = true;
                                    }
                                    else if (Rule.Os.Name == null || Rule.Os.Name == "windows")
                                    {
                                        bWindows = true;
                                        // check version
                                        if (Rule.Os.Version != null)
                                        {
                                            string text = Environment.OSVersion.Version.ToString();
                                            Regex  r    = new Regex(Rule.Os.Version, RegexOptions.IgnoreCase);
                                            Match  m    = r.Match(text);
                                            if (!m.Success)
                                            {
                                                bWindows = false;
                                            }
                                        }

                                        //check Arch
                                        if (Rule.Os.Arch != null)
                                        {
                                            if (Rule.Os.Arch == "x86" && C.GetJavaArch() == "64")
                                            {
                                                bWindows = false;
                                            }
                                        }
                                    }
                                }
                                if (Rule.Action == "disallow" && Rule.Os.Name == "windows")
                                {
                                    bWindows = false;
                                }
                            }
                            if (bWindows == false)
                            {
                                continue;
                            }
                        }

                        // one value
                        if (jvme.JvmClass.Value.String != null)
                        {
                            args += " " + jvme.JvmClass.Value.String;
                        }

                        // multiple values

                        if (jvme.JvmClass.Value.StringArray != null)
                        {
                            foreach (string value in jvme.JvmClass.Value.StringArray)
                            {
                                // fix spaces in Json path
                                if (value.Split('=').Last().Contains(" "))
                                {
                                    args += " " + value.Split('=').First() + "=\"" + value.Split('=').Last() + "\"";
                                }
                                else
                                {
                                    args += " " + value;
                                }
                            }
                        }
                    }
                    else
                    {
                        args += " " + jvme.String;
                    }
                }

                // startup class
                args += " " + MC.MainClass;

                // Game
                foreach (GameElement ge in MC.Arguments.Game)
                {
                    if (ge.GameClass != null)
                    {
                    }
                    else
                    {
                        args += " " + ge.String;
                    }
                }
            }
            else
            {
                // f*****g Mojang drivers Hack
                args += " -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump";
                // Tweaks (forge)
                args += " -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true";
                // Path to natives
                args += " -Djava.library.path=${natives_directory}";
                // Libs
                args += " -cp ${classpath}";
                // startup class
                args += " " + MC.MainClass;
                // minecraft arguments
                args += " " + MC.MinecraftArguments;
            }

            // libraries
            foreach (KeyValuePair <string, string> entry in ClassPath)
            {
                classpath += string.Format("\"{0}\";", entry.Value);
            }

            // version .jar
            classpath += string.Format("\"{0}\\{1}\\{1}.jar\" ", _sVersionDir, MC.Id);

            // fill placeholders
            args = args.Replace("${auth_player_name}", Profile.name);

            if (isForge)
            {
                args = args.Replace("${version_name}", MC.Id + "-forge" + forgeVersion.Replace(MC.Id, ""));
            }
            else
            {
                args = args.Replace("${version_name}", MC.Id);
            }
            args = args.Replace("${game_directory}", string.Format("\"{0}\\{1}\\minecraft\"", _sPacksDir, sPackName));
            args = args.Replace("${assets_root}", string.Format("\"{0}\"", _sAssetsDir));
            args = args.Replace("${game_assets}", string.Format("\"{0}\\virtual\\legacy\"", _sAssetsDir));
            args = args.Replace("${assets_index_name}", MC.Assets);
            args = args.Replace("${auth_uuid}", Profile.id);
            args = args.Replace("${auth_access_token}", Acc.accessToken);
            args = args.Replace("${auth_session}", string.Format("token:{0}:{1}", Acc.accessToken, Profile.id));
            args = args.Replace("${user_properties}", "{}");
            args = args.Replace("${user_type}", "Mojang");
            args = args.Replace("${version_type}", MC.Type);
            args = args.Replace("${natives_directory}", "\"" + _sNativesDir + @"\" + MC.Id + "\"");
            args = args.Replace("${classpath}", classpath);
            args = args.Replace("${launcher_name}", Application.ProductName);
            args = args.Replace("${launcher_version}", Application.ProductVersion);

            return(args);
        }
Exemple #2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool refreshUser = (bool)e.Argument;   // the 'argument' parameter resurfaces here


            BackgroundWorker worker = sender as BackgroundWorker;

            // Check Environment
            Launcher L = new Launcher(Offline);
            Manager  U = new Manager();

            L.CheckDirectories();

            // Test User
            string MCPlayerName = null;
            string UserAccount  = "none";
            string MCUID        = null;

            worker.ReportProgress(25);


            if (refreshUser == true)
            {
                if (U.GetDefault() != Guid.Empty)
                {
                    // Get Account
                    MCUserAccount Account = U.GetAccount(U.GetDefault());

                    // Validate Account
                    AuthHandler A = new AuthHandler();
                    try
                    {
                        Account.accessToken = A.Refresh(Account.accessToken, Account.clientToken);
                        U.SaveAccount(Account);
                    }
                    catch (MCInvalidTokenException)
                    {
                        FrmRefreshToken fTokRefresh = new FrmRefreshToken(Account);
                        DialogResult    res         = fTokRefresh.ShowDialog();
                        if (res == DialogResult.Cancel)
                        {
                            U.SetDefault(Guid.Empty);
                        }
                        fTokRefresh.Dispose();
                    }
                    catch (Exception)
                    {
                        DialogResult res = DialogResult.No;
                        Invoke(new Action(() =>
                        {
                            res = MessageBox.Show(this, "In Offlinemodus wechseln?", "Verbindungsfehler zu Mojang!", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                        }));

                        if (res == DialogResult.Yes)
                        {
                            Offline = true;
                            Invoke(new Action(() =>
                            {
                                MnuAccounts.Enabled = false;
                            }));
                        }
                        else
                        {
                            U.SetDefault(Guid.Empty);
                        }
                    }
                }
            }

            if (U.GetDefault() != Guid.Empty)
            {
                MCPlayerName = U.GetPlayerName(U.GetDefault());
                MCUID        = U.GetMCProfileID(U.GetDefault());
                UserAccount  = U.GetAccount(U.GetDefault()).username;
            }
            // set statusbar
            Invoke(new Action(() =>
            {
                LblDefaultAccount.Text = UserAccount;
                LstPacks.Clear();
                lst_packs_images.Images.Clear();
            }));

            worker.ReportProgress(50);

            // Get Packs from Server
            try
            {
                if (Offline == false)
                {
                    L.LoadAvailablePacks(MCPlayerName, MCUID);
                    MCAvailablePacks packs = L.GetAvailablePacks();
                    if (packs.Packs != null)
                    {
                        foreach (MCAvailablePack Pack in packs.Packs)
                        {
                            ListViewItem LvItem = new ListViewItem(Pack.Name, Pack.Name)
                            {
                                Font = new Font("Thaoma", 16, FontStyle.Bold)
                            };
                            Invoke(new Action(() =>
                            {
                                lst_packs_images.Images.Add(Pack.Name, L.GetPackIcon(Pack));
                                LstPacks.Items.Add(LvItem);
                            }));
                        }
                    }
                }
                else
                {
                    L.LoadInstalledPacks();
                    MCPacksInstalled Packs = L.GetInstalledPacks();
                    if (Packs.packs != null)
                    {
                        foreach (MCPacksInstalledPack Pack in Packs.packs)
                        {
                            ListViewItem LvItem = new ListViewItem(Pack.Name, Pack.Name)
                            {
                                Font = new Font("Thaoma", 16, FontStyle.Bold)
                            };
                            Invoke(new Action(() =>
                            {
                                if (L.GetPackIconOffline(Pack) != null)
                                {
                                    lst_packs_images.Images.Add(Pack.Name, L.GetPackIconOffline(Pack));
                                }
                                LstPacks.Items.Add(LvItem);
                            }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Invoke(new Action(() =>
                {
                    MessageBox.Show(this, ex.Message.ToString(), "Verbindungsfehler zu Minestar!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }));
            }
            worker.ReportProgress(75);

            // Load installed Packs
            L.LoadInstalledPacks();

            // end worker
            worker.ReportProgress(100);
            System.Threading.Thread.Sleep(500);
        }