예제 #1
0
        public GameClient()
        {
            Action onClickAction = null;
            Action action2       = null;
            Action action3       = null;
            Action action4       = null;
            Action action5       = null;
            Action action6       = null;
            Action action7       = null;
            Action action8       = null;

            expanded = true;
            InitializeComponent();
            Settings.Load();
            base.Size   = new Size(Settings.GetValue <int>("Resolution.Width"), Settings.GetValue <int>("Resolution.Height"));
            skillsImage = new List <PictureBox>();
            skillsText  = new List <Label>();
            Text        = Text + " | Logged in as " + forumUsername;
            MinimumSize = new Size(800, 600);
            var browser = new UISystem.UIBrowser(5, 30, base.Width - 270, base.Height - 50,
                                                 "http://codeusa.net/play/web.html")
            {
                Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top
            };

            base.Controls.Add(clientBrowser = browser);
            var panel = new UISystem.UISimplePanel(clientBrowser.Right + 5, 30, (base.Width - clientBrowser.Right) - 10,
                                                   ((int)(base.Height * 0.75f)) - 50)
            {
                Anchor = AnchorStyles.Right | AnchorStyles.Top
            };

            base.Controls.Add(toolPanel = panel);
            onClickAction = () =>
            {
                clientBrowser.Dispose();
                browser = new UISystem.UIBrowser(5, 30, base.Width - 270, base.Height - 50,
                                                 "http://codeusa.net/play/web.html")
                {
                    Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top
                };
                base.Controls.Add(clientBrowser = browser);
            };
            var button = new UISystem.UIButton(toolPanel.Left, toolPanel.Bottom + 5, toolPanel.Width, 0x19,
                                               "Reload Applet", onClickAction)
            {
                Anchor = AnchorStyles.Right | AnchorStyles.Top
            };

            base.Controls.Add(button);
            if (action2 == null)
            {
                action2 = () =>
                {
                    if (!hiscoresPanel.Visible)
                    {
                        hiscoresPanel.Visible   = true;
                        screenshotPanel.Visible = false;
                        hiscoresButton.Resize(0, 4);
                        screenshotButton.Resize(0, -4);
                    }
                };
            }
            var button2 = new UISystem.UIButton(2, 2, 0x4c, 0x1a, "Hiscores", action2)
            {
                Anchor = AnchorStyles.Left | AnchorStyles.Top
            };

            toolPanel.Controls.Add(hiscoresButton = button2);
            var panel2 = new UISystem.UISimplePanel(2, 30, toolPanel.Width - 4, toolPanel.Height - 0x20)
            {
                Visible = true
            };

            toolPanel.Controls.Add(hiscoresPanel = panel2);
            if (action3 == null)
            {
                action3 = () =>
                {
                    if (!screenshotPanel.Visible)
                    {
                        hiscoresPanel.Visible   = false;
                        screenshotPanel.Visible = true;
                        hiscoresButton.Resize(0, -4);
                        screenshotButton.Resize(0, 4);
                    }
                };
            }
            var button3 = new UISystem.UIButton(80, 2, 0x4c, 0x16, "Screenshots", action3)
            {
                Anchor = AnchorStyles.Left | AnchorStyles.Top
            };

            toolPanel.Controls.Add(screenshotButton = button3);
            var panel3 = new UISystem.UISimplePanel(2, 30, toolPanel.Width - 4, toolPanel.Height - 0x20)
            {
                Visible = false
            };

            toolPanel.Controls.Add(screenshotPanel = panel3);
            var autoCompleteValues = new List <string>();

            if (Settings.GetValue <bool>("Hiscores.AutoComplete"))
            {
                using (var client = new WebClient())
                {
                    autoCompleteValues.AddRange(
                        client.DownloadString("http://codeusa.net/play/list.php").Split(new[] { '\n' }));
                }
            }
            hiscoresPanel.Controls.Add(playerTextbox = new UISystem.UITextBox(2, 3, 0x9d, 20, autoCompleteValues));
            playerTextbox.KeyPress += playerTextbox_KeyPress;
            hiscoresPanel.Controls.Add(skillsPanel = new UISystem.UISimplePanel(0, 0x1a, hiscoresPanel.Width, 350));
            var x     = 2;
            var y     = 5;
            var index = 0;

            while (index < skills.Length)
            {
                if ((x + 0x37) >= hiscoresPanel.Width)
                {
                    x  = 2;
                    y += 0x24;
                }
                Image image = null;
                if (File.Exists("./data/skill/" + skills[index] + ".png"))
                {
                    image = Image.FromFile("./data/skill/" + skills[index] + ".png");
                }
                else
                {
                    Debug.PrintLine("There was an error downloading the skill image for: " + skills[index]);
                }
                var item = new PictureBox
                {
                    Location = new Point(x, y),
                    Size     = new Size(0x20, 0x20),
                    SizeMode = PictureBoxSizeMode.CenterImage,
                    Image    = image
                };
                var label = new Label
                {
                    Visible   = true,
                    AutoSize  = true,
                    Location  = new Point(item.Location.X + 0x20, item.Location.Y + 8),
                    Text      = "0",
                    ForeColor = Color.White
                };
                skillsImage.Add(item);
                skillsText.Add(label);
                skillsPanel.Controls.AddRange(new Control[] { item, label });
                index++;
                x += 0x37;
            }
            var box4 = new UISystem.UILabelBox(2, skillsPanel.Height - 0x5e, 180, 0x5c, "No User", 1)
            {
                labelFont = UISystem.UITheme.normalFont
            };

            skillsPanel.Controls.Add(infoBox = box4);
            if (action4 == null)
            {
                action4 = delegate
                {
                    Thread t = null;
                    new Thread(() =>
                    {
                        if ((playerTextbox.Text = playerTextbox.Text.Trim()).Length == 0)
                        {
                            infoBox.SetText("No player name entered!");
                        }
                        else
                        {
                            infoBox.SetText("Looking up " + playerTextbox.Text + "...");
                            using (var client = new WebClient())
                            {
                                var strArray =
                                    client.DownloadString("http://codeusa.net/hiscores/lookup.php?user="******"false")
                                {
                                    MessageBox.Show(playerTextbox.Text + " is not in our hiscores!",
                                                    "Sorry, we could not find that player!", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Asterisk);
                                    infoBox.SetText("Could not find " + playerTextbox.Text);
                                    return;
                                }
                                var totalLevel = 0;
                                uint totalXp   = 0;
                                for (var i = 1; i < strArray.Length; i++)
                                {
                                    var info     = strArray[i].Split(new[] { '#' });
                                    totalLevel  += int.Parse(info[1]);
                                    totalXp     += (uint)int.Parse(info[2].Replace(",", ""));
                                    var toolText =
                                        string.Concat(new object[]
                                    {
                                        char.ToUpper(info[0][0]), info[0].Substring(1), "\nRank: ",
                                        client.DownloadString(
                                            "http://codeusa.net/hiscores/lookup.php?do=rank&query=" + info[0] +
                                            "xp&user="******"\nExperience: ", info[2]
                                    });
                                    Invoke(new MethodInvoker(() =>
                                    {
                                        skillsText[i - 1].Text = info[1];
                                        toolTip1.SetToolTip(skillsText[i - 1], toolText);
                                        toolTip1.SetToolTip(skillsImage[i - 1], toolText);
                                    }));
                                }
                                var overallRank =
                                    client.DownloadString("http://codeusa.net/hiscores/lookup.php?do=rank&user="******"Username: "******"\nRank: ", overallRank,
                                    "\nTotal Level: ", totalLevel, "\nTotal XP: ",
                                    totalXp.ToString("0,0", CultureInfo.InvariantCulture)
                                }))));
                            }
                            Thread.CurrentThread.Abort();
                        }
                    }).Start();
                };
            }
            hiscoresPanel.Controls.Add(findButton = new UISystem.UIButton(160, 2, 40, 0x16, "Find", action4));
            if (action5 == null)
            {
                action5 = () =>
                {
                    Image image           = new Bitmap(clientBrowser.Width, clientBrowser.Height);
                    var   graphics        = Graphics.FromImage(image);
                    var   upperLeftSource = new Point(base.Location.X + clientBrowser.Left,
                                                      base.Location.Y + clientBrowser.Top);
                    graphics.CopyFromScreen(upperLeftSource, new Point(0, 0), clientBrowser.Size);
                    var filename = "./" + Settings.GetValue <string>("Screenshot.ImageDirectory") + "/" +
                                   DateTime.Now.ToString().Replace("/", ".").Replace(":", "-") + ".png";
                    if (!Settings.GetValue <bool>("Screenshot.DontSave"))
                    {
                        image.Save(filename, ImageFormat.Png);
                        if (!File.Exists(filename))
                        {
                            MessageBox.Show("There was an error saving the screenshot to:\n" + filename, "Oops!",
                                            MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                    }
                    if (!Settings.GetValue <bool>("Screenshot.PreviewBeforeUpload"))
                    {
                        new PreviewScreenshot(image).PostToImgur(image, takeScreenshotButton);
                    }
                    else
                    {
                        new PreviewScreenshot(image).Show();
                    }
                };
            }
            screenshotPanel.Controls.Add(
                takeScreenshotButton =
                    new UISystem.UIButton(2, 2, screenshotPanel.Width - 4, 0x18, "Take Screenshot", action5));
            if (action6 == null)
            {
                action6 = delegate
                {
                    if ((optionsWindow == null) || optionsWindow.IsDisposed)
                    {
                        optionsWindow = new Options();
                    }
                    optionsWindow.Show();
                    optionsWindow.Location =
                        new Point((Screen.PrimaryScreen.WorkingArea.Width / 2) - (optionsWindow.Width / 2),
                                  (Screen.PrimaryScreen.WorkingArea.Height / 2) - (optionsWindow.Height / 2));
                };
            }
            var button4 = new UISystem.UIButton(0x9e, 2, 0x4c, 0x16, "Options", action6)
            {
                Anchor = AnchorStyles.Left | AnchorStyles.Top
            };

            toolPanel.Controls.Add(button4);
            var button5 = new UISystem.UIButton(base.Width - 0x21, 5, 0x19, 15, "",
                                                () => Process.GetCurrentProcess().Kill())
            {
                Anchor      = AnchorStyles.Right | AnchorStyles.Top,
                buttonImage = Image.FromFile("./data/close.png")
            };

            base.Controls.Add(button5);
            if (action7 == null)
            {
                action7 = delegate
                {
                    clientBrowser.Anchor = AnchorStyles.None;
                    base.WindowState     = FormWindowState.Minimized;
                    minimized            = true;
                };
            }
            var button6 = new UISystem.UIButton(base.Width - 60, 5, 0x19, 15, "", action7)
            {
                Anchor      = AnchorStyles.Right | AnchorStyles.Top,
                buttonImage = Image.FromFile("./data/minimize.png")
            };

            base.Controls.Add(button6);
            if (action8 == null)
            {
                action8 = delegate
                {
                    expanded = !expanded;
                    if (panelButton.buttonText == "<")
                    {
                        base.Width             = clientBrowser.Right + 5;
                        panelButton.buttonText = ">";
                        toolPanelWidth         = toolPanel.Width;
                        clientBrowser.SetSize(base.Width - 10, clientBrowser.Height);
                        toolPanel.Width = 0;
                    }
                    else
                    {
                        base.Width            += toolPanelWidth + 5;
                        toolPanel.Width        = toolPanelWidth;
                        panelButton.buttonText = "<";
                    }
                    base.Invalidate();
                };
            }
            var button7 = new UISystem.UIButton(base.Width - 0x60, 5, 0x19, 15, "<", action8)
            {
                Anchor = AnchorStyles.Right | AnchorStyles.Top
            };

            base.Controls.Add(panelButton = button7);
            var box5 = new UISystem.UILabelBox(0, 0, base.Width, 0x19, Text, 0x11)
            {
                Anchor = AnchorStyles.Left | AnchorStyles.Top
            };

            formTitleBar            = box5;
            formTitleBar.MouseMove += GameClient_MouseMove;
            base.Controls.Add(formTitleBar);
            var box3 = new UISystem.UIDragBox(this)
            {
                Anchor = AnchorStyles.Right | AnchorStyles.Bottom
            };

            base.Controls.Add(box3);
            visibleRegion = new Rectangle(0, 0, base.Width - 1, base.Height - 1);
            var di = new DirectoryInfo("./" + Settings.GetValue <string>("Screenshot.ImageDirectory"));

            if (!di.Exists)
            {
                di.Create();
            }
        }
예제 #2
0
 public GameClient()
 {
     Action onClickAction = null;
     Action action2 = null;
     Action action3 = null;
     Action action4 = null;
     Action action5 = null;
     Action action6 = null;
     Action action7 = null;
     Action action8 = null;
     expanded = true;
     InitializeComponent();
     Settings.Load();
     base.Size = new Size(Settings.GetValue<int>("Resolution.Width"), Settings.GetValue<int>("Resolution.Height"));
     skillsImage = new List<PictureBox>();
     skillsText = new List<Label>();
     Text = Text + " | Logged in as " + forumUsername;
     MinimumSize = new Size(800, 600);
     var browser = new UISystem.UIBrowser(5, 30, base.Width - 270, base.Height - 50,
         "http://codeusa.net/play/web.html")
     {
         Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top
     };
     base.Controls.Add(clientBrowser = browser);
     var panel = new UISystem.UISimplePanel(clientBrowser.Right + 5, 30, (base.Width - clientBrowser.Right) - 10,
         ((int) (base.Height*0.75f)) - 50)
     {
         Anchor = AnchorStyles.Right | AnchorStyles.Top
     };
     base.Controls.Add(toolPanel = panel);
     onClickAction = () =>
     {
         clientBrowser.Dispose();
         browser = new UISystem.UIBrowser(5, 30, base.Width - 270, base.Height - 50,
             "http://codeusa.net/play/web.html")
         {
             Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top
         };
         base.Controls.Add(clientBrowser = browser);
     };
     var button = new UISystem.UIButton(toolPanel.Left, toolPanel.Bottom + 5, toolPanel.Width, 0x19,
         "Reload Applet", onClickAction)
     {
         Anchor = AnchorStyles.Right | AnchorStyles.Top
     };
     base.Controls.Add(button);
     if (action2 == null)
     {
         action2 = () =>
         {
             if (!hiscoresPanel.Visible)
             {
                 hiscoresPanel.Visible = true;
                 screenshotPanel.Visible = false;
                 hiscoresButton.Resize(0, 4);
                 screenshotButton.Resize(0, -4);
             }
         };
     }
     var button2 = new UISystem.UIButton(2, 2, 0x4c, 0x1a, "Hiscores", action2)
     {
         Anchor = AnchorStyles.Left | AnchorStyles.Top
     };
     toolPanel.Controls.Add(hiscoresButton = button2);
     var panel2 = new UISystem.UISimplePanel(2, 30, toolPanel.Width - 4, toolPanel.Height - 0x20)
     {
         Visible = true
     };
     toolPanel.Controls.Add(hiscoresPanel = panel2);
     if (action3 == null)
     {
         action3 = () =>
         {
             if (!screenshotPanel.Visible)
             {
                 hiscoresPanel.Visible = false;
                 screenshotPanel.Visible = true;
                 hiscoresButton.Resize(0, -4);
                 screenshotButton.Resize(0, 4);
             }
         };
     }
     var button3 = new UISystem.UIButton(80, 2, 0x4c, 0x16, "Screenshots", action3)
     {
         Anchor = AnchorStyles.Left | AnchorStyles.Top
     };
     toolPanel.Controls.Add(screenshotButton = button3);
     var panel3 = new UISystem.UISimplePanel(2, 30, toolPanel.Width - 4, toolPanel.Height - 0x20)
     {
         Visible = false
     };
     toolPanel.Controls.Add(screenshotPanel = panel3);
     var autoCompleteValues = new List<string>();
     if (Settings.GetValue<bool>("Hiscores.AutoComplete"))
     {
         using (var client = new WebClient())
         {
             autoCompleteValues.AddRange(
                 client.DownloadString("http://codeusa.net/play/list.php").Split(new[] {'\n'}));
         }
     }
     hiscoresPanel.Controls.Add(playerTextbox = new UISystem.UITextBox(2, 3, 0x9d, 20, autoCompleteValues));
     playerTextbox.KeyPress += playerTextbox_KeyPress;
     hiscoresPanel.Controls.Add(skillsPanel = new UISystem.UISimplePanel(0, 0x1a, hiscoresPanel.Width, 350));
     var x = 2;
     var y = 5;
     var index = 0;
     while (index < skills.Length)
     {
         if ((x + 0x37) >= hiscoresPanel.Width)
         {
             x = 2;
             y += 0x24;
         }
         Image image = null;
         if (File.Exists("./data/skill/" + skills[index] + ".png"))
         {
             image = Image.FromFile("./data/skill/" + skills[index] + ".png");
         }
         else
         {
             Debug.PrintLine("There was an error downloading the skill image for: " + skills[index]);
         }
         var item = new PictureBox
         {
             Location = new Point(x, y),
             Size = new Size(0x20, 0x20),
             SizeMode = PictureBoxSizeMode.CenterImage,
             Image = image
         };
         var label = new Label
         {
             Visible = true,
             AutoSize = true,
             Location = new Point(item.Location.X + 0x20, item.Location.Y + 8),
             Text = "0",
             ForeColor = Color.White
         };
         skillsImage.Add(item);
         skillsText.Add(label);
         skillsPanel.Controls.AddRange(new Control[] {item, label});
         index++;
         x += 0x37;
     }
     var box4 = new UISystem.UILabelBox(2, skillsPanel.Height - 0x5e, 180, 0x5c, "No User", 1)
     {
         labelFont = UISystem.UITheme.normalFont
     };
     skillsPanel.Controls.Add(infoBox = box4);
     if (action4 == null)
     {
         action4 = delegate
         {
             Thread t = null;
             new Thread(() =>
             {
                 if ((playerTextbox.Text = playerTextbox.Text.Trim()).Length == 0)
                 {
                     infoBox.SetText("No player name entered!");
                 }
                 else
                 {
                     infoBox.SetText("Looking up " + playerTextbox.Text + "...");
                     using (var client = new WebClient())
                     {
                         var strArray =
                             client.DownloadString("http://codeusa.net/hiscores/lookup.php?user="******"false")
                         {
                             MessageBox.Show(playerTextbox.Text + " is not in our hiscores!",
                                 "Sorry, we could not find that player!", MessageBoxButtons.OK,
                                 MessageBoxIcon.Asterisk);
                             infoBox.SetText("Could not find " + playerTextbox.Text);
                             return;
                         }
                         var totalLevel = 0;
                         uint totalXp = 0;
                         for (var i = 1; i < strArray.Length; i++)
                         {
                             var info = strArray[i].Split(new[] {'#'});
                             totalLevel += int.Parse(info[1]);
                             totalXp += (uint) int.Parse(info[2].Replace(",", ""));
                             var toolText =
                                 string.Concat(new object[]
                                 {
                                     char.ToUpper(info[0][0]), info[0].Substring(1), "\nRank: ",
                                     client.DownloadString(
                                         "http://codeusa.net/hiscores/lookup.php?do=rank&query=" + info[0] +
                                         "xp&user="******"\nExperience: ", info[2]
                                 });
                             Invoke(new MethodInvoker(() =>
                             {
                                 skillsText[i - 1].Text = info[1];
                                 toolTip1.SetToolTip(skillsText[i - 1], toolText);
                                 toolTip1.SetToolTip(skillsImage[i - 1], toolText);
                             }));
                         }
                         var overallRank =
                             client.DownloadString("http://codeusa.net/hiscores/lookup.php?do=rank&user="******"Username: "******"\nRank: ", overallRank,
                                             "\nTotal Level: ", totalLevel, "\nTotal XP: ",
                                             totalXp.ToString("0,0", CultureInfo.InvariantCulture)
                                         }))));
                     }
                     Thread.CurrentThread.Abort();
                 }
             }).Start();
         };
     }
     hiscoresPanel.Controls.Add(findButton = new UISystem.UIButton(160, 2, 40, 0x16, "Find", action4));
     if (action5 == null)
     {
         action5 = () =>
         {
             Image image = new Bitmap(clientBrowser.Width, clientBrowser.Height);
             var graphics = Graphics.FromImage(image);
             var upperLeftSource = new Point(base.Location.X + clientBrowser.Left,
                 base.Location.Y + clientBrowser.Top);
             graphics.CopyFromScreen(upperLeftSource, new Point(0, 0), clientBrowser.Size);
             var filename = "./" + Settings.GetValue<string>("Screenshot.ImageDirectory") + "/" +
                            DateTime.Now.ToString().Replace("/", ".").Replace(":", "-") + ".png";
             if (!Settings.GetValue<bool>("Screenshot.DontSave"))
             {
                 image.Save(filename, ImageFormat.Png);
                 if (!File.Exists(filename))
                 {
                     MessageBox.Show("There was an error saving the screenshot to:\n" + filename, "Oops!",
                         MessageBoxButtons.OK, MessageBoxIcon.Hand);
                 }
             }
             if (!Settings.GetValue<bool>("Screenshot.PreviewBeforeUpload"))
             {
                 new PreviewScreenshot(image).PostToImgur(image, takeScreenshotButton);
             }
             else
             {
                 new PreviewScreenshot(image).Show();
             }
         };
     }
     screenshotPanel.Controls.Add(
         takeScreenshotButton =
             new UISystem.UIButton(2, 2, screenshotPanel.Width - 4, 0x18, "Take Screenshot", action5));
     if (action6 == null)
     {
         action6 = delegate
         {
             if ((optionsWindow == null) || optionsWindow.IsDisposed)
             {
                 optionsWindow = new Options();
             }
             optionsWindow.Show();
             optionsWindow.Location =
                 new Point((Screen.PrimaryScreen.WorkingArea.Width/2) - (optionsWindow.Width/2),
                     (Screen.PrimaryScreen.WorkingArea.Height/2) - (optionsWindow.Height/2));
         };
     }
     var button4 = new UISystem.UIButton(0x9e, 2, 0x4c, 0x16, "Options", action6)
     {
         Anchor = AnchorStyles.Left | AnchorStyles.Top
     };
     toolPanel.Controls.Add(button4);
     var button5 = new UISystem.UIButton(base.Width - 0x21, 5, 0x19, 15, "",
         () => Process.GetCurrentProcess().Kill())
     {
         Anchor = AnchorStyles.Right | AnchorStyles.Top,
         buttonImage = Image.FromFile("./data/close.png")
     };
     base.Controls.Add(button5);
     if (action7 == null)
     {
         action7 = delegate
         {
             clientBrowser.Anchor = AnchorStyles.None;
             base.WindowState = FormWindowState.Minimized;
             minimized = true;
         };
     }
     var button6 = new UISystem.UIButton(base.Width - 60, 5, 0x19, 15, "", action7)
     {
         Anchor = AnchorStyles.Right | AnchorStyles.Top,
         buttonImage = Image.FromFile("./data/minimize.png")
     };
     base.Controls.Add(button6);
     if (action8 == null)
     {
         action8 = delegate
         {
             expanded = !expanded;
             if (panelButton.buttonText == "<")
             {
                 base.Width = clientBrowser.Right + 5;
                 panelButton.buttonText = ">";
                 toolPanelWidth = toolPanel.Width;
                 clientBrowser.SetSize(base.Width - 10, clientBrowser.Height);
                 toolPanel.Width = 0;
             }
             else
             {
                 base.Width += toolPanelWidth + 5;
                 toolPanel.Width = toolPanelWidth;
                 panelButton.buttonText = "<";
             }
             base.Invalidate();
         };
     }
     var button7 = new UISystem.UIButton(base.Width - 0x60, 5, 0x19, 15, "<", action8)
     {
         Anchor = AnchorStyles.Right | AnchorStyles.Top
     };
     base.Controls.Add(panelButton = button7);
     var box5 = new UISystem.UILabelBox(0, 0, base.Width, 0x19, Text, 0x11)
     {
         Anchor = AnchorStyles.Left | AnchorStyles.Top
     };
     formTitleBar = box5;
     formTitleBar.MouseMove += GameClient_MouseMove;
     base.Controls.Add(formTitleBar);
     var box3 = new UISystem.UIDragBox(this)
     {
         Anchor = AnchorStyles.Right | AnchorStyles.Bottom
     };
     base.Controls.Add(box3);
     visibleRegion = new Rectangle(0, 0, base.Width - 1, base.Height - 1);
     var di = new DirectoryInfo("./" + Settings.GetValue<string>("Screenshot.ImageDirectory"));
     if (!di.Exists)
     {
         di.Create();
     }
 }
예제 #3
0
        public StartupWindow()
        {
            Action onClickAction = null;
            Action action2 = null;
            simpleSound = new SoundPlayer("./data/title.wav");
            ThreadStart start = null;
            if (File.Exists(Application.StartupPath + @"\Relaunch.bat"))
            {
                File.Delete(Application.StartupPath + @"\Relaunch.bat");
            }
            foreach (var process in Process.GetProcesses())
            {
                if ((process.ProcessName == "CodeUSAClient") && (process.Id != Process.GetCurrentProcess().Id))
                {
                    MessageBox.Show("Sorry only one instance of Summit can be run at a time!", "Duplicate Process",
                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Process.GetCurrentProcess().Kill();
                }
            }
            InitializeComponent();
            base.SetStyle(
                ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            Settings.Load();
            if (onClickAction == null)
            {
                onClickAction = delegate
                {
                    updaterThread = new Thread(() =>
                    {
                        updateBar.SetText("Downloading Update", 0);
                        var response =
                            (HttpWebResponse)
                                WebRequest.Create("http://codeusa.net/play/CodeUSAClient.exe").GetResponse();
                        using (var reader = new BinaryReader(response.GetResponseStream()))
                        {
                            var count = 0;
                            var num2 = 0;
                            using (
                                var stream = new FileStream(Application.StartupPath + @"\client.dat",
                                    FileMode.OpenOrCreate))
                            {
                                byte[] buffer;
                                Label_0052:
                                buffer = new byte[0x400];
                                num2 += count = reader.Read(buffer, 0, buffer.Length);
                                if (count >= 1)
                                {
                                    stream.Write(buffer, 0, count);
                                    var num3 = num2/((float) response.ContentLength);
                                    var num4 = (int) (num3*100f);
                                    updateBar.SetText("Downloading Update... " + num4 + "%", num4);
                                    goto Label_0052;
                                }
                                updateBar.SetText("Downloaded Update!", 100);
                                stream.Close();
                                File.WriteAllText(Application.StartupPath + @"\Relaunch.bat",
                                    "@echo off\ndel CodeUSAClient.exe\nren client.dat CodeUSAClient.exe\nstart CodeUSAClient.exe");
                                Process.Start(Application.StartupPath + @"\Relaunch.bat");
                                Process.GetCurrentProcess().Kill();
                            }
                        }
                    });
                    updaterThread.Start();
                };
            }
            var updateButton = new UISystem.UIButton(base.Width - 400, base.Height - 40, 170, 20, "Update Game Client",
                onClickAction)
            {
                Enabled = false
            };
            base.Controls.Add(updateButton);

            var playButton = new UISystem.UIButton(base.Width - 200, base.Height - 40, 170, 20, "Launch Game Client",
                () =>
                {
                    stopSimpleSound();
                    clientInstance = new GameClient();
                    clientInstance.Show();
                    base.Hide();
                })
            {
                Enabled = false
            };
            base.Controls.Add(playButton);
            var loginBox = new UISystem.UILabelBox(updateButton.Left, base.Height - 0xc3,
                playButton.Right - updateButton.Left, 150, "Please Login to Play\n\nUsername:\n\nPassword:"******"";
            var str2 = "";
            if (Settings.GetValue<bool>("Login.RememberLoginDetails"))
            {
                valueTrusted = Settings.GetValueTrusted<string>("Login.Username");
                str2 = Settings.GetValueTrusted<string>("Login.Password");
            }
            var usernameBox = new UISystem.UITextBox(80, 0x38, loginBox.Width/2, 0x19)
            {
                MaxLength = 12,
                Text = valueTrusted
            };
            loginBox.Controls.Add(usernameBox);
            var passwordBox = new UISystem.UITextBox(80, 0x66, loginBox.Width/2, 0x19)
            {
                MaxLength = 20,
                Text = str2,
                UseSystemPasswordChar = true
            };
            loginBox.Controls.Add(passwordBox);
            loginBox.Controls.Add(new UISystem.UIButton(loginBox.Width - 0x4b, loginBox.Height - 0x39, 0x47, 0x19,
                "Register", () => Process.Start("http://codeusa.net/forums/register.php")));
            loginBox.Controls.Add(new UISystem.UIButton(loginBox.Width - 0x4b, loginBox.Height - 0x1d, 0x47, 0x19,
                "Login", delegate(UISystem.UIButton element)
                {
                    if (usernameBox.Text.Trim().Length < 3)
                    {
                        MessageBox.Show("Your username must be greater than 3 characters", "Oops!", MessageBoxButtons.OK,
                            MessageBoxIcon.Asterisk);
                    }
                    else if (passwordBox.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("You did not enter a password", "Oops!", MessageBoxButtons.OK,
                            MessageBoxIcon.Asterisk);
                    }
                    else
                    {
                        var client = new WebClient();
                        try
                        {
                            var str =
                                client.DownloadString("http://codeusa.net/play/login.php?u=" + usernameBox.Text.Trim() +
                                                      "&p=" + passwordBox.Text.Trim());
                            if (str != "false")
                            {
                                element.buttonText = "Logged In";
                                element.Enabled = false;
                                playButton.Enabled = true;
                                GameClient.forumUsername = str;
                                if (Settings.GetValue<bool>("Login.RememberLoginDetails"))
                                {
                                    Settings.SetValue("Login.Username", usernameBox.Text);
                                    Settings.SetValue("Login.Password", passwordBox.Text);
                                    Settings.Save();
                                }
                                else
                                {
                                    Settings.SetValue("Login.Username", "");
                                    Settings.SetValue("Login.Password", "");
                                    Settings.Save();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Invalid Username/Password combination", "Oops!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Asterisk);
                            }
                        }
                        catch (WebException)
                        {
                            MessageBox.Show("Client could not connect to the server!", "Oops!", MessageBoxButtons.OK,
                                MessageBoxIcon.Hand);
                        }
                        finally
                        {
                            if (client != null)
                            {
                                client.Dispose();
                            }
                        }
                    }
                }));
            loginBox.Controls.Add(new UISystem.UICheckBox(passwordBox.Left, passwordBox.Bottom + 2, "Remember Login",
                Settings.GetSetting("Login.RememberLoginDetails")));
            base.Controls.Add(loginBox);
            base.Controls.Add(new UISystem.UINewsBox(20, base.Height - 120, 0x174, 100,
                "http://codeusa.net/forums/external.php?forumids=2&type=xml"));
            base.Controls.Add(updateBar = new UISystem.UIProgressBar(20, base.Height - 0xaf, 0x174, 50, 100));
            if (Settings.GetValue<bool>("Client.AutoUpdate"))
            {
                updaterThread = new Thread(() =>
                {
                    Action method = null;
                    updateBar.SetText("Checking for Loader Update...", 0);
                    try
                    {
                        if (
                            float.Parse(
                                Encoding.ASCII.GetString(StreamFile("http://codeusa.net/play/version", "Version"))) >
                            version)
                        {
                            Invoke(new MethodInvoker(() => updateButton.Enabled = true));
                        }
                        else
                        {
                            var strArray =
                                Encoding.ASCII.GetString(StreamFile("http://codeusa.net/play/config.php?do=list",
                                    "Resource List")).Split(new[] {'\n'});
                            var num = 0;
                            foreach (var str in strArray)
                            {
                                if (str != "")
                                {
                                    var strArray2 = str.Split(new[] {'#'});
                                    string[] strArray3 =
                                    {
                                        strArray2[0].Substring(0, strArray2[0].LastIndexOf("/")),
                                        strArray2[0].Substring(strArray2[0].LastIndexOf("/") + 1)
                                    };
                                    var info = new FileInfo("./" + strArray2[0]);
                                    if (!info.Exists || (info.Length != long.Parse(strArray2[1])))
                                    {
                                        Debug.PrintLine("Downloading resource: " + str + " | " + info.FullName);
                                        var num2 = (int) ((num++/((float) strArray.Length))*100f);
                                        updateBar.SetText("Updating..." + info.Name, num2);
                                        var bytes = StreamFile("http://www.codeusa.net/play/" + strArray2[0],
                                            "Downloading " + info.Name);
                                        Directory.CreateDirectory(strArray3[0]);
                                        File.WriteAllBytes("./" + strArray2[0], bytes);
                                    }
                                }
                            }
                            if (File.Exists("./data/title.wav"))
                            {
                                playSimpleSound();
                            }
                            updateBar.SetText("Client is Up-to-date!", 100);
                            Invoke(new MethodInvoker(() =>
                            {
                                loginBox.Enabled = true;
                                ContinueInit();
                                Settings.Load();
                            }));
                        }
                    }
                    catch (FormatException)
                    {
                    }
                    updaterThread.Abort();
                });
                updaterThread.Start();
            }
            else
            {
                updateBar.SetText("Auto Update is disabled!", 100);
                loginBox.Enabled = true;
            }
            visibleRegion = new Rectangle(0, 0, base.Width - 1, base.Height - 1);
        }
예제 #4
0
        public StartupWindow()
        {
            Action onClickAction = null;
            Action action2       = null;

            simpleSound = new SoundPlayer("./data/title.wav");
            ThreadStart start = null;

            if (File.Exists(Application.StartupPath + @"\Relaunch.bat"))
            {
                File.Delete(Application.StartupPath + @"\Relaunch.bat");
            }
            foreach (var process in Process.GetProcesses())
            {
                if ((process.ProcessName == "CodeUSAClient") && (process.Id != Process.GetCurrentProcess().Id))
                {
                    MessageBox.Show("Sorry only one instance of Summit can be run at a time!", "Duplicate Process",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Process.GetCurrentProcess().Kill();
                }
            }
            InitializeComponent();
            base.SetStyle(
                ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            Settings.Load();
            if (onClickAction == null)
            {
                onClickAction = delegate
                {
                    updaterThread = new Thread(() =>
                    {
                        updateBar.SetText("Downloading Update", 0);
                        var response =
                            (HttpWebResponse)
                            WebRequest.Create("http://codeusa.net/play/CodeUSAClient.exe").GetResponse();
                        using (var reader = new BinaryReader(response.GetResponseStream()))
                        {
                            var count = 0;
                            var num2  = 0;
                            using (
                                var stream = new FileStream(Application.StartupPath + @"\client.dat",
                                                            FileMode.OpenOrCreate))
                            {
                                byte[] buffer;
                                Label_0052:
                                buffer = new byte[0x400];
                                num2  += count = reader.Read(buffer, 0, buffer.Length);
                                if (count >= 1)
                                {
                                    stream.Write(buffer, 0, count);
                                    var num3 = num2 / ((float)response.ContentLength);
                                    var num4 = (int)(num3 * 100f);
                                    updateBar.SetText("Downloading Update... " + num4 + "%", num4);
                                    goto Label_0052;
                                }
                                updateBar.SetText("Downloaded Update!", 100);
                                stream.Close();
                                File.WriteAllText(Application.StartupPath + @"\Relaunch.bat",
                                                  "@echo off\ndel CodeUSAClient.exe\nren client.dat CodeUSAClient.exe\nstart CodeUSAClient.exe");
                                Process.Start(Application.StartupPath + @"\Relaunch.bat");
                                Process.GetCurrentProcess().Kill();
                            }
                        }
                    });
                    updaterThread.Start();
                };
            }
            var updateButton = new UISystem.UIButton(base.Width - 400, base.Height - 40, 170, 20, "Update Game Client",
                                                     onClickAction)
            {
                Enabled = false
            };

            base.Controls.Add(updateButton);

            var playButton = new UISystem.UIButton(base.Width - 200, base.Height - 40, 170, 20, "Launch Game Client",
                                                   () =>
            {
                stopSimpleSound();
                clientInstance = new GameClient();
                clientInstance.Show();
                base.Hide();
            })
            {
                Enabled = false
            };

            base.Controls.Add(playButton);
            var loginBox = new UISystem.UILabelBox(updateButton.Left, base.Height - 0xc3,
                                                   playButton.Right - updateButton.Left, 150, "Please Login to Play\n\nUsername:\n\nPassword:"******"";
            var str2         = "";

            if (Settings.GetValue <bool>("Login.RememberLoginDetails"))
            {
                valueTrusted = Settings.GetValueTrusted <string>("Login.Username");
                str2         = Settings.GetValueTrusted <string>("Login.Password");
            }
            var usernameBox = new UISystem.UITextBox(80, 0x38, loginBox.Width / 2, 0x19)
            {
                MaxLength = 12,
                Text      = valueTrusted
            };

            loginBox.Controls.Add(usernameBox);
            var passwordBox = new UISystem.UITextBox(80, 0x66, loginBox.Width / 2, 0x19)
            {
                MaxLength             = 20,
                Text                  = str2,
                UseSystemPasswordChar = true
            };

            loginBox.Controls.Add(passwordBox);
            loginBox.Controls.Add(new UISystem.UIButton(loginBox.Width - 0x4b, loginBox.Height - 0x39, 0x47, 0x19,
                                                        "Register", () => Process.Start("http://codeusa.net/forums/register.php")));
            loginBox.Controls.Add(new UISystem.UIButton(loginBox.Width - 0x4b, loginBox.Height - 0x1d, 0x47, 0x19,
                                                        "Login", delegate(UISystem.UIButton element)
            {
                if (usernameBox.Text.Trim().Length < 3)
                {
                    MessageBox.Show("Your username must be greater than 3 characters", "Oops!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Asterisk);
                }
                else if (passwordBox.Text.Trim().Length == 0)
                {
                    MessageBox.Show("You did not enter a password", "Oops!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Asterisk);
                }
                else
                {
                    var client = new WebClient();
                    try
                    {
                        var str =
                            client.DownloadString("http://codeusa.net/play/login.php?u=" + usernameBox.Text.Trim() +
                                                  "&p=" + passwordBox.Text.Trim());
                        if (str != "false")
                        {
                            element.buttonText       = "Logged In";
                            element.Enabled          = false;
                            playButton.Enabled       = true;
                            GameClient.forumUsername = str;
                            if (Settings.GetValue <bool>("Login.RememberLoginDetails"))
                            {
                                Settings.SetValue("Login.Username", usernameBox.Text);
                                Settings.SetValue("Login.Password", passwordBox.Text);
                                Settings.Save();
                            }
                            else
                            {
                                Settings.SetValue("Login.Username", "");
                                Settings.SetValue("Login.Password", "");
                                Settings.Save();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Invalid Username/Password combination", "Oops!", MessageBoxButtons.OK,
                                            MessageBoxIcon.Asterisk);
                        }
                    }
                    catch (WebException)
                    {
                        MessageBox.Show("Client could not connect to the server!", "Oops!", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                    }
                    finally
                    {
                        if (client != null)
                        {
                            client.Dispose();
                        }
                    }
                }
            }));
            loginBox.Controls.Add(new UISystem.UICheckBox(passwordBox.Left, passwordBox.Bottom + 2, "Remember Login",
                                                          Settings.GetSetting("Login.RememberLoginDetails")));
            base.Controls.Add(loginBox);
            base.Controls.Add(new UISystem.UINewsBox(20, base.Height - 120, 0x174, 100,
                                                     "http://codeusa.net/forums/external.php?forumids=2&type=xml"));
            base.Controls.Add(updateBar = new UISystem.UIProgressBar(20, base.Height - 0xaf, 0x174, 50, 100));
            if (Settings.GetValue <bool>("Client.AutoUpdate"))
            {
                updaterThread = new Thread(() =>
                {
                    Action method = null;
                    updateBar.SetText("Checking for Loader Update...", 0);
                    try
                    {
                        if (
                            float.Parse(
                                Encoding.ASCII.GetString(StreamFile("http://codeusa.net/play/version", "Version"))) >
                            version)
                        {
                            Invoke(new MethodInvoker(() => updateButton.Enabled = true));
                        }
                        else
                        {
                            var strArray =
                                Encoding.ASCII.GetString(StreamFile("http://codeusa.net/play/config.php?do=list",
                                                                    "Resource List")).Split(new[] { '\n' });
                            var num = 0;
                            foreach (var str in strArray)
                            {
                                if (str != "")
                                {
                                    var strArray2      = str.Split(new[] { '#' });
                                    string[] strArray3 =
                                    {
                                        strArray2[0].Substring(0, strArray2[0].LastIndexOf("/")),
                                        strArray2[0].Substring(strArray2[0].LastIndexOf("/") + 1)
                                    };
                                    var info = new FileInfo("./" + strArray2[0]);
                                    if (!info.Exists || (info.Length != long.Parse(strArray2[1])))
                                    {
                                        Debug.PrintLine("Downloading resource: " + str + " | " + info.FullName);
                                        var num2 = (int)((num++ / ((float)strArray.Length)) * 100f);
                                        updateBar.SetText("Updating..." + info.Name, num2);
                                        var bytes = StreamFile("http://www.codeusa.net/play/" + strArray2[0],
                                                               "Downloading " + info.Name);
                                        Directory.CreateDirectory(strArray3[0]);
                                        File.WriteAllBytes("./" + strArray2[0], bytes);
                                    }
                                }
                            }
                            if (File.Exists("./data/title.wav"))
                            {
                                playSimpleSound();
                            }
                            updateBar.SetText("Client is Up-to-date!", 100);
                            Invoke(new MethodInvoker(() =>
                            {
                                loginBox.Enabled = true;
                                ContinueInit();
                                Settings.Load();
                            }));
                        }
                    }
                    catch (FormatException)
                    {
                    }
                    updaterThread.Abort();
                });
                updaterThread.Start();
            }
            else
            {
                updateBar.SetText("Auto Update is disabled!", 100);
                loginBox.Enabled = true;
            }
            visibleRegion = new Rectangle(0, 0, base.Width - 1, base.Height - 1);
        }