Exemplo n.º 1
0
        public async Task BuildAssetDownload(int NumThreads, string version)
        {
            _NumThreads = NumThreads;
            _version    = version;
            if (!_disposed)
            {
                AllFile   = new Tools().GetAllTheAsset(version).Length;
                _disposed = true;
            }
            if (FinishFile == AllFile)
            {
                return;
            }
            string Path = System.IO.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\Asset\";

            if (File.Exists(Path + @"\ConsoleApp15.exe"))
            {
                process.StartInfo.FileName = "cmd.exe";
                string Arguments = Path + @"ConsoleApp15.exe " + string.Format("{0} {1} {2}", version, NumThreads, System.Directory.GetCurrentDirectory());
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.CreateNoWindow         = false;
                process.Start();
                process.StandardInput.WriteLine(Arguments + "&exit");
                process.StandardInput.AutoFlush = true;
                process.StandardInput.Close();
                Thread thread = new Thread(Process_OutputDataReceived);
                thread.Start();
                await Task.Run(() =>
                {
                    while (true)
                    {
                        if (FinishFile == AllFile)
                        {
                            return;
                        }
                        Thread.Sleep(2000);
                    }
                });
            }

            GacDownload gac = new GacDownload();

            gac.Download(Path + "yq.zip", "http://www.baibaoblog.cn:81/Asset/Asset.zip");
            while (gac.Complete != 1)
            {
                Thread.Sleep(500);
            }
            if (File.Exists(Path + "yq.zip"))
            {
                Unzip  unzip = new Unzip();
                string a     = "";
                unzip.UnZipFile(Path + "yq.zip", Path, out a);
                BuildAssetDownload(NumThreads, version);
            }
        }
        /// <summary>
        /// 启动游戏
        /// </summary>
        /// <param name="version">版本</param>
        /// <param name="java">java</param>
        /// <param name="RAM">虚拟内存</param>
        /// <param name="name">游戏名</param>
        /// <param name="uuid">uuid</param>
        /// <param name="token">token</param>
        /// <param name="yggdrasilURLORID">ID</param>
        /// <param name="JVMparameter">JVM</param>
        /// <param name="RearParameter">后置参数</param>
        /// <param name="authentication">验证方式</param>
        public async Task StartGame(string version, string java, int RAM, string name, string uuid, string token, string yggdrasilURLORID, string JVMparameter, string RearParameter, AuthenticationServerMode authentication)
        {
            GacDownload GacDownload = new GacDownload();
            string      str3        = null;
            Download    download    = new Download();

            if (authentication == AuthenticationServerMode.yggdrasil)
            {
                if (SLC.FileExist(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\yggdrasilSquareMinecraftLauncher.jar") != null)
                {
                    this.SLC.SetFile("SquareMinecraftLauncher");
                    GacDownload.Download(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\yggdrasilSquareMinecraftLauncher.jar", "https://bmclapi2.bangbang93.com/mirrors/authlib-injector/artifact/39/authlib-injector-1.1.39.jar");
                    while (true)
                    {
                        if (GacDownload.Complete == 0 && GacDownload.Failure == 1)
                        {
                            throw new SquareMinecraftLauncherException("yggdrasil下载失败");
                        }
                        else if (GacDownload.Complete == 1)
                        {
                            break;
                        }
                        ForgeInstallCore.Delay(2000);
                    }
                }
                string s = download.getHtml(yggdrasilURLORID);
                if (s == null)
                {
                    throw new SquareMinecraftLauncherException("启动失败,无法获取相关信息");
                }
                byte[]   bytes      = Encoding.Default.GetBytes(s);
                string[] textArray1 = new string[] { "-javaagent:", System.Directory.GetCurrentDirectory(), @"\SquareMinecraftLauncher\yggdrasilSquareMinecraftLauncher.jar=", yggdrasilURLORID, " -Dauthlibinjector.side=client -Dauthlibinjector.yggdrasil.prefetched=", Convert.ToBase64String(bytes) };
                str3 = string.Concat(textArray1);
            }
            else
            {
                if (SLC.FileExist(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\UnifiedPassSquareMinecraftLauncher.jar") != null)
                {
                    this.SLC.SetFile("SquareMinecraftLauncher");
                    GacDownload.Download(System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\UnifiedPassSquareMinecraftLauncher.jar", "https://login2.nide8.com:233/download/nide8auth.jar");
                    while (true)
                    {
                        if (GacDownload.Complete == 0 && GacDownload.Failure == 1)
                        {
                            throw new SquareMinecraftLauncherException("统一通行证下载失败");
                        }
                        else if (GacDownload.Complete == 1)
                        {
                            break;
                        }
                        ForgeInstallCore.Delay(2000);
                    }
                }
                str3 = "-javaagent:" + System.Directory.GetCurrentDirectory() + @"\SquareMinecraftLauncher\UnifiedPassSquareMinecraftLauncher.jar=" + yggdrasilURLORID;
            }
            if ((JVMparameter != null) && (JVMparameter != ""))
            {
                str3 = str3 + "," + JVMparameter;
            }
            await this.StartGame(version, java, RAM, name, uuid, token, str3, RearParameter);
        }