예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            MLogin   login   = new MLogin();
            MSession session = MSession.GetOfflineSession(textBox1.Text);

            session = login.TryAutoLogin();
            Minecraft.Initialize(Path.Combine(appDataPath, @"SkyLauncher\"));
            MProfileInfo[] infos   = MProfileInfo.GetProfiles();
            MProfile       profile = MProfile.FindProfile(infos, "1.12.2");

            DownloadGame(profile);

            var option = new MLaunchOption()
            {
                // must require
                StartProfile = profile,
                JavaPath     = "java.exe", //SET YOUR JAVA PATH (if you want autoset, goto wiki)
                MaximumRamMb = 4096,       // MB
                Session      = MSession.GetOfflineSession(textBox1.Text),

                // not require
                LauncherName        = "McLauncher", // display launcher name at main window
                CustomJavaParameter = ""            // set your own java args
            };

            MLaunch launch = new MLaunch(option);

            launch.GetProcess().Start();
        }
예제 #2
0
        private void StartDebug(MLaunch launch)
        {
            Console.WriteLine("GameStartMode : Debug");

            var process = launch.GetProcess();

            Console.WriteLine("Trying Write Game Args");
            try
            {
                System.IO.File.WriteAllText("launcher.txt", process.StartInfo.Arguments);
            }
            catch
            {
                Console.WriteLine("Write Game Args Failed");
            }

            Console.WriteLine("Setting Debug Process");
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.EnableRaisingEvents = true;
            process.ErrorDataReceived  += Process_ErrorDataReceived;
            process.OutputDataReceived += Process_OutputDataReceived;

            Console.WriteLine("Start Debug Process");
            process.Start();
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();

            //Dispatcher.Invoke(new Action(delegate
            //{
            //    Console.WriteLine("Start Log Window");
            //    LogWindow.Log.Show();
            //}));
        }
예제 #3
0
        private void Btn_Launch_Click(object sender, EventArgs e)
        {
            // Launch

            if (session == null)
            {
                MessageBox.Show("Login First");
                return;
            }

            if (Cb_Version.Text == "")
            {
                return;
            }
            groupBox1.Enabled = false;
            groupBox2.Enabled = false;

            string startVersion = Cb_Version.Text;
            string javaPath     = Txt_Java.Text;
            string xmx          = Txt_Ram.Text;
            string launcherName = Txt_LauncherName.Text;
            string serverIp     = Txt_ServerIp.Text;

            var th = new Thread(new ThreadStart(delegate
            {
                var profile = MProfile.FindProfile(versions, startVersion); // Find Profile

                DownloadGame(profile);                                      // Download game files

                MLaunchOption option = new MLaunchOption()                  // Set options
                {
                    StartProfile        = profile,
                    JavaPath            = javaPath,
                    LauncherName        = launcherName,
                    MaximumRamMb        = int.Parse(xmx),
                    ServerIp            = serverIp,
                    Session             = session,
                    CustomJavaParameter = Txt_JavaArgs.Text
                };

                if (Txt_ScWd.Text != "" && Txt_ScHt.Text != "")
                {
                    option.ScreenHeight = int.Parse(Txt_ScHt.Text);
                    option.ScreenWidth  = int.Parse(Txt_ScWd.Text);
                }

                MLaunch launch = new MLaunch(option); // Start Process
                var process    = launch.GetProcess();

                DebugProcess(process);

                this.Invoke((MethodInvoker) delegate
                {
                    groupBox1.Enabled = true;
                    groupBox2.Enabled = true;
                });
            }));

            th.Start();
        }
예제 #4
0
        private void StartGame()
        {
            var local = MProfileInfo.GetProfilesFromLocal();

            MProfileInfo[] versions = MProfileInfo.GetProfiles();
            MProfile       profile  = MProfile.GetProfile(versions, "1.12.2-forge1.12.2-14.23.5.2847");
            MLaunchOption  option   = new MLaunchOption()
            {
                StartProfile        = profile,
                JavaPath            = GADD_Application.Properties.Settings.Default.mclocation + "\\runtime\\bin\\javaw.exe",
                MaximumRamMb        = GADD_Application.Properties.Settings.Default.ram,
                LauncherName        = "GADD",
                Session             = session,
                CustomJavaParameter = Properties.Settings.Default.javargs
            };
            MLaunch launch = new MLaunch(option);
            var     proc   = launch.GetProcess();

            //proc.Start();
            //launch.GetProcess().Start();
            StartDebug(proc);
            //Console.ProcessLock(launch);
            Invoke((MethodInvoker) delegate
            {
                GaddPage.GP.ButtonStat(true);
            });
        }
예제 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            MLogin   login   = new MLogin();
            MSession session = MSession.GetOfflineSession(textBox1.Text);

            session = login.TryAutoLogin();
            Minecraft.Initialize(Path.Combine(appDataPath, @"SkyLauncher\"));
            MProfileInfo[] infos   = MProfileInfo.GetProfiles();
            MProfile       profile = MProfile.FindProfile(infos, comboBox1.SelectedItem.ToString());

            DownloadGame(profile);

            var option = new MLaunchOption()
            {
                // must require
                StartProfile = profile,
                JavaPath     = "java.exe", //JAVA PAT
                MaximumRamMb = 4096,       // MB
                Session      = MSession.GetOfflineSession(textBox1.Text),

                // not require
                LauncherName        = "SkyLauncher",
                CustomJavaParameter = "" // java args
            };

            MLaunch launch = new MLaunch(option);

            launch.GetProcess().Start();
        }
예제 #6
0
        public void Run(MProfile profile, MSession session, string ram)
        {
            int ramNumber = Checkram(ram);

            string javapath = Directory.GetCurrentDirectory() + @"\Minecraft\runtime\jre-x64\bin\javaw.exe";

            MLaunchOption option = LaunchOption(profile, session, ramNumber, javapath);

            MLaunch launch = new MLaunch(option);

            launch.GetProcess().Start();
        }
예제 #7
0
        public Process CreateProcess(MLaunchOption option)
        {
            if (string.IsNullOrEmpty(option.JavaPath))
            {
                option.JavaPath = CheckJRE();
            }

            CheckGameFiles(option.StartProfile);

            var launch = new MLaunch(option);

            return(launch.GetProcess());
        }
예제 #8
0
        public async Task <bool> StartMinecraftAsync(IWin32Window fromWindow)
        {
            if (this.instanceMetadata == null)
            {
                return(false);
            }

            var session = await SessionUtil.GetSessionAsync(fromWindow);

            if (session == null)
            {
                return(false);
            }

            var launchOptions = CreateLaunchOptions(session);
            var launchVersion = this.instanceMetadata.CurrentLaunchVersion;

            if (this.packMetadata.SupportsVr)
            {
                if (this.isVrEnabled)
                {
                    launchVersion = this.instanceMetadata.VrLaunchVersion;
                }
                else if (this.packMetadata.EnableVivecraftForNonVrPlayers != false)
                {
                    launchVersion = this.instanceMetadata.NonVrLaunchVersion;
                }
            }

            launchOptions.StartVersion = await GetVersionMetadataAsync(launchVersion);

            var launch  = new MLaunch(launchOptions);
            var process = launch.GetProcess();

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.EnableRaisingEvents = true;
            process.Exited += (_, _) => CurrentProcess = null;

            process.Start();

            CurrentProcess = process;
            Launched?.Invoke(this, EventArgs.Empty);

            return(true);
        }
예제 #9
0
        public Process Start(string _version)
        {
            System.Net.ServicePointManager.DefaultConnectionLimit = 256;

            var game     = new MinecraftPath(path);
            var launcher = new CMLauncher(game);

            launcher.ProgressChanged += Download_Progress;
            launcher.FileChanged     += Download_ChangeFile;

            var lv = new LocalVersionLoader(game).GetVersionMetadatas();

            MVersion findVersion = null;

            try
            {
                findVersion = lv.GetVersion(_version);
            }
            catch (KeyNotFoundException)
            {
            }


            //var findVersion = lv.GetVersion(_version);

            if (findVersion == null)
            {
                MVersionMetadata findMVersion = null;

                try
                {
                    findMVersion = lv.GetVersionMetadata(_version);
                }
                catch (KeyNotFoundException)
                {
                }

                if (findMVersion != null)
                {
                    findMVersion.Save(game);
                }
                else
                {
                    var findWVersion = new MojangVersionLoader().GetVersionMetadatas().GetVersionMetadata(_version);

                    if (findWVersion != null)
                    {
                        findWVersion.Save(game);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            try
            {
                findVersion = lv.GetVersion(_version);
            }
            catch (KeyNotFoundException)
            {
                return(null);
            }

            var launchOption = new MLaunchOption
            {
                MaximumRamMb        = ram,
                Session             = se,
                Path                = game,
                StartVersion        = findVersion,
                GameLauncherName    = "JML",
                GameLauncherVersion = "1.0"
            };

            MLaunch launch  = new MLaunch(launchOption);
            var     process = launch.GetProcess();

            process.Start();

            //Process process = launcher.CreateProcess(launchOption);
            //process.Start();

            return(process);
        }
예제 #10
0
        void StartWithAdvancedOptions(MSession session)
        {
            // game directory
            var defaultPath = MinecraftPath.GetOSDefaultPath();
            var path        = Path.Combine(Environment.CurrentDirectory, "game dir");

            // create minecraft path instance
            var minecraft = new MinecraftPath(path);

            minecraft.SetAssetsPath(Path.Combine(defaultPath, "assets")); // this speed up asset downloads

            // get all version metadatas
            // you can also use MVersionLoader.GetVersionMetadatasFromLocal and GetVersionMetadatasFromWeb
            var versionMetadatas = MVersionLoader.GetVersionMetadatas(minecraft);

            foreach (var item in versionMetadatas)
            {
                Console.WriteLine("Name : {0}", item.Name);
                Console.WriteLine("Type : {0}", item.Type);
                Console.WriteLine("Path : {0}", item.Path);
                Console.WriteLine("IsLocalVersion : {0}", item.IsLocalVersion);
                Console.WriteLine("============================================");
            }
            Console.WriteLine("");
            Console.WriteLine("LatestRelease : {0}", versionMetadatas.LatestReleaseVersion?.Name);
            Console.WriteLine("LatestSnapshot : {0}", versionMetadatas.LatestSnapshotVersion?.Name);

            Console.WriteLine("Input Version Name (ex: 1.15.2) : ");
            var versionName = Console.ReadLine();

            // get MVersion from MVersionMetadata
            var version = versionMetadatas.GetVersion(versionName);

            if (version == null)
            {
                Console.WriteLine("{0} is not exist", versionName);
                return;
            }

            Console.WriteLine("\n\nVersion Information : ");
            Console.WriteLine("Id : {0}", version.Id);
            Console.WriteLine("Type : {0}", version.TypeStr);
            Console.WriteLine("ReleaseTime : {0}", version.ReleaseTime);
            Console.WriteLine("AssetId : {0}", version.AssetId);
            Console.WriteLine("JAR : {0}", version.Jar);
            Console.WriteLine("Libraries : {0}", version.Libraries.Length);

            if (version.IsInherited)
            {
                Console.WriteLine("Inherited Profile from {0}", version.ParentVersionId);
            }

            // Download mode
            Console.WriteLine("\nSelect download mode : ");
            Console.WriteLine("(1) Sequence Download");
            Console.WriteLine("(2) Parallel Download");
            var downloadModeInput = Console.ReadLine();

            MDownloader downloader;

            if (downloadModeInput == "1")
            {
                downloader = new MDownloader(minecraft, version); // Sequence Download
            }
            else if (downloadModeInput == "2")
            {
                downloader = new MParallelDownloader(minecraft, version); // Parallel Download (note: Parallel Download is not stable yet)
            }
            else
            {
                Console.WriteLine("Input 1 or 2");
                Console.ReadLine();
                return;
            }

            downloader.ChangeFile     += Downloader_ChangeFile;
            downloader.ChangeProgress += Downloader_ChangeProgress;

            // Start download
            downloader.DownloadAll();

            Console.WriteLine("Download Completed.\n");

            // Set java
            Console.WriteLine("Input java path (empty input will download java) : ");
            var javaInput = Console.ReadLine();

            if (javaInput == "")
            {
                var java = new MJava();
                java.ProgressChanged += Downloader_ChangeProgress;
                javaInput             = java.CheckJava();
            }

            // LaunchOption
            var option = new MLaunchOption()
            {
                JavaPath     = javaInput,
                Session      = session,
                StartVersion = version,
                Path         = minecraft,

                MaximumRamMb = 4096,
                ScreenWidth  = 1600,
                ScreenHeight = 900,
            };

            // Launch
            var launch  = new MLaunch(option);
            var process = launch.GetProcess();

            Console.WriteLine(process.StartInfo.Arguments);
            process.Start();
            Console.WriteLine("Started");
            Console.ReadLine();
        }
예제 #11
0
        private void Btn_Launch_Click(object sender, EventArgs e)
        {
            // Launch

            if (Session == null)
            {
                MessageBox.Show("Login First");
                return;
            }

            if (cbVersion.Text == "")
            {
                MessageBox.Show("Select Version");
                return;
            }

            // disable ui
            setUIEnabled(false);

            // create LaunchOption
            var launchOption = createLaunchOption();

            if (launchOption == null)
            {
                return;
            }

            var version        = cbVersion.Text;
            var useParallel    = rbParallelDownload.Checked;
            var checkHash      = cbCheckFileHash.Checked;
            var downloadAssets = !cbSkipAssetsDownload.Checked;

            var th = new Thread(() =>
            {
                try
                {
                    if (useMJava) // Download Java
                    {
                        var mjava              = new MJava(MinecraftPath.Runtime);
                        mjava.ProgressChanged += Launcher_ProgressChanged;

                        var javapath          = mjava.CheckJava();
                        launchOption.JavaPath = javapath;
                    }

                    MVersion versionInfo      = Versions.GetVersion(version); // Get Version Info
                    launchOption.StartVersion = versionInfo;

                    MDownloader downloader; // Create Downloader
                    if (useParallel)
                    {
                        downloader = new MParallelDownloader(MinecraftPath, versionInfo, 10, true);
                    }
                    else
                    {
                        downloader = new MDownloader(MinecraftPath, versionInfo);
                    }

                    downloader.ChangeFile     += Launcher_FileChanged;
                    downloader.ChangeProgress += Launcher_ProgressChanged;
                    downloader.CheckHash       = checkHash;
                    downloader.DownloadAll(downloadAssets);

                    var launch  = new MLaunch(launchOption); // Create Arguments and Process
                    var process = launch.GetProcess();

                    StartProcess(process); // Start Process with debug options

                    // or just start process
                    // process.Start();
                }
                catch (MDownloadFileException mex) // download exception
                {
                    MessageBox.Show(
                        $"FileName : {mex.ExceptionFile.Name}\n" +
                        $"FilePath : {mex.ExceptionFile.Path}\n" +
                        $"FileUrl : {mex.ExceptionFile.Url}\n" +
                        $"FileType : {mex.ExceptionFile.Type}\n\n" +
                        mex.ToString());
                }
                catch (Win32Exception wex) // java exception
                {
                    MessageBox.Show(wex.ToString() + "\n\nIt seems your java setting has problem");
                }
                catch (Exception ex) // all exception
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    Invoke(new Action(() =>
                    {
                        // re open log form
                        if (logForm != null)
                        {
                            logForm.Close();
                        }

                        logForm = new GameLog();
                        logForm.Show();

                        // enable ui
                        setUIEnabled(true);
                    }));
                }
            });

            th.Start();
        }
예제 #12
0
        private void btnLaunch_Click(object sender, EventArgs e)
        {
            //Launches game

            string selected = this.cbVersion.GetItemText(this.cbVersion.SelectedItem);

            System.Reflection.Assembly assembly   = System.Reflection.Assembly.GetExecutingAssembly();
            FileVersionInfo            versionInf = FileVersionInfo.GetVersionInfo(assembly.Location);

            if (guna2CheckBox1.Checked == true)

            {
                //Playing rpc
                if (Properties.Settings.Default.langtr == true)
                {
                    client.UpdateState($"{selected} oynuyor.");
                }
                else
                {
                    client.UpdateState($"Playing {selected}.");
                }
            }

            UpdateSession(MSession.GetOfflineSession(lbUsername.Text));
            if (Session == null)
            {
                MessageBox.Show("İlk önce giriş yap");
                return;
            }

            if (cbVersion.Text == "")
            {
                MessageBox.Show("Versiyon Seç / Select Version");
                return;
            }

            var launchOption = createLaunchOption();

            if (launchOption == null)
            {
                return;
            }
            //Creates launch options
            var version        = cbVersion.Text;
            var useParallel    = rbParallelDownload.Checked;
            var checkHash      = cbCheckFileHash.Checked;
            var downloadAssets = !cbSkipAssetsDownload.Checked;

            var th = new Thread(() =>
            {
                try
                {
                    if (useMJava)
                    {
                        //Minecraft custom java
                        var mjava              = new MJava(MinecraftPath.Runtime);
                        mjava.ProgressChanged += Launcher_ProgressChanged;

                        var javapath          = mjava.CheckJava();
                        launchOption.JavaPath = javapath;
                    }

                    MVersion versionInfo      = Versions.GetVersion(version);
                    launchOption.StartVersion = versionInfo;

                    MDownloader downloader;
                    if (useParallel)
                    {
                        downloader = new MParallelDownloader(MinecraftPath, versionInfo, 10, true);
                    }
                    else
                    {
                        downloader = new MDownloader(MinecraftPath, versionInfo);
                    }

                    downloader.ChangeFile     += Launcher_FileChanged;
                    downloader.ChangeProgress += Launcher_ProgressChanged;
                    downloader.CheckHash       = checkHash;
                    downloader.DownloadAll(downloadAssets);

                    var launch  = new MLaunch(launchOption);
                    var process = launch.GetProcess();

                    StartProcess(process);
                }
                catch (MDownloadFileException mex)
                {
                    MessageBox.Show(
                        $"FileName : {mex.ExceptionFile.Name}\n" +
                        $"FilePath : {mex.ExceptionFile.Path}\n" +
                        $"FileUrl : {mex.ExceptionFile.Url}\n" +
                        $"FileType : {mex.ExceptionFile.Type}\n\n" +
                        mex.ToString());
                }
                catch (Win32Exception wex)
                {
                    MessageBox.Show(wex.ToString() + "\n\nJava Problem");
                }
                catch (Exception ex)
                {
                    if (Properties.Settings.Default.langtr == true)
                    {
                        this.Alert("Oyun başlatılamadı", "Libaryler indirilemedi veya", "birşeyler ters gitti.", Form_Info.enmType.Error);
                    }//error
                    else
                    {
                        this.Alert("ERROR", "Libraries could not be downloaded or ", "something goes wrong.", Form_Info.enmType.Error);
                    }
                    MessageBox.Show(ex.ToString());
                }
            });

            th.Start();
        }
예제 #13
0
        private void Btn_Launch_Click(object sender, EventArgs e)
        {
            // 실행 버튼 눌렀을때
            // 실행할 버전으로 프로파일 검색하고 패치
            // 실행에 필요한 인수 설정
            // 실행

            if (session == null)
            {
                MessageBox.Show("Login First");
                return;
            }

            if (Cb_Version.Text == "")
            {
                return;
            }
            groupBox1.Enabled = false;
            groupBox2.Enabled = false;

            string nn     = Cb_Version.Text;
            string jj     = Txt_Java.Text;
            string xmx    = Txt_Ram.Text;
            string ln     = Txt_LauncherName.Text;
            string server = Txt_ServerIp.Text;

            var th = new Thread(new ThreadStart(delegate
            {
                MProfile profile      = null;
                MProfile forgeProfile = null;

                foreach (var item in versions)
                {
                    if (item.Name == nn)
                    {
                        profile = MProfile.Parse(item);
                        break;
                    }
                }

                if (profile.IsForge)
                {
                    foreach (var item in versions)
                    {
                        if (item.Name == profile.InnerJarId)
                        {
                            forgeProfile = MProfile.Parse(item);
                            break;
                        }
                    }

                    DownloadGame(forgeProfile, true);
                }

                DownloadGame(profile, !profile.IsForge);

                MLaunchOption option = new MLaunchOption()
                {
                    BaseProfile         = forgeProfile,
                    StartProfile        = profile,
                    JavaPath            = jj,
                    LauncherName        = ln,
                    MaximumRamMb        = int.Parse(xmx),
                    ServerIp            = server,
                    Session             = session,
                    CustomJavaParameter = Txt_JavaArgs.Text
                };

                if (Txt_ScWd.Text != "" && Txt_ScHt.Text != "")
                {
                    option.ScreenHeight = int.Parse(Txt_ScHt.Text);
                    option.ScreenWidth  = int.Parse(Txt_ScWd.Text);
                }

                MLaunch launch = new MLaunch(option);

                if (true)
                {
                    StartDebug(launch);
                }
                else
                {
                    var pro = launch.GetProcess();                                     // 인수 생성 후 설정된 Process 객체 가져옴
                    System.IO.File.WriteAllText("mcarg.txt", pro.StartInfo.Arguments); // 만들어진 인수 파일로 저장 (디버그용)
                    pro.Start();                                                       // Process 객체로 실행
                }

                this.Invoke((MethodInvoker) delegate
                {
                    groupBox1.Enabled = true;
                    groupBox2.Enabled = true;
                });
            }));

            th.Start();
        }
        private void LaunchButton_Click(object sender, EventArgs e)
        {
            string sptxt = Data.serverIP;

            if (!string.IsNullOrEmpty(sptxt))
            {
                File.WriteAllText("mars_client\\serverip.ser", sptxt);
            }
            else
            {
                File.WriteAllText("mars_client\\serverip.ser", "");
            }
            object _version = Data.versionString;

            if (_version == null)
            {
                MessageBox.Show("Please select a version!", "Mars", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string version = (string)_version;

            File.WriteAllText("mars_client\\version.ser", version);
            CMLauncher launcher = Data.launcher;
            bool       forge    = version.ToLower().Contains("forge");

            OutputManager.ShowConsoleWindow(true);
            Console.WriteLine("[MARS] Setting up launch arguments... Please wait!");

            MSession ssh;

            if (!Data.offline)
            {
                ssh = new MSession();
                Type editor = typeof(MSession);
                editor.GetField("<ClientToken>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.clientToken);
                editor.GetField("<AccessToken>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.accessToken);
                editor.GetField("<Username>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.username);
                editor.GetField("<UUID>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.mcUUID);
            }
            else
            {
                string username = Data.username;
                ssh = MSession.GetOfflineSession(username);
            }

            Console.WriteLine("[MARS] Successfully created session.");

            MLaunchOption options = new MLaunchOption()
            {
                JavaPath     = "java.exe",
                MaximumRamMb = GetInstalledMemoryMB() / 2,
                Session      = ssh,

                VersionType         = version,
                GameLauncherName    = "MarsClient",
                GameLauncherVersion = "1.5",
            };

            Console.WriteLine("[MARS] Assigned launch options.");

            if (forge)
            {
                string[] parts        = version.Split('-');
                string   mcVer        = parts[0];
                string   forgeVer     = parts[2] + "-" + parts[3];
                MProfile forgeProfile = launcher.GetProfile(mcVer, forgeVer);
                options.StartProfile = forgeProfile;
            }
            else
            {
                options.StartProfile = launcher.GetProfile(version);
            }
            if (!string.IsNullOrEmpty(sptxt))
            {
                options.ServerIp = sptxt;
            }

            Console.WriteLine("[MARS] Located target profile. Launching...");
            Console.WriteLine("[MARS] Moving to new thread...");

            Data.hook.OnHookKeyPressed += Hook_OnHookKeyPressed;
            MLaunch launch = new MLaunch(options);

            mcThread = new Thread(new ParameterizedThreadStart(delegate(object obj) {
                MLaunch threadLaunch       = (MLaunch)obj;
                Process pr                 = threadLaunch.GetProcess();
                ProcessStartInfo psi       = pr.StartInfo;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardInput  = true;
                psi.UseShellExecute        = false;
                staticMC = Process.Start(psi);
                staticMC.EnableRaisingEvents = true;

                launched         = true;
                staticMC.Exited += delegate
                {
                    //OutputManager.RemoveConsole();
                    rpcTimer.Stop();
                    Data.rpccli.Dispose();
                    Invoke((MethodInvoker) delegate
                    {
                        minecraftClosed = true;
                    });
                    mcThread.Abort();
                };
                staticMC.OutputDataReceived += (object _, DataReceivedEventArgs _a) =>
                {
                    string txt = _a.Data;
                    OutputManager.ProcessText(txt);
                    if (txt == null)
                    {
                        return;
                    }
                    if (txt.Contains("[Client thread/INFO]: Connecting to"))
                    {
                        int timeind      = txt.IndexOf(']');
                        string a         = txt.Substring(timeind + 38);
                        string b         = a.Split(',')[0];
                        string newserver = "Server: " + b;
                        if (!currentServer.Equals(newserver))
                        {
                            Debug.WriteLine("Connected to: \"" + b + "\"");
                            Console.WriteLine("Connected to: \"" + b + "\"");
                        }
                        currentServer = "Server: " + b;
                    }
                };
                staticMC.BeginOutputReadLine();
            }));
            mcThread.Start(launch);

            int launchWaits = 0;

            while (staticMC == null)
            {
                launchWaits++;
                Console.WriteLine("[MARS] Waiting for process to launch... #{0}", launchWaits);
                Thread.Sleep(250);
            }

            Console.WriteLine("[MARS] Waiting for main window handle...");
            Data.mcProcess = staticMC;
            while (staticMC.MainWindowHandle == IntPtr.Zero)
            {
                Thread.Sleep(100);
            }
            Data.mcWindow = staticMC.MainWindowHandle;

            Console.WriteLine("\n\n[MARS] Got main window handle. Attaching UI framework...");
            Console.WriteLine("[MARS] Building window...\n\n");

            InGameWindow igw = new InGameWindow();

            Data.hud = igw;
            igw.Show();
            SetParent(igw.Handle, Data.mcWindow);
            igw.NowParented();

            Console.WriteLine("[MARS] Begun window message pump.");
            Console.WriteLine("[MARS] Fetching HypixelSelf info...");

            if (File.Exists("mars_client\\hypixelself.ser"))
            {
                Data.player = HypixelSelf.Deserialize(File.ReadAllText
                                                          ("mars_client\\hypixelself.ser"));
            }

            Console.WriteLine("[MARS] Loaded, if any.\n\n");

            Console.WriteLine("[MARS] Finished initialization.");
        }
예제 #15
0
        private void btn_Launch_Click(object sender, EventArgs e)
        {
            if (gameistarted == true)
            {
                killgame();
            }
            else
            {
                gameistarted = true;

                string selected = this.cbVersion.GetItemText(this.cbVersion.SelectedItem);

                System.Reflection.Assembly assembly   = System.Reflection.Assembly.GetExecutingAssembly();
                FileVersionInfo            versionInf = FileVersionInfo.GetVersionInfo(assembly.Location);

                client.UpdateState($"Playing {selected}.");


                UpdateSession(MSession.GetOfflineSession(username_lbl.Text));

                if (Session == null)
                {
                    MessageBox.Show("İlk önce giriş yap");
                    return;
                }

                if (cbVersion.Text == "")
                {
                    MessageBox.Show("Versiyon Seç / Select Version");
                    return;
                }

                var launchOption = createLaunchOption();
                if (launchOption == null)
                {
                    return;
                }
                //Creates launch options
                var version = cbVersion.Text;

                var th = new Thread(() =>
                {
                    try
                    {
                        if (useMJava)
                        {
                            //Minecraft custom java
                            var mjava              = new MJava(MinecraftPath.Runtime);
                            mjava.ProgressChanged += Launcher_ProgressChanged;

                            var javapath          = mjava.CheckJava();
                            launchOption.JavaPath = javapath;
                        }
                        else
                        {
                            launchOption.JavaPath = javapath;
                        }

                        MVersion versionInfo      = Versions.GetVersion(version);
                        launchOption.StartVersion = versionInfo;

                        MDownloader downloader;
                        downloader = new MDownloader(MinecraftPath, versionInfo);

                        downloader.ChangeFile     += Launcher_FileChanged;
                        downloader.ChangeProgress += Launcher_ProgressChanged;
                        downloader.CheckHash       = true;
                        downloader.DownloadAll();

                        var launch  = new MLaunch(launchOption);
                        var process = launch.GetProcess();

                        StartProcess(process);

                        btn_Launch.Text = "Oyunu Kapat";
                    }
                    catch (MDownloadFileException mex)
                    {
                        MessageBox.Show(
                            $"FileName : {mex.ExceptionFile.Name}\n" +
                            $"FilePath : {mex.ExceptionFile.Path}\n" +
                            $"FileUrl : {mex.ExceptionFile.Url}\n" +
                            $"FileType : {mex.ExceptionFile.Type}\n\n" +
                            mex.ToString());
                        gameistarted = false;
                    }
                    catch (Win32Exception wex)
                    {
                        gameistarted = false;
                        MessageBox.Show(wex.ToString() + "\n\nJava Problem");
                    }
                    catch (Exception ex)
                    {
                        gameistarted = false;
                        MessageBox.Show(ex.ToString());
                    }
                });
                th.Start();
            }
        }