Exemplo n.º 1
0
        private void loadLvl(object sender, EventArgs e)
        {
            ll.Items.Clear();
            string sv = lvs.SelectedItem.ToString() + "-";

            sv = sv.Substring(0, sv.IndexOf("-"));
            jo = new JSONObject(File.ReadAllText(Application.StartupPath + "\\lvl.json")).getJSONObject("versions").getJSONObject(sv);
            if (jo.Contains("artefacts"))
            {
                JSONObject stable = jo.getJSONObject("artefacts").getJSONObject("com.mumfrey:liteloader");
                var        keys   = stable.getKeys();
                foreach (string key in keys)
                {
                    if (key == "latest")
                    {
                        continue;
                    }
                    ll.Items.Add(stable.getJSONObject(key).getString("version"));
                }
            }
            if (jo.Contains("snapshots"))
            {
                JSONObject snapshot = jo.getJSONObject("snapshots").getJSONObject("com.mumfrey:liteloader");
                var        keys     = snapshot.getKeys();
                foreach (string key in keys)
                {
                    if (key == "latest")
                    {
                        continue;
                    }
                    ll.Items.Add(snapshot.getJSONObject(key).getString("version"));
                }
            }
        }
Exemplo n.º 2
0
        private void button7_Click(object sender, EventArgs e)
        {
            string sv = lvs.SelectedItem.ToString() + "-";

            sv = sv.Substring(0, sv.IndexOf("-"));
            if (ll.SelectedIndex != -1)
            {
                if (jo.Contains("artefacts"))
                {
                    JSONObject stable = jo.getJSONObject("artefacts").getJSONObject("com.mumfrey:liteloader");
                    var        keys   = stable.getKeys();
                    foreach (string key in keys)
                    {
                        if (key == "latest")
                        {
                            continue;
                        }
                        if (stable.getJSONObject(key).getString("version") == ll.SelectedItem.ToString())
                        {
                            TaskToDo t = new TaskToDo();
                            t.Type  = "Download";
                            t.param = String.Format("http://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/{0}/liteloader-{1}.jar;" + Application.StartupPath + "\\liteloader-{1}.jar", sv, ll.SelectedItem.ToString());
                            TaskToDo t2 = new TaskToDo();
                            t2.Type            = "InstallLiteLoader";
                            t2.param           = ll.SelectedItem.ToString() + ";" + lvs.SelectedItem.ToString();
                            st                 = new ShowTask(new TaskToDo[] { t, t2 });
                            st.onTaskComplete += new EventHandler(changeDSourcel);
                            st.beginTask();
                        }
                    }
                }
                if (jo.Contains("snapshots"))
                {
                    JSONObject snapshot = jo.getJSONObject("snapshots").getJSONObject("com.mumfrey:liteloader");
                    var        keys     = snapshot.getKeys();
                    foreach (string key in keys)
                    {
                        if (key == "latest")
                        {
                            continue;
                        }
                        if (snapshot.getJSONObject(key).getString("version") == ll.SelectedItem.ToString())
                        {
                            l_snap = true;
                            TaskToDo t = new TaskToDo();
                            t.Type  = "Download";
                            t.param = String.Format("http://dl.liteloader.com/versions/com/mumfrey/liteloader/{0}/liteloader-{0}.jar;" + Application.StartupPath + "\\liteloader-{0}.jar", ll.SelectedItem.ToString());
                            TaskToDo t2 = new TaskToDo();
                            t2.Type            = "InstallLiteLoader";
                            t2.param           = ll.SelectedItem.ToString() + ";" + lvs.SelectedItem.ToString();
                            st                 = new ShowTask(new TaskToDo[] { t, t2 });
                            st.onTaskComplete += new EventHandler(changeDSourcel);
                            st.beginTask();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public LauncherReturn LaunchMC(MCLaunchArgs argument, YggDrasilAuth auth, int whatToReturn = 0)
        {
            auth.Login();
            LauncherReturn    lr     = new LauncherReturn();
            JSONObject        jo     = new JSONObject(File.ReadAllText(argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\versions\\" + argument.VerName + "\\" + argument.VerName + ".json"));
            String            Libcmd = "";
            List <JSONObject> libs   = new List <JSONObject>();

            libs.AddRange(jo.getJSONArray("libraries").toJSONObjects());
            JSONObject ji  = jo;
            string     jar = argument.VerName;

            #region 处理继承
            if (jo.Contains("inheritsFrom"))
            {
                jar = jo.getString("jar");
                ji  = new JSONObject(File.ReadAllText(argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\versions\\" + jo.getString("inheritsFrom") + "\\" + jo.getString("inheritsFrom") + ".json"));
                libs.AddRange(ji.getJSONArray("libraries").toJSONObjects());
                if (ji.Contains("inheritsFrom"))
                {
                    ji = new JSONObject(File.ReadAllText(argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\versions\\" + ji.getString("inheritsFrom") + "\\" + ji.getString("inheritsFrom") + ".json"));
                    libs.AddRange(ji.getJSONArray("libraries").toJSONObjects());
                    if (ji.Contains("inheritsFrom"))
                    {
                        ji = new JSONObject(File.ReadAllText(argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\versions\\" + ji.getString("inheritsFrom") + "\\" + ji.getString("inheritsFrom") + ".json"));
                        libs.AddRange(ji.getJSONArray("libraries").toJSONObjects());
                    }
                }
            }
            #endregion
            #region 处理库
            String          lnsuffix = "";
            List <TaskToDo> tl       = new List <TaskToDo>();
            foreach (JSONObject libdata in libs)
            {
                String[] libname = libdata.getString("name").Split(":".ToCharArray());
                if (libdata.Contains("natives") && libdata.getJSONObject("natives").Contains("windows"))
                {
                    lnsuffix = "-" + libdata.getJSONObject("natives").getString("windows");
                    lnsuffix = lnsuffix.Replace("${arch}", "32");
                }
                String libpath = argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\libraries\\" + libname[0].Replace(".", "\\") + "\\" + libname[1] + "\\" + libname[2] + "\\" + libname[1] + "-" + libname[2] + lnsuffix + ".jar";
                if (Libcmd.Contains(libpath))
                {
                    continue;
                }
                if (File.Exists(libpath))
                {
                    if (libdata.Contains("extract"))
                    {
                        Unzipper.decompress(libpath, argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\versions\\" + argument.VerName + "\\" + argument.VerName + "-natives");
                    }
                    else
                    {
                        Libcmd = Libcmd + libpath + ";";
                    }
                }
                else
                {
                    TaskToDo ttd = new TaskToDo();
                    ttd.Type  = "Download";
                    ttd.param = "http://bmclapi2.bangbang93.com/libraries/" + libname[0].Replace(".", "/") + "/" + libname[1] + "/" + libname[2] + "/" + libname[1] + "-" + libname[2] + lnsuffix + ".jar;" + libpath;
                    tl.Add(ttd);
                }
                lnsuffix = "";
            }
            #endregion
            #region 处理资源文件
            bool virt = false;
            if (jo.Contains("assets") && !jo.Contains("assetIndex"))
            {
                var I = new JSONObject();
                I.putString("id", jo.getString("assets"));
                jo.putJSONObject("assetIndex", I);
                ji = jo;
            }
            if (!File.Exists(argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\assets\\indexes\\" + ji.getJSONObject("assetIndex").getString("id") + ".json"))
            {
                TaskToDo tt = new TaskToDo();
                tt.Type  = "Download";
                tt.param = ji.getJSONObject("assetIndex").getString("url") + ";" + argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\assets\\indexes\\" + ji.getJSONObject("assetIndex").getString("id") + ".json";
                tl.Add(tt);
            }
            else
            {
                JSONObject    joa    = new JSONObject(File.ReadAllText(argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\assets\\indexes\\" + ji.getJSONObject("assetIndex").getString("id") + ".json"));
                List <string> files  = joa.getJSONObject("objects").getKeys();
                List <string> hashes = new List <string>();
                virt = joa.Contains("virtual");
                JSONObject job = joa.getJSONObject("objects");
                foreach (string keyf in files)
                {
                    hashes.Add(job.getJSONObject(keyf).getString("hash"));
                }
                bool   lackasset = false;
                string fp, nfp;
                nfp = argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\assets\\virtual\\" + ji.getJSONObject("assetIndex").getString("id");
                for (int j = 0; j < files.Count; j++)
                {
                    fp = argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\assets\\objects\\" + hashes[j].Substring(0, 2) + "\\" + hashes[j];
                    if (virt)
                    {
                        if (!File.Exists(nfp + "\\" + files[j].Replace("/", "\\")))
                        {
                            lackasset = true;
                            break;
                        }
                    }
                    else
                    {
                        if (!File.Exists(fp))
                        {
                            lackasset = true;
                            break;
                        }
                    }
                }
                if (lackasset)
                {
                    if (MessageBox.Show("资源文件不完整,是否补全?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        for (int j = 0; j < files.Count; j++)
                        {
                            if (virt)
                            {
                                if (!File.Exists(nfp + "\\" + files[j].Replace("/", "\\")))
                                {
                                    TaskToDo to = new TaskToDo();
                                    to.Type  = "Download";
                                    to.param = "http://bmclapi2.bangbang93.com/assets/" + hashes[j].Substring(0, 2) + "/" + hashes[j] + ";" + nfp + "\\" + files[j].Replace("/", "\\");
                                    tl.Add(to);
                                }
                            }
                            else
                            {
                                fp = argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\assets\\objects\\" + hashes[j].Substring(0, 2) + "\\" + hashes[j];
                                if (!File.Exists(fp))
                                {
                                    TaskToDo to = new TaskToDo();
                                    to.Type  = "Download";
                                    to.param = "http://bmclapi2.bangbang93.com/assets/" + hashes[j].Substring(0, 2) + "/" + hashes[j] + ";" + fp;
                                    tl.Add(to);
                                }
                            }
                        }
                    }
                }
            }
            #endregion
            if (tl.Count != 0)
            {
                ShowTask st = new ShowTask(tl.ToArray());
                st.yda  = auth;
                st.mcla = argument;
                st.wtr  = whatToReturn;
                if (whatToReturn == 0)
                {
                    st.onTaskCompleteA += new ShowTask.onTaskCompleteEventHandler(LaunchMC);
                }
                st.beginTask();
                lr.rtv = "缺少文件,正在下载。";
                return(lr);
            }
            try
            {
                Directory.Delete(argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\") + "\\versions\\" + argument.VerName + "\\" + argument.VerName + "-natives\\META-INF", true);
            }
            catch (DirectoryNotFoundException ex)
            {
            }
            Libcmd = Libcmd + argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\versions\\" + jar + "\\" + jar + ".jar";
            String RunCommand;
            if (auth.Nick != "")
            {
                argument.Nick = auth.Nick;
            }
            String minecraftArguments = "";
            if (jo.Contains("minecraftArguments"))
            {
                minecraftArguments = jo.getString("minecraftArguments");
            }
            else if (jo.Contains("arguments"))
            {
                JSONObject ag   = jo.getJSONObject("arguments");
                var        gmja = ag.getJSONArray("game");
                var        gl   = gmja.length();
                for (int l = 0; l < gl; l++)
                {
                    if (gmja.getString(l).Contains(","))
                    {
                        continue;
                    }
                    minecraftArguments = minecraftArguments + gmja.getString(l).Replace("\n", "").Replace(" ", "") + " ";
                }
                minecraftArguments = minecraftArguments.Substring(0, minecraftArguments.Length - 1);
            }
            minecraftArguments = minecraftArguments.Replace("${auth_player_name}", argument.Nick).Replace("${version_name}", "JuicyLauncher_2").Replace("${game_directory}", "\"" + argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\"").Replace("${assets_index_name}", ji.getJSONObject("assetIndex").getString("id")).Replace("${auth_uuid}", auth.uuid).Replace("${auth_access_token}", auth.accessToken).Replace("${user_type}", auth.UserType).Replace("${version_type}", "JuicyLauncher_2").Replace("${user_properties}", auth.userProperties.toString()).Replace("${game_assets}", "${assets_root}");

            if (virt == true)
            {
                minecraftArguments = minecraftArguments.Replace("${assets_root}", "\"" + argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\assets\\virtual\\" + ji.getJSONObject("assetIndex").getString("id") + "\"");
            }
            else
            {
                minecraftArguments = minecraftArguments.Replace("${assets_root}", "\"" + argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\assets\"");
            }
            RunCommand = "-Xmx" + argument.MaxMem.ToString() + "m -Djava.library.path=\"" + argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/") + "\\versions\\" + argument.VerName + "\\" + argument.VerName + "-natives\" " + argument.ExtraJreArgs + " -cp \"" + Libcmd + "\" " + jo.getString("mainClass") + " " + minecraftArguments + " " + argument.ExtraMCArgs;
            Process          p   = new Process();
            ProcessStartInfo psi = new ProcessStartInfo(argument.JrePath, RunCommand);
            psi.WorkingDirectory = argument.CurrentDir.Replace(".\\", Application.StartupPath + "\\").Replace("./", Application.StartupPath + "/");
            psi.UseShellExecute  = false;
            p.StartInfo          = psi;
            if (whatToReturn == 1)
            {
                lr.MCMain = p;
                return(lr);
            }
            p.Start();
            Application.Exit();
            return(lr);
        }
Exemplo n.º 4
0
        public void DoNext(object sender, AsyncCompletedEventArgs e)
        {
            string cd = new JSONObject(File.ReadAllText(Application.StartupPath + "\\JLConfig.json")).getString("CurrentDir").Replace(".\\", Application.StartupPath + "\\");

            if (i == tasks.Length)
            {
                wc.Dispose();
                if (onTaskComplete != null)
                {
                    onTaskComplete(null, null);
                }
                if (onTaskCompleteA != null)
                {
                    onTaskCompleteA(mcla, yda, wtr);
                }
                this.Close();
                return;
            }
            tl.SelectedIndex = i;
            if (tl.SelectedItem.ToString().StartsWith("下载"))
            {
                if (!Directory.GetParent(tasks[i].param.Split(";".ToCharArray())[1]).Exists)
                {
                    Directory.GetParent(tasks[i].param.Split(";".ToCharArray())[1]).Create();
                }
                wc.DownloadFileAsync(new Uri(tasks[i].param.Split(";".ToCharArray())[0]), tasks[i].param.Split(";".ToCharArray())[1]);
            }
            if (tl.SelectedItem.ToString().StartsWith("安装Forge"))
            {
                Unzipper.decompress(tasks[i].param.Split(";".ToCharArray())[0], Application.StartupPath + "\\ftmp");
                JSONObject ipf             = new JSONObject(File.ReadAllText(Application.StartupPath + "\\ftmp\\install_profile.json"));
                string     vername         = ipf.getJSONObject("install").getString("target");
                string     installPathBase = cd + "\\versions\\" + vername + "\\" + vername;
                if (!Directory.GetParent(installPathBase).Exists)
                {
                    Directory.GetParent(installPathBase).Create();
                }
                string   dist    = ipf.getJSONObject("install").getString("path");
                String[] libname = dist.Split(":".ToCharArray());
                string   dp      = libname[1] + "-" + libname[2];
                dist = cd + "\\libraries\\" + libname[0].Replace(".", "\\") + "\\" + libname[1] + "\\" + libname[2] + "\\" + dp + ".jar";
                if (!Directory.GetParent(dist).Exists)
                {
                    Directory.GetParent(dist).Create();
                }
                if (!ipf.getJSONObject("versionInfo").Contains("inheritsFrom"))
                {
                    File.Copy(cd + "\\versions\\" + tasks[i].param.Split(";".ToCharArray())[1] + "\\" + tasks[i].param.Split(";".ToCharArray())[1] + ".jar", installPathBase + ".jar");
                }
                File.WriteAllText(installPathBase + ".json", ipf.getJSONObject("versionInfo").toString());
                File.Copy(Application.StartupPath + "\\ftmp\\" + dp + "-universal.jar", dist, true);
                i++;
                DoNext(null, null);
                return;
            }
            if (tl.SelectedItem.ToString().StartsWith("安装LiteLoader"))
            {
                string sv = tasks[i].param.Split(";".ToCharArray())[1] + "-";
                sv = sv.Substring(0, sv.IndexOf("-"));
                JSONObject jo  = new JSONObject(File.ReadAllText(Application.StartupPath + "\\lvl.json")).getJSONObject("versions").getJSONObject(sv);
                JSONObject sjo = new JSONObject();
                if (jo.Contains("artefacts"))
                {
                    JSONObject stable = jo.getJSONObject("artefacts").getJSONObject("com.mumfrey:liteloader");
                    var        keys   = stable.getKeys();
                    foreach (string key in keys)
                    {
                        if (key == "latest")
                        {
                            continue;
                        }
                        if (stable.getJSONObject(key).getString("version") == tasks[i].param.Split(";".ToCharArray())[0])
                        {
                            sjo = stable.getJSONObject(key);
                        }
                    }
                }
                if (jo.Contains("snapshots"))
                {
                    JSONObject stable = jo.getJSONObject("snapshots").getJSONObject("com.mumfrey:liteloader");
                    var        keys   = stable.getKeys();
                    foreach (string key in keys)
                    {
                        if (key == "latest")
                        {
                            continue;
                        }
                        if (stable.getJSONObject(key).getString("version") == tasks[i].param.Split(";".ToCharArray())[0])
                        {
                            sjo = stable.getJSONObject(key);
                        }
                    }
                }
                if (!Directory.Exists(cd + "\\libraries\\com\\mumfrey\\liteloader\\" + sv))
                {
                    Directory.CreateDirectory(cd + "\\libraries\\com\\mumfrey\\liteloader\\" + sv);
                }
                if (!File.Exists(Application.StartupPath + "\\liteloader-" + tasks[i].param.Split(";".ToCharArray())[0] + ".jar"))
                {
                    i++;
                    DoNext(null, null);
                    return;
                }
                File.Copy(Application.StartupPath + "\\liteloader-" + tasks[i].param.Split(";".ToCharArray())[0] + ".jar", cd + "\\libraries\\com\\mumfrey\\liteloader\\" + sv + "\\liteloader-" + sv + ".jar", true);
                JSONObject verInfo = new JSONObject(File.ReadAllText(cd + "\\versions\\" + tasks[i].param.Split(";".ToCharArray())[1] + "\\" + tasks[i].param.Split(";".ToCharArray())[1] + ".json"));
                var        vl      = sjo.getJSONArray("libraries");
                vl.putJSONObject(vl.length(), new JSONObject("{\"name\": \"com.mumfrey:liteloader:" + sv + "\",\"url\": \"http://dl.liteloader.com/versions/\"}"));
                verInfo.putJSONArray("libraries", vl);
                verInfo.putString("inheritsFrom", tasks[i].param.Split(";".ToCharArray())[1]);
                verInfo.putString("jar", sv);
                verInfo.putString("mainClass", "net.minecraft.launchwrapper.Launch");
                verInfo.putString("minecraftArguments", verInfo.getString("minecraftArguments") + " --tweakClass " + sjo.getString("tweakClass"));
                string dist = cd + "\\versions\\" + tasks[i].param.Split(";".ToCharArray())[1] + "-Liteloader" + tasks[i].param.Split(";".ToCharArray())[0] + "\\" + tasks[i].param.Split(";".ToCharArray())[1] + "-Liteloader" + tasks[i].param.Split(";".ToCharArray())[0] + ".json";
                if (!Directory.GetParent(dist).Exists)
                {
                    Directory.GetParent(dist).Create();
                }
                File.WriteAllText(dist, verInfo.toString());
                i++;
                DoNext(null, null);
                return;
            }
            if (tl.SelectedItem.ToString().StartsWith("安装OptiFine"))
            {
                string sv = tasks[i].param.Split(";".ToCharArray())[1] + "-";
                sv = sv.Substring(0, sv.IndexOf("-"));
                string ov   = tasks[i].param.Split(";".ToCharArray())[0];
                string targ = tasks[i].param.Split(";".ToCharArray())[1];
                if (!Directory.Exists(cd + "\\libraries\\optifine\\OptiFine\\" + sv + "_" + ov))
                {
                    Directory.CreateDirectory(cd + "\\libraries\\optifine\\OptiFine\\" + sv + "_" + ov);
                }
                File.Copy(cd + "\\mods\\Optifine_" + sv + "_" + ov + ".jar", cd + "\\libraries\\optifine\\OptiFine\\" + sv + "_" + ov + "\\OptiFine-" + sv + "_" + ov + ".jar", true);
                JSONObject verInfo = new JSONObject(File.ReadAllText(cd + "\\versions\\" + tasks[i].param.Split(";".ToCharArray())[1] + "\\" + tasks[i].param.Split(";".ToCharArray())[1] + ".json"));
                var        vl      = new JSONArray();
                vl.putJSONObject(0, new JSONObject("{      \"name\": \"optifine:OptiFine:" + sv + "_" + ov + "\"    }"));
                vl.putJSONObject(1, new JSONObject("{\"name\": \"net.minecraft:launchwrapper:1.12\"}"));
                verInfo.putJSONArray("libraries", vl);
                verInfo.putString("inheritsFrom", targ);
                verInfo.putString("jar", sv);
                verInfo.putString("mainClass", "net.minecraft.launchwrapper.Launch");
                verInfo.putString("minecraftArguments", verInfo.getString("minecraftArguments") + " --tweakClass optifine.OptiFineTweaker");
                string dist = cd + "\\versions\\" + targ + "-OptiFine_" + ov + "\\" + targ + "-OptiFine_" + ov + ".json";
                if (!Directory.GetParent(dist).Exists)
                {
                    Directory.GetParent(dist).Create();
                }
                File.WriteAllText(dist, verInfo.toString());
                i++;
                DoNext(null, null);
                return;
            }
            totPG.Step = i * 100 / tl.Items.Count - totPG.Value;
            totPG.PerformStep();
            tpgPct.Text = totPG.Value + "%";
            i++;
        }