Пример #1
0
        public void Start()
        {
            if (IsReady())
            {
                var     setting = MCSetting.GetSetting();
                Process p       = new Process();
                var     args    = "";
                JObject JSON;
                var     JSONPath = mc.Ver.Path + $@"\{mc.Ver.Name}.json";
                var     natives  = $@"{mc.Ver.Path}\{mc.Ver.Name}-natives";
                var     gamePath = $@"{AppDomain.CurrentDomain.BaseDirectory}\.minecraft";
                using (System.IO.FileStream fs = new System.IO.FileStream(JSONPath, System.IO.FileMode.Open))
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(fs, Encoding.UTF8);
                    JSON = JObject.Parse(sr.ReadToEnd());
                    sr.Close();
                }
                List <string> TrueLibs = new List <string>();
                if (JSON == null)
                {
                    throw new ApplicationException("无法读取指定版本的JSON文件");
                }

                TrueLibs.AddRange(GetLib(JSONPath));
                //填充参数
                if (JSON["inheritsFrom"] != null)
                {
                    var inher = JSON["inheritsFrom"].ToString();
                    var qu    = from c in MCSetting.AllVer
                                where c.Name == inher
                                select c;
                    if (qu.Count() == 0)
                    {
                        throw new System.IO.FileNotFoundException("找不到指定的版本继承");
                    }
                    else
                    {
                        try
                        {
                            TrueLibs.AddRange(GetLib(qu.First().Path + $@"\{qu.First().Name}.json"));
                            TrueLibs.Add($@"{qu.First().Path}\{qu.First().Name}.jar");
                        }
                        catch
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    TrueLibs.Add($@"{gamePath}\versions\{mc.Ver.Name}\{mc.Ver.Name}.jar");
                }
                if (!System.IO.Directory.Exists(natives))
                {
                    throw new System.IO.DirectoryNotFoundException("该版本的natives目录不存在");
                }
                args = $"-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heap.dump -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -XX:-OmitStackTraceInFastThrow -Xmn128m -Xmx{setting.MaxRam}m -Djava.library.path={natives} -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true -Dhellominecraftlauncher.gamedir={gamePath}";
                args = args + " -cp ";
                foreach (var tl in TrueLibs)
                {
                    args = args + tl + ";";
                }
                args = args + " ";
                args = args + JSON["mainClass"].ToString() + " ";
                args = args + JSON["minecraftArguments"].ToString() + " --height 480 --width 854";
                args = args.Replace("${auth_player_name}", mc.Name);
                args = args.Replace("${version_name}", $"\"BasicStart\"");
                args = args.Replace("${game_directory}", $"{gamePath}");
                args = args.Replace("${assets_root}", $@"{gamePath}\assets ");
                args = args.Replace("${assets_index_name}", JSON["assets"].ToString());
                var Random = getRandStringEx(32).ToLower();
                args = args.Replace("${auth_uuid}", Random);
                args = args.Replace("${auth_access_token}", Random);
                args = args.Replace("${user_properties}", "{}");
                args = args.Replace("${user_type}", "Legacy");
                args = args.Replace(@"\\", @"\");
                ProcessStartInfo psi = new ProcessStartInfo(setting.JavaPath, args);
                p.StartInfo = psi;
                p.Start();
            }
            else
            {
                throw new ApplicationException("发生了一个未知的错误,无法启动游戏.");
            }
        }
Пример #2
0
 public bool IsReady()
 {
     if (mc.ver == null)
     {
         return(false);
     }
     if (!string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Ver.Name) && !string.IsNullOrEmpty(MCSetting.GetSetting().JavaPath))
     {
         if (System.IO.Directory.Exists(Ver.Path))
         {
             return(true);
         }
     }
     return(false);
 }