Advertisement
Guest User

Code Launcher HappyBlocks

a guest
Oct 27th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. using System.Net;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices; // This is to unzip the files downloaded from Dropbox
  7.  
  8. namespace GMODit
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.        
  13.         #region Mouse Capture Code
  14.  
  15.         public const int WM_NCLBUTTONDOWN = 0xA1;
  16.         public const int HT_CAPTION = 0x2;
  17.  
  18.         [DllImportAttribute("user32.dll")]
  19.         public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
  20.  
  21.         [DllImportAttribute("user32.dll")]
  22.         public static extern bool ReleaseCapture();
  23.  
  24.         #endregion
  25.  
  26.         public Form1()
  27.         {
  28.             InitializeComponent();
  29.             this.password.KeyUp += new KeyEventHandler(password_KeyUp); //necessary for Enter key capture.
  30.             this.MouseDown += new MouseEventHandler(Form1_MouseDown); //necessary for mouse capture.
  31.  
  32.             if (Directory.Exists(@"C:\GMODit\.minecraft") == false)
  33.             {
  34.                 Directory.CreateDirectory(@"C:\GMODit\.minecraft");
  35.             }
  36.  
  37.             if (File.Exists(@"C:\GMODit\.minecraft\gmoditlastlogin") == false)
  38.             {
  39.                 StreamWriter URaDummyJoel = new StreamWriter(@"C:\GMODit\.minecraft\gmoditlastlogin"); // This creates a blank file
  40.                 URaDummyJoel.Close(); //I'm a dummy because the lack of this section would cause a crash on the first run. Every. Time.
  41.            }
  42.  
  43.             StreamReader loginInfo = new StreamReader(@"C:\GMODit\.minecraft\gmoditlastlogin");
  44.  
  45.             string username;
  46.  
  47.             if ((username = loginInfo.ReadLine()) != null)
  48.             {
  49.                 this.rememberMeBox.Checked = true;
  50.             }
  51.             string password = loginInfo.ReadLine();
  52.  
  53.             //decode password string using decryption algorithm that I haven't written yet... :'(
  54.  
  55.             this.username.Text = username;
  56.             this.password.Text = password;
  57.  
  58.             loginInfo.Close();
  59.  
  60.            
  61.         }
  62.  
  63.         private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  64.         {
  65.             if (e.Button == MouseButtons.Left)
  66.             {
  67.                 ReleaseCapture();
  68.                 SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
  69.             }
  70.         }
  71.  
  72.         private void button1_Click(object sender, EventArgs e)
  73.         {
  74.             if (rememberMeBox.Checked == true)
  75.             {
  76.                 StreamWriter logininfo = new StreamWriter(@"C:\GMODit\.minecraft\gmoditlastlogin");
  77.                 logininfo.WriteLine(this.username.Text);
  78.                 logininfo.WriteLine(this.password.Text);
  79.  
  80.                 logininfo.Close();
  81.             }
  82.             else
  83.             {
  84.                 StreamWriter logininfo = new StreamWriter(@"C:\GMODit\.minecraft\gmoditlastlogin"); // creates blank file; overwrites old file
  85.                 logininfo.Close();
  86.             }
  87.  
  88.             bool ismodded = false;
  89.             bool clientExists = false;
  90.             string folderlocation = @"C:\GMODIT\.minecraft";
  91.             string modlocation = folderlocation + @"\mods";
  92.             string coremodlocation = folderlocation + @"\coremods";
  93.             string templocation = "c:\\temp\\";
  94.  
  95.             if (Directory.Exists(folderlocation))
  96.             {
  97.                 clientExists = true;
  98.             }
  99.  
  100.             if (!Directory.Exists(templocation))
  101.             {
  102.                 Directory.CreateDirectory(templocation);
  103.             }
  104.  
  105.             if (File.Exists(folderlocation + "\\version3.modit"))
  106.             {
  107.                 ismodded = true;
  108.             }
  109.             else
  110.             {
  111.                 //download and extract the three files
  112.  
  113.                 if (InternetCheck.Checked == true) //Secret features being planned!
  114.                 {
  115.                     WebClient downloader = new WebClient();
  116.                     label4.Text = "Téléchargement du client...";
  117.                     this.Update();
  118.                     downloader.DownloadFile("<link to file to download>", templocation + "client.zip");
  119.                     label4.Text = "Téléchargement des mods...";
  120.                     this.Update();
  121.                     downloader.DownloadFile("<link to file to download>", templocation + "mods.zip");
  122.                     label4.Text = "Téléchargement de CoreMods...";
  123.                     this.Update();
  124.                     downloader.DownloadFile("<link to file to download>", templocation + "coremods.zip");
  125.  
  126.                     label4.Text = "Extraction...";
  127.                     Shell32.Shell sc = new Shell32.Shell();
  128.                     Directory.CreateDirectory(@"C:\temp\.minecraft");
  129.                     Shell32.Folder output = sc.NameSpace(@"C:\temp\.minecraft\");
  130.                     Shell32.Folder input = sc.NameSpace(templocation + "client.zip");
  131.                     output.CopyHere(input.Items(), 256);
  132.  
  133.                     Directory.CreateDirectory(@"C:\temp\.minecraft\mods");
  134.                     output = sc.NameSpace(@"C:\temp\.minecraft\mods");
  135.                     input = sc.NameSpace(templocation + "mods.zip");
  136.                     output.CopyHere(input.Items(), 256);
  137.  
  138.                     Directory.CreateDirectory(@"C:\temp\.minecraft\coremods");
  139.                     output = sc.NameSpace(@"C:\temp\.minecraft\coremods");
  140.                     input = sc.NameSpace(templocation + "coremods.zip");
  141.                     output.CopyHere(input.Items(), 256);
  142.  
  143.                     label4.Text = "Cleaning up...";
  144.                     this.Update();
  145.                     File.Delete(templocation + "client.zip");
  146.                     File.Delete(templocation + "mods.zip");
  147.                     File.Delete(templocation + "coremods.zip");
  148.                 }
  149.                 else
  150.                 {
  151.                     WebClient downloader = new WebClient();
  152.                     label4.Text = "Téléchargement du client...";
  153.                     this.Update();
  154.                     downloader.DownloadFile("<link to file to download>", templocation + "client_full.zip");
  155.  
  156.                     label4.Text = "Extraction...";
  157.                     Shell32.Shell sc = new Shell32.Shell();
  158.                     Directory.CreateDirectory(@"C:\temp\.minecraft");
  159.                     Shell32.Folder output = sc.NameSpace(@"C:\temp\.minecraft\");
  160.                     Shell32.Folder input = sc.NameSpace(templocation + "client_full.zip");
  161.                     output.CopyHere(input.Items(), 256);
  162.  
  163.                     label4.Text = "Nettoyage des fichiers Temps...";
  164.                     File.Delete(templocation + "client_full.zip");
  165.                 }
  166.  
  167.                 new Microsoft.VisualBasic.Devices.Computer().FileSystem.CopyDirectory("C:\\temp\\.minecraft", folderlocation, true);
  168.  
  169.                 Directory.Delete("C:\\temp\\.minecraft", true);
  170.  
  171.                 clientExists = true;
  172.                 ismodded = true;
  173.             }
  174.  
  175.             if (clientExists && ismodded)
  176.             {
  177.                 bool authed = false;
  178.                 string user, session = "";
  179.                 string[] res = verifyUser(username.Text, password.Text, out authed);
  180.                 if (authed)
  181.                 {
  182.                     user = res[2];
  183.                     session = res[3];
  184.                     StartMinecraft(user, session);
  185.                     Application.Exit();
  186.                 }
  187.             }
  188.         }
  189.  
  190.         private string[] verifyUser(string username, string password, out bool authed)
  191.         {
  192.             HttpWebResponse response;
  193.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://login.minecraft.net/?user=" + username + "&password=" + password + "&version=13");
  194.             try
  195.             {
  196.                 response = (HttpWebResponse)request.GetResponse();
  197.             }
  198.             catch (Exception)
  199.             {
  200.                 authed = false;
  201.                 return null;
  202.             }
  203.             string str = new StreamReader(response.GetResponseStream()).ReadToEnd();
  204.             if (str.Contains(":") == false)
  205.             {
  206.                 authed = false;
  207.                 this.label4.Text = str;
  208.                 return null;
  209.             }
  210.             authed = true;
  211.             return str.Split(new char[] { ':' });
  212.        }
  213.  
  214.         private string GetJavaInstallationPath()
  215.         {
  216.             string environmentPath = Environment.GetEnvironmentVariable("JAVA_HOME");
  217.             if (!string.IsNullOrEmpty(environmentPath))
  218.             {
  219.                 return environmentPath;
  220.             }
  221.  
  222.             try
  223.             {
  224.                 string javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment\\";
  225.                 using (Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(javaKey))
  226.                 {
  227.                     string currentVersion = rk.GetValue("CurrentVersion").ToString();
  228.                     using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion))
  229.                     {
  230.                         return key.GetValue("JavaHome").ToString();
  231.                     }
  232.                 }
  233.             }
  234.             catch (NullReferenceException)
  235.             {
  236.                 try
  237.                 {
  238.                     string javaKey = "Wow6432Node\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\";
  239.                     using (Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(javaKey))
  240.                     {
  241.                         string currentVersion = rk.GetValue("CurrentVersion").ToString();
  242.                         using (Microsoft.Win32.RegistryKey key = rk.OpenSubKey(currentVersion))
  243.                         {
  244.                             return key.GetValue("JavaHome").ToString();
  245.                         }
  246.                     }
  247.                 }
  248.                 catch (NullReferenceException)
  249.                 {
  250.                     MessageBox.Show("Cannot find Java installation. Please reinstall the latest version of Java and try again.", "GMODit Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  251.                     return null;
  252.                 }
  253.             }
  254.         }
  255.  
  256.         private void StartMinecraft(string username, string session)
  257.         {
  258.             string installPath = GetJavaInstallationPath();
  259.             string filePath = System.IO.Path.Combine(installPath, "bin\\Javaw.exe");
  260.  
  261.             Environment.SetEnvironmentVariable("APPDATA", "C:\\GMODIT\\");
  262.  
  263.             Process process = new Process();
  264.             ProcessStartInfo info = new ProcessStartInfo();
  265.             string dir = @"C:\GMODIT\.minecraft\bin\";
  266.             info.FileName = filePath;
  267.             info.CreateNoWindow = true;
  268.             info.Arguments = "-cp \"" + dir + "minecraft.jar;" + dir + "lwjgl.jar;" + dir + "lwjgl_util.jar;" + dir + "jinput.jar;\" ";
  269.             info.Arguments += "\"-Djava.library.path=" + dir + "natives\" -Xmx1024M -Xms512M net.minecraft.client.Minecraft " + username + " " + session;
  270.             process.StartInfo = info;
  271.             process.Start();
  272.         }
  273.  
  274.         private void Exit_Click(object sender, EventArgs e)
  275.         {
  276.             Application.Exit();
  277.         }
  278.  
  279.         private void password_TextChanged(object sender, EventArgs e)
  280.         {
  281.            
  282.  
  283.             if (password.Text == "")
  284.             {
  285.                 button1.Enabled = false;
  286.             }
  287.             else
  288.             {
  289.                 button1.Enabled = true;
  290.             }
  291.         }
  292.  
  293.         private void password_KeyUp(object sender, KeyEventArgs e)
  294.         {
  295.             if (e.KeyCode == Keys.Enter)
  296.                 button1_Click(null, null);
  297.         }
  298.  
  299.         private void label1_Click(object sender, EventArgs e)
  300.         {
  301.  
  302.         }
  303.  
  304.         private void groupBox2_Enter(object sender, EventArgs e)
  305.         {
  306.  
  307.         }
  308.  
  309.         private void label14_Click(object sender, EventArgs e)
  310.         {
  311.  
  312.         }
  313.  
  314.         private void pictureBox1_Click(object sender, EventArgs e)
  315.         {
  316.  
  317.         }
  318.  
  319.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  320.         {
  321.  
  322.         }
  323.  
  324.         private void eventLog1_EntryWritten(object sender, EntryWrittenEventArgs e)
  325.         {
  326.  
  327.         }
  328.  
  329.         private void eventLog1_EntryWritten_1(object sender, EntryWrittenEventArgs e)
  330.         {
  331.  
  332.         }
  333.  
  334.         private void label4_Click(object sender, EventArgs e)
  335.         {
  336.  
  337.         }
  338.  
  339.         private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  340.         {
  341.  
  342.         }
  343.     }
  344. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement