namespace CryOnline_Launcher
{
    using Microsoft.Win32;
    using SevenZip;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Net;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Security.Principal;
    using System.Threading;
    using System.Windows.Forms;

    public class Form1 : Form
    {
        private CheckBox checkBox1;
        private ImageList CloseIL;
        private IContainer components = null;
        private ProgressBar DLProgressBar;
        private ImageList ForumIL;
        private ImageList HomepageIL;
        public const int HT_CAPTION = 2;
        private bool isDownloaded = false;
        private bool isSuccess = true;
        private Label label1;
        private Label label2;
        private Label label4;
        private ImageList LauncherIL;
        private Label lbl_cltstat;
        private Label lbl_srvstat;
        private LinkLabel linkLabel1;
        private int PatchNumber = 0;
        private PictureBox pictureBox1;
        private PictureBox pictureBox10;
        private PictureBox pictureBox2;
        private PictureBox pictureBox3;
        private PictureBox pictureBox4;
        private PictureBox pictureBox5;
        private PictureBox pictureBox6;
        private PictureBox pictureBox7;
        private PictureBox pictureBox8;
        private PictureBox pictureBox9;
        private ImageList StartGameIL;
        private Thread StartPatching;
        private TextBox textBox1;
        private TextBox textBox2;
        private List<Update> UpdateList;
        private MemoryStream UpdateListStream;
        private WebBrowser webBrowser1;
        private WebBrowser webBrowser2;
        public const int WM_NCLBUTTONDOWN = 0xa1;

        public Form1()
        {
            this.InitializeComponent();
        }

        private void Close_Click(object sender, EventArgs e)
        {
            FileStream stream = new FileStream("./PatchNo.cry", FileMode.Create);
            StreamWriter writer = new StreamWriter(stream);
            writer.WriteLine("{0}", this.lbl_cltstat.Text);
            writer.Flush();
            stream.Close();
            this.StartPatching.Abort();
            Application.Exit();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
            {
                this.RunElevated(Application.ExecutablePath);
                base.Close();
            }
            if ((this.SubKeyExist(@"SOFTWARE\CryOnline\Updater") && this.SubValueExist(@"SOFTWARE\CryOnline\Updater", "Username")) && this.SubValueExist(@"SOFTWARE\CryOnline\Updater", "Password"))
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\CryOnline\Updater");
                this.Username = (string) key.GetValue("Username");
                this.Password = (string) key.GetValue("Password");
                this.textBox1.Text = this.Username;
                this.textBox2.Text = this.Password;
                this.checkBox1.Checked = true;
            }
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            this.StartPatching = new Thread(new ThreadStart(this.startPatching));
            this.StartPatching.Start();
        }

        private void Forum_Click(object sender, EventArgs e)
        {
            Process.Start("http://board.cry-online.net");
        }

        private int GetLatestPatchNo(List<Update> UpdateList)
        {
            int number = 0;
            foreach (Update update in UpdateList)
            {
                if (update.Number > number)
                {
                    number = update.Number;
                }
            }
            return number;
        }

        private void Homepage_Click(object sender, EventArgs e)
        {
            Process.Start("http://cry-online.net");
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(Form1));
            this.linkLabel1 = new LinkLabel();
            this.webBrowser1 = new WebBrowser();
            this.webBrowser2 = new WebBrowser();
            this.textBox1 = new TextBox();
            this.textBox2 = new TextBox();
            this.checkBox1 = new CheckBox();
            this.DLProgressBar = new ProgressBar();
            this.pictureBox1 = new PictureBox();
            this.StartGameIL = new ImageList(this.components);
            this.pictureBox2 = new PictureBox();
            this.ForumIL = new ImageList(this.components);
            this.pictureBox3 = new PictureBox();
            this.HomepageIL = new ImageList(this.components);
            this.pictureBox4 = new PictureBox();
            this.pictureBox5 = new PictureBox();
            this.pictureBox7 = new PictureBox();
            this.pictureBox6 = new PictureBox();
            this.CloseIL = new ImageList(this.components);
            this.label1 = new Label();
            this.label2 = new Label();
            this.lbl_cltstat = new Label();
            this.label4 = new Label();
            this.lbl_srvstat = new Label();
            this.pictureBox8 = new PictureBox();
            this.LauncherIL = new ImageList(this.components);
            this.pictureBox9 = new PictureBox();
            this.pictureBox10 = new PictureBox();
            ((ISupportInitialize) this.pictureBox1).BeginInit();
            ((ISupportInitialize) this.pictureBox2).BeginInit();
            ((ISupportInitialize) this.pictureBox3).BeginInit();
            ((ISupportInitialize) this.pictureBox4).BeginInit();
            ((ISupportInitialize) this.pictureBox5).BeginInit();
            ((ISupportInitialize) this.pictureBox7).BeginInit();
            ((ISupportInitialize) this.pictureBox6).BeginInit();
            ((ISupportInitialize) this.pictureBox8).BeginInit();
            ((ISupportInitialize) this.pictureBox9).BeginInit();
            ((ISupportInitialize) this.pictureBox10).BeginInit();
            base.SuspendLayout();
            this.linkLabel1.AutoSize = true;
            this.linkLabel1.Location = new Point(540, 0x169);
            this.linkLabel1.Name = "linkLabel1";
            this.linkLabel1.Size = new Size(0, 13);
            this.linkLabel1.TabIndex = 1;
            this.webBrowser1.Location = new Point(0xee, 250);
            this.webBrowser1.MinimumSize = new Size(20, 20);
            this.webBrowser1.Name = "webBrowser1";
            this.webBrowser1.ScrollBarsEnabled = false;
            this.webBrowser1.Size = new Size(0x18b, 0xb8);
            this.webBrowser1.TabIndex = 2;
            this.webBrowser1.Url = new Uri("http://cry-online.net/patcher/news.html", UriKind.Absolute);
            this.webBrowser2.Location = new Point(0x296, 250);
            this.webBrowser2.MinimumSize = new Size(20, 20);
            this.webBrowser2.Name = "webBrowser2";
            this.webBrowser2.ScrollBarsEnabled = false;
            this.webBrowser2.Size = new Size(190, 0xb8);
            this.webBrowser2.TabIndex = 3;
            this.webBrowser2.Url = new Uri("http://cry-online.net/patcher/notice.html", UriKind.Absolute);
            this.textBox1.Location = new Point(0xf2, 0x1d0);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new Size(0xb9, 20);
            this.textBox1.TabIndex = 4;
            this.textBox2.Location = new Point(0x1c0, 0x1d0);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new Size(0xba, 20);
            this.textBox2.TabIndex = 5;
            this.textBox2.UseSystemPasswordChar = true;
            this.checkBox1.AutoSize = true;
            this.checkBox1.BackColor = System.Drawing.Color.Transparent;
            this.checkBox1.Font = new Font("Microsoft Sans Serif", 12f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.checkBox1.ForeColor = System.Drawing.Color.White;
            this.checkBox1.Location = new Point(650, 0x1d0);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new Size(0x40, 0x18);
            this.checkBox1.TabIndex = 10;
            this.checkBox1.Text = "Save";
            this.checkBox1.UseVisualStyleBackColor = false;
            this.DLProgressBar.BackColor = System.Drawing.Color.Purple;
            this.DLProgressBar.ForeColor = System.Drawing.Color.Magenta;
            this.DLProgressBar.Location = new Point(0xe5, 0x20f);
            this.DLProgressBar.MarqueeAnimationSpeed = 50;
            this.DLProgressBar.Name = "DLProgressBar";
            this.DLProgressBar.Size = new Size(270, 0x1c);
            this.DLProgressBar.Step = 1;
            this.DLProgressBar.Style = ProgressBarStyle.Continuous;
            this.DLProgressBar.TabIndex = 14;
            this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox1.Image = (Image) manager.GetObject("pictureBox1.Image");
            this.pictureBox1.Location = new Point(0x317, 0x1f7);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Size(80, 0x37);
            this.pictureBox1.TabIndex = 0x10;
            this.pictureBox1.TabStop = false;
            this.pictureBox1.Click += new EventHandler(this.StartGame_Click);
            this.pictureBox1.MouseDown += new MouseEventHandler(this.pictureBox1_MouseDown);
            this.pictureBox1.MouseEnter += new EventHandler(this.pictureBox1_MouseEnter);
            this.pictureBox1.MouseLeave += new EventHandler(this.pictureBox1_MouseLeave);
            this.pictureBox1.MouseHover += new EventHandler(this.pictureBox1_MouseHover);
            this.StartGameIL.ImageStream = (ImageListStreamer) manager.GetObject("StartGameIL.ImageStream");
            this.StartGameIL.TransparentColor = System.Drawing.Color.Transparent;
            this.StartGameIL.Images.SetKeyName(0, "Start_Aktiv.png");
            this.StartGameIL.Images.SetKeyName(1, "Start_Mo.png");
            this.StartGameIL.Images.SetKeyName(2, "Start_Click.png");
            this.StartGameIL.Images.SetKeyName(3, "Start_Inaktiv.png");
            this.pictureBox2.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox2.Image = (Image) manager.GetObject("pictureBox2.Image");
            this.pictureBox2.Location = new Point(0x2c1, 0x1f7);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new Size(80, 0x37);
            this.pictureBox2.TabIndex = 0x11;
            this.pictureBox2.TabStop = false;
            this.pictureBox2.Click += new EventHandler(this.Forum_Click);
            this.pictureBox2.MouseDown += new MouseEventHandler(this.pictureBox2_MouseDown);
            this.pictureBox2.MouseEnter += new EventHandler(this.pictureBox2_MouseEnter);
            this.pictureBox2.MouseLeave += new EventHandler(this.pictureBox2_MouseLeave);
            this.pictureBox2.MouseHover += new EventHandler(this.pictureBox2_MouseHover);
            this.ForumIL.ImageStream = (ImageListStreamer) manager.GetObject("ForumIL.ImageStream");
            this.ForumIL.TransparentColor = System.Drawing.Color.Transparent;
            this.ForumIL.Images.SetKeyName(0, "Forum_Aktiv.png");
            this.ForumIL.Images.SetKeyName(1, "Forum_MO.png");
            this.ForumIL.Images.SetKeyName(2, "Forum_Click.png");
            this.pictureBox3.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox3.Image = (Image) manager.GetObject("pictureBox3.Image");
            this.pictureBox3.Location = new Point(0x26b, 0x1f7);
            this.pictureBox3.Name = "pictureBox3";
            this.pictureBox3.Size = new Size(80, 0x37);
            this.pictureBox3.TabIndex = 0x12;
            this.pictureBox3.TabStop = false;
            this.pictureBox3.Click += new EventHandler(this.Homepage_Click);
            this.pictureBox3.MouseDown += new MouseEventHandler(this.pictureBox3_MouseDown);
            this.pictureBox3.MouseEnter += new EventHandler(this.pictureBox3_MouseEnter);
            this.pictureBox3.MouseLeave += new EventHandler(this.pictureBox3_MouseLeave);
            this.pictureBox3.MouseHover += new EventHandler(this.pictureBox3_MouseHover);
            this.HomepageIL.ImageStream = (ImageListStreamer) manager.GetObject("HomepageIL.ImageStream");
            this.HomepageIL.TransparentColor = System.Drawing.Color.Transparent;
            this.HomepageIL.Images.SetKeyName(0, "Homepage_Aktiv.png");
            this.HomepageIL.Images.SetKeyName(1, "Homepage_MO.png");
            this.HomepageIL.Images.SetKeyName(2, "Homepage_Click.png");
            this.pictureBox4.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox4.BackgroundImage = (Image) manager.GetObject("pictureBox4.BackgroundImage");
            this.pictureBox4.Location = new Point(0xef, 0x1b6);
            this.pictureBox4.Name = "pictureBox4";
            this.pictureBox4.Size = new Size(100, 20);
            this.pictureBox4.TabIndex = 0x13;
            this.pictureBox4.TabStop = false;
            this.pictureBox5.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox5.BackgroundImage = (Image) manager.GetObject("pictureBox5.BackgroundImage");
            this.pictureBox5.Location = new Point(0x1c0, 0x1b6);
            this.pictureBox5.Name = "pictureBox5";
            this.pictureBox5.Size = new Size(100, 20);
            this.pictureBox5.TabIndex = 20;
            this.pictureBox5.TabStop = false;
            this.pictureBox7.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox7.BackgroundImage = (Image) manager.GetObject("pictureBox7.BackgroundImage");
            this.pictureBox7.Location = new Point(0x290, 0xd4);
            this.pictureBox7.Name = "pictureBox7";
            this.pictureBox7.Size = new Size(200, 30);
            this.pictureBox7.TabIndex = 0x16;
            this.pictureBox7.TabStop = false;
            this.pictureBox6.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox6.BackgroundImage = (Image) manager.GetObject("pictureBox6.BackgroundImage");
            this.pictureBox6.Location = new Point(0x3b0, 120);
            this.pictureBox6.Name = "pictureBox6";
            this.pictureBox6.Size = new Size(20, 20);
            this.pictureBox6.TabIndex = 0x18;
            this.pictureBox6.TabStop = false;
            this.pictureBox6.Click += new EventHandler(this.Close_Click);
            this.pictureBox6.MouseDown += new MouseEventHandler(this.pictureBox6_MouseDown);
            this.pictureBox6.MouseEnter += new EventHandler(this.pictureBox6_MouseEnter);
            this.pictureBox6.MouseLeave += new EventHandler(this.pictureBox6_MouseLeave);
            this.pictureBox6.MouseHover += new EventHandler(this.pictureBox6_MouseHover);
            this.CloseIL.ImageStream = (ImageListStreamer) manager.GetObject("CloseIL.ImageStream");
            this.CloseIL.TransparentColor = System.Drawing.Color.Transparent;
            this.CloseIL.Images.SetKeyName(0, "CloseAktiv.png");
            this.CloseIL.Images.SetKeyName(1, "CloseOver.png");
            this.CloseIL.Images.SetKeyName(2, "CloseClick.png");
            this.label1.AutoSize = true;
            this.label1.BackColor = System.Drawing.Color.Transparent;
            this.label1.ForeColor = System.Drawing.Color.White;
            this.label1.Location = new Point(0x304, 470);
            this.label1.Name = "label1";
            this.label1.Size = new Size(80, 13);
            this.label1.TabIndex = 0x19;
            this.label1.Text = "Launcher V 5.3";
            this.label2.AutoSize = true;
            this.label2.BackColor = System.Drawing.Color.Transparent;
            this.label2.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.label2.ForeColor = System.Drawing.Color.White;
            this.label2.Location = new Point(0xe2, 0x1fc);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x62, 0x10);
            this.label2.TabIndex = 0x1a;
            this.label2.Text = "Client Status:";
            this.lbl_cltstat.AutoSize = true;
            this.lbl_cltstat.BackColor = System.Drawing.Color.Transparent;
            this.lbl_cltstat.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.lbl_cltstat.ForeColor = System.Drawing.Color.White;
            this.lbl_cltstat.Location = new Point(320, 0x1fc);
            this.lbl_cltstat.Name = "lbl_cltstat";
            this.lbl_cltstat.Size = new Size(0x24, 0x10);
            this.lbl_cltstat.TabIndex = 0x1b;
            this.lbl_cltstat.Text = "xxxx";
            this.label4.AutoSize = true;
            this.label4.BackColor = System.Drawing.Color.Transparent;
            this.label4.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.label4.ForeColor = System.Drawing.Color.White;
            this.label4.Location = new Point(0x16a, 0x1fc);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x69, 0x10);
            this.label4.TabIndex = 0x1a;
            this.label4.Text = "Server Status:";
            this.lbl_srvstat.AutoSize = true;
            this.lbl_srvstat.BackColor = System.Drawing.Color.Transparent;
            this.lbl_srvstat.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.lbl_srvstat.ForeColor = System.Drawing.Color.White;
            this.lbl_srvstat.Location = new Point(0x1cf, 0x1fc);
            this.lbl_srvstat.Name = "lbl_srvstat";
            this.lbl_srvstat.Size = new Size(0x24, 0x10);
            this.lbl_srvstat.TabIndex = 0x1b;
            this.lbl_srvstat.Text = "xxxx";
            this.pictureBox8.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox8.BackgroundImage = (Image) manager.GetObject("pictureBox8.BackgroundImage");
            this.pictureBox8.Location = new Point(0x215, 0x1f7);
            this.pictureBox8.Name = "pictureBox8";
            this.pictureBox8.Size = new Size(80, 0x37);
            this.pictureBox8.TabIndex = 0x1c;
            this.pictureBox8.TabStop = false;
            this.pictureBox8.Click += new EventHandler(this.pictureBox8_Click);
            this.pictureBox8.MouseDown += new MouseEventHandler(this.pictureBox8_MouseDown);
            this.pictureBox8.MouseEnter += new EventHandler(this.pictureBox8_MouseEnter);
            this.pictureBox8.MouseLeave += new EventHandler(this.pictureBox8_MouseLeave);
            this.pictureBox8.MouseHover += new EventHandler(this.pictureBox8_MouseHover);
            this.LauncherIL.ImageStream = (ImageListStreamer) manager.GetObject("LauncherIL.ImageStream");
            this.LauncherIL.TransparentColor = System.Drawing.Color.Transparent;
            this.LauncherIL.Images.SetKeyName(0, "LU_Aktiv.png");
            this.LauncherIL.Images.SetKeyName(1, "LU_Click.png");
            this.LauncherIL.Images.SetKeyName(2, "LU_Inaktiv.png");
            this.LauncherIL.Images.SetKeyName(3, "LU_MO.png");
            this.pictureBox9.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox9.Image = (Image) manager.GetObject("pictureBox9.Image");
            this.pictureBox9.Location = new Point(0x350, 210);
            this.pictureBox9.Name = "pictureBox9";
            this.pictureBox9.Size = new Size(0x1a, 0x1a);
            this.pictureBox9.TabIndex = 0x1d;
            this.pictureBox9.TabStop = false;
            this.pictureBox9.Click += new EventHandler(this.pictureBox9_Click);
            this.pictureBox10.BackColor = System.Drawing.Color.Transparent;
            this.pictureBox10.BackgroundImage = (Image) manager.GetObject("pictureBox10.BackgroundImage");
            this.pictureBox10.Location = new Point(0xe5, 0xd6);
            this.pictureBox10.Name = "pictureBox10";
            this.pictureBox10.Size = new Size(200, 30);
            this.pictureBox10.TabIndex = 30;
            this.pictureBox10.TabStop = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            this.BackgroundImage = (Image) manager.GetObject("$this.BackgroundImage");
            base.ClientSize = new Size(920, 610);
            base.Controls.Add(this.pictureBox10);
            base.Controls.Add(this.pictureBox9);
            base.Controls.Add(this.pictureBox8);
            base.Controls.Add(this.lbl_srvstat);
            base.Controls.Add(this.lbl_cltstat);
            base.Controls.Add(this.label4);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.label1);
            base.Controls.Add(this.pictureBox6);
            base.Controls.Add(this.pictureBox7);
            base.Controls.Add(this.pictureBox5);
            base.Controls.Add(this.pictureBox4);
            base.Controls.Add(this.pictureBox3);
            base.Controls.Add(this.pictureBox2);
            base.Controls.Add(this.pictureBox1);
            base.Controls.Add(this.DLProgressBar);
            base.Controls.Add(this.checkBox1);
            base.Controls.Add(this.textBox2);
            base.Controls.Add(this.textBox1);
            base.Controls.Add(this.webBrowser2);
            base.Controls.Add(this.webBrowser1);
            base.Controls.Add(this.linkLabel1);
            base.FormBorderStyle = FormBorderStyle.None;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.Name = "Form1";
            this.Text = "L";
            base.TransparencyKey = System.Drawing.Color.FromArgb(250, 0, 250);
            base.Load += new EventHandler(this.Form1_Load);
            base.Shown += new EventHandler(this.Form1_Shown);
            base.MouseDown += new MouseEventHandler(this.MainForm_MouseDown);
            ((ISupportInitialize) this.pictureBox1).EndInit();
            ((ISupportInitialize) this.pictureBox2).EndInit();
            ((ISupportInitialize) this.pictureBox3).EndInit();
            ((ISupportInitialize) this.pictureBox4).EndInit();
            ((ISupportInitialize) this.pictureBox5).EndInit();
            ((ISupportInitialize) this.pictureBox7).EndInit();
            ((ISupportInitialize) this.pictureBox6).EndInit();
            ((ISupportInitialize) this.pictureBox8).EndInit();
            ((ISupportInitialize) this.pictureBox9).EndInit();
            ((ISupportInitialize) this.pictureBox10).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(base.Handle, 0xa1, 2, 0);
            }
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            this.pictureBox1.Image = this.StartGameIL.Images[2];
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox1.Image = this.StartGameIL.Images[1];
        }

        private void pictureBox1_MouseHover(object sender, EventArgs e)
        {
            this.pictureBox1.Image = this.StartGameIL.Images[1];
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.pictureBox1.Image = this.StartGameIL.Images[0];
        }

        private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
        {
            this.pictureBox2.Image = this.ForumIL.Images[2];
        }

        private void pictureBox2_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox2.Image = this.ForumIL.Images[1];
        }

        private void pictureBox2_MouseHover(object sender, EventArgs e)
        {
            this.pictureBox2.Image = this.ForumIL.Images[1];
        }

        private void pictureBox2_MouseLeave(object sender, EventArgs e)
        {
            this.pictureBox2.Image = this.ForumIL.Images[0];
        }

        private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
        {
            this.pictureBox3.Image = this.HomepageIL.Images[2];
        }

        private void pictureBox3_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox3.Image = this.HomepageIL.Images[1];
        }

        private void pictureBox3_MouseHover(object sender, EventArgs e)
        {
            this.pictureBox3.Image = this.HomepageIL.Images[1];
        }

        private void pictureBox3_MouseLeave(object sender, EventArgs e)
        {
            this.pictureBox3.Image = this.HomepageIL.Images[0];
        }

        private void pictureBox6_MouseDown(object sender, MouseEventArgs e)
        {
            this.pictureBox6.Image = this.CloseIL.Images[2];
        }

        private void pictureBox6_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox6.Image = this.CloseIL.Images[1];
        }

        private void pictureBox6_MouseHover(object sender, EventArgs e)
        {
            this.pictureBox6.Image = this.CloseIL.Images[1];
        }

        private void pictureBox6_MouseLeave(object sender, EventArgs e)
        {
            this.pictureBox6.Image = this.CloseIL.Images[0];
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            this.RunElevated("Cry-Updater.exe");
            Application.Exit();
        }

        private void pictureBox8_MouseDown(object sender, MouseEventArgs e)
        {
            this.pictureBox8.Image = this.LauncherIL.Images[1];
        }

        private void pictureBox8_MouseEnter(object sender, EventArgs e)
        {
            this.pictureBox8.Image = this.LauncherIL.Images[3];
        }

        private void pictureBox8_MouseHover(object sender, EventArgs e)
        {
            this.pictureBox8.Image = this.LauncherIL.Images[3];
        }

        private void pictureBox8_MouseLeave(object sender, EventArgs e)
        {
            this.pictureBox8.Image = this.LauncherIL.Images[0];
        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        private void RunElevated(string fileName)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo {
                Verb = "runas",
                FileName = fileName
            };
            try
            {
                Process.Start(startInfo);
            }
            catch (Win32Exception)
            {
            }
        }

        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        private void StartGame_Click(object sender, EventArgs e)
        {
            if (this.checkBox1.Checked)
            {
                RegistryKey key;
                if (this.SubKeyExist(@"SOFTWARE\CryOnline\Updater"))
                {
                    key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\CryOnline\Updater", true);
                    key.SetValue("Username", this.textBox1.Text);
                    key.SetValue("Password", this.textBox2.Text);
                }
                else
                {
                    key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\CryOnline\Updater");
                    key.SetValue("Username", this.textBox1.Text);
                    key.SetValue("Password", this.textBox2.Text);
                }
            }
            else if (this.SubKeyExist(@"SOFTWARE\CryOnline\Updater"))
            {
                Registry.CurrentUser.DeleteSubKey(@"SOFTWARE\CryOnline\Updater");
            }
            this.Username = this.textBox1.Text;
            this.Password = this.textBox2.Text;
            base.Hide();
            new Form2().Show(this);
        }

        private void startPatching()
        {
            string str;
            MethodInvoker method = null;
            AsyncCompletedEventHandler handler = null;
            MethodInvoker invoker2 = null;
            this.pictureBox1.Invoke(delegate {
                this.pictureBox1.Enabled = false;
                this.pictureBox1.Image = this.StartGameIL.Images[3];
            });
            WebClient client = new WebClient();
            this.UpdateListStream = new MemoryStream(client.DownloadData("http://cry-community.de/patcher/patchinfolist.txt"));
            this.UpdateList = new List<Update>();
            StreamReader reader = new StreamReader(this.UpdateListStream);
            while (!reader.EndOfStream)
            {
                str = reader.ReadLine();
                Update item = new Update();
                string[] strArray = str.Split(new char[] { '\t' });
                item.Number = Convert.ToInt32(strArray[0]);
                item.FileName = strArray[1];
                this.UpdateList.Add(item);
            }
            reader.Close();
            if (System.IO.File.Exists("./PatchNo.cry"))
            {
                StreamReader reader2 = new StreamReader(System.IO.File.OpenRead("./PatchNo.cry"));
                str = reader2.ReadLine();
                try
                {
                    this.PatchNumber = Convert.ToInt32(str);
                }
                catch
                {
                    this.PatchNumber = 0;
                }
                reader2.Close();
            }
            this.lbl_cltstat.Invoke(() => this.lbl_cltstat.Text = this.PatchNumber.ToString());
            this.lbl_srvstat.Invoke(() => this.lbl_srvstat.Text = this.GetLatestPatchNo(this.UpdateList).ToString());
            using (List<Update>.Enumerator enumerator = this.UpdateList.GetEnumerator())
            {
                Update update;
                while (enumerator.MoveNext())
                {
                    update = enumerator.Current;
                    if (update.Number > this.PatchNumber)
                    {
                        if (method == null)
                        {
                            method = delegate {
                                this.DLProgressBar.Value = 0;
                                this.DLProgressBar.Maximum = 100;
                            };
                        }
                        this.DLProgressBar.Invoke(method);
                        try
                        {
                            WebClient client2 = new WebClient();
                            client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.wc_DownloadProgressChanged);
                            if (handler == null)
                            {
                                handler = (AsyncCompletedEventHandler) ((s, e) => (this.isDownloaded = true));
                            }
                            client2.DownloadFileCompleted += handler;
                            try
                            {
                                client2.DownloadFileAsync(new Uri("http://cry-community.de/patcher/data/" + update.FileName), "temp.7z");
                            }
                            catch (WebException)
                            {
                                MessageBox.Show("Fehler: Download Fehlgeschlagen. Bitte stellen Sie sicher, dass Sie \x00fcber eine konsistente Internetverbindung verf\x00fcgen.", "CryLauncher", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                throw;
                            }
                            while (!this.isDownloaded)
                            {
                            }
                            this.isDownloaded = false;
                            SevenZipExtractor sze = new SevenZipExtractor("temp.7z");
                            sze.ExtractionFinished += delegate (object s, EventArgs e) {
                                sze.Dispose();
                                System.IO.File.Delete("temp.7z");
                                this.lbl_cltstat.Invoke(() => this.lbl_cltstat.Text = update.Number.ToString());
                            };
                            sze.ExtractArchive(".");
                        }
                        catch
                        {
                            this.isSuccess = false;
                            goto Label_02CA;
                        }
                    }
                }
            }
        Label_02CA:
            if (this.isSuccess)
            {
                this.PatchNumber = this.GetLatestPatchNo(this.UpdateList);
                FileStream stream = new FileStream("./PatchNo.cry", FileMode.Create);
                StreamWriter writer = new StreamWriter(stream);
                writer.WriteLine("{0}", this.PatchNumber);
                writer.Flush();
                stream.Close();
                if (invoker2 == null)
                {
                    invoker2 = delegate {
                        this.pictureBox1.Image = this.StartGameIL.Images[0];
                        this.pictureBox1.Enabled = true;
                    };
                }
                this.pictureBox1.Invoke(invoker2);
            }
        }

        public bool SubKeyExist(string Subkey)
        {
            if (Registry.CurrentUser.OpenSubKey(Subkey) == null)
            {
                return false;
            }
            return true;
        }

        public bool SubValueExist(string Subkey, string Value)
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(Subkey);
            if (key == null)
            {
                return false;
            }
            if (key.GetValue(Value) == null)
            {
                return false;
            }
            return true;
        }

        private void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            this.DLProgressBar.Invoke(() => this.DLProgressBar.Value = e.ProgressPercentage);
        }

        public string Password { get; set; }

        public string Username { get; set; }
    }
}

