Esempio n. 1
0
        } //makes the loading look less shitty


        private void MainForm_Load(object sender, EventArgs e)
        {
            var watch = Pool.Get <Stopwatch>();

            try
            {
                watch.Restart();

                AdminLaunchButton.Visible = false;
                if (!Program.IsElevated)
                {
                    AdminLaunchButton.Image = BitmapHelper.ResizeImage(SystemIcons.Shield.ToBitmap(), new Size(16, 16));
                }


                DvarsCheckBox.Visible = Debugger.IsAttached;

                var argsSB = Pool.Get <StringBuilder>();
                try
                {
                    argsSB.Clear();

                    var cmdArgs = Environment.GetCommandLineArgs();
                    for (int i = 0; i < cmdArgs.Length; i++)
                    {
                        var arg = cmdArgs[i];
                        if (arg.IndexOf(Application.ProductName, StringComparison.OrdinalIgnoreCase) >= 0 || arg.IndexOf(Application.StartupPath, StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            continue;
                        }
                        if (arg.Equals("-unlock", StringComparison.OrdinalIgnoreCase))
                        {
                            DvarsCheckBox.Visible = true;
                        }
                        if (arg.Equals("-unlock=1", StringComparison.OrdinalIgnoreCase))
                        {
                            DvarsCheckBox.Visible = true;
                            DvarsCheckBox.Checked = true;
                        }

                        if (arg.Equals("-fog=1", StringComparison.OrdinalIgnoreCase))
                        {
                            settings.Fog = true;
                        }
                        else if (arg.Equals("-fog=0", StringComparison.OrdinalIgnoreCase))
                        {
                            settings.Fog = false;
                        }

                        if (arg.Equals("-launch", StringComparison.OrdinalIgnoreCase))
                        {
                            StartGameButton.PerformClick();
                        }

                        if (arg.Equals("-debug", StringComparison.OrdinalIgnoreCase))
                        {
                            IsDev = true;
                        }

                        if (Program.IsElevated) //ensure elevation before checking these args, otherwise a user could potentially make these forms appear without being elevated & cause an exception
                        {
                            if (arg.Equals("-hotkeys", StringComparison.OrdinalIgnoreCase))
                            {
                                new Hotkeys().Show();
                            }

                            if (arg.Equals("-cdkeymanager", StringComparison.OrdinalIgnoreCase))
                            {
                                var form = new CDKeyManagerForm();
                                form.Show();
                                form.BeginInvoke((MethodInvoker) delegate
                                {
                                    form.BringToFront();
                                    form.Select();
                                });
                                form.Location = new Point((int)(Location.X / 3.25f), (int)(Location.Y / 3f));
                            }
                        }



                        if (arg.IndexOf("-fov=", StringComparison.OrdinalIgnoreCase) >= 0)
                        {
                            if (decimal.TryParse(arg.Split('=')[1], out decimal FoV))
                            {
                                SetFoVNumeric(FoV);
                            }
                        }

                        argsSB.Append(arg).Append(" ");
                    }

                    if (argsSB.Length > 1)
                    {
                        argsSB.Length -= 1;
                        var argStr = argsSB.ToString();
                        Log.WriteLine(argsSB.Clear().Append("Launched program with args: ").Append(argStr).ToString());
                    }
                }
                finally { Pool.Free(ref argsSB); }

                StartUpdates();

                Task.Run(() =>
                {
                    try
                    {
                        if (string.IsNullOrEmpty(settings.InstallPath) || !Directory.Exists(settings.InstallPath))
                        {
                            var scannedPath = PathScanner.ScanForGamePath();
                            if (!string.IsNullOrEmpty(scannedPath))
                            {
                                MessageBox.Show("Automatically detected game path: " + Environment.NewLine + scannedPath, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                settings.InstallPath = scannedPath;
                            }
                            else
                            {
                                ipDialog.Description = "Locate your Call of Duty installation directory";
                                var ipResult         = ipDialog.ShowDialog();
                                if (ipResult == DialogResult.Cancel)
                                {
                                    Application.Exit();
                                    return;
                                }
                                var selectedPath     = ipDialog.SelectedPath;
                                settings.InstallPath = selectedPath;
                                MessageBox.Show("Set install path to: " + selectedPath, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An error has occurred: " + ex.Message + Environment.NewLine + "Please refer to the log for more information.");
                        Log.WriteLine("An exception happened on Install Path code:" + Environment.NewLine + ex.ToString());
                    }
                });

                UpdateProcessBox();

                AdminLaunchButton.Visible = !Program.IsElevated && (SelectedMemory?.ProcMemory?.RequiresElevation() ?? false);

                SetFoVNumeric(settings.FoV);

                MinimizeCheckBox.Checked     = settings.MinimizeToTray;
                FogCheckBox.Checked          = settings.Fog;
                fogToolStripMenuItem.Checked = settings.Fog;
                LaunchParametersTB.Text      = settings.CommandLine;

                if (settings.TrackGameTime)
                {
                    AccessGameTimeLabel();
                }
                else
                {
                    GameTimeLabel.Visible = false;
                    CurSessionGT.Visible  = false;
                    GameTracker.Enabled   = false;
                }

                if (IsDev)
                {
                    UpdateButton.Visible = true;
                }
            }
            finally
            {
                watch.Stop();

                var sb = Pool.Get <StringBuilder>();
                try
                {
                    var timeTaken = watch.Elapsed;
                    Console.WriteLine(sb.Clear().Append("Form load took: ").Append(timeTaken.TotalMilliseconds).Append("ms").ToString());

                    if (timeTaken.TotalMilliseconds > 100)
                    {
                        Log.WriteLine(sb.Clear().Append("Startup took: ").Append(timeTaken.TotalMilliseconds).Append("ms (this is too long!)").ToString());
                    }

                    Log.WriteLine(sb.Clear().Append("Successfully started application, version ").Append(Application.ProductVersion).ToString());
                }
                finally { Pool.Free(ref sb); }
            }
        }
Esempio n. 2
0
        } //makes the loading look less shitty

        public CDKeyManagerForm()
        {
            Instance = this;
            InitializeComponent();
        }