Exemplo n.º 1
0
        private static Launcher CreateLauncher(Demo demo, Boolean?sourceEngine)
        {
            Launcher launcher = null;

            if (demo == null)
            {
                Debug.Assert(sourceEngine != null);

                if (sourceEngine == true)
                {
                    return(new SourceLauncher());
                }
                else
                {
                    return(new HalfLifeSteamLauncher());
                }
            }
            else
            {
                switch (demo.Engine)
                {
                case Demo.Engines.HalfLife:
                    if (((HalfLifeDemo)demo).ConvertNetworkProtocol())
                    {
                        if (Config.Settings.PlaybackProgramOldCs == ProgramSettings.PlaybackProgram.CounterStrike)
                        {
                            launcher = new CounterStrikeLauncher();
                        }
                        else
                        {
                            launcher = new HalfLifeSteamLauncher();
                        }
                    }
                    else
                    {
                        launcher = new HalfLifeLauncher();
                    }
                    break;

                case Demo.Engines.HalfLifeSteam:
                    if (((HalfLifeDemo)demo).NetworkProtocol == 47 && demo.GameFolderName == "cstrike" && Config.Settings.PlaybackProgramOldCs == ProgramSettings.PlaybackProgram.CounterStrike)
                    {
                        launcher = new CounterStrikeLauncher();
                    }
                    else
                    {
                        launcher = new HalfLifeSteamLauncher();
                    }
                    break;

                case Demo.Engines.Source:
                    launcher = new SourceLauncher();
                    break;
                }
            }

            if (launcher == null)
            {
                return(null);
            }

            launcher.Demo = demo;
            return(launcher);
        }
Exemplo n.º 2
0
        private void ConnectToServer(Server server)
        {
            if (server == null)
            {
                return;
            }

            if (server.State != Server.StateEnum.Succeeded)
            {
                return;
            }

            launcher = LauncherFactory.CreateLauncher(server.SourceEngine);
            launcher.JoiningServer = true;
            launcher.ServerSourceEngine = server.SourceEngine;
            launcher.ServerAddress = server.Address;
            launcher.ServerGameFolderName = server.GameFolder;
            launcher.ServerMapName = server.Map;
            launcher.Interface = (ILauncher)this;

            try
            {
                launcher.Verify();
            }
            catch (Launcher.AbortLaunchException)
            {
                return;
            }
            catch (ApplicationException ex)
            {
                Common.Message(this, null, ex);
                return;
            }
            catch (Exception ex)
            {
                Common.Message(this, null, ex, MessageWindow.Flags.Error);
                return;
            }

            canOpenServer = false;
            MinimiseToTray();

            // launch the game
            try
            {
                launcher.Run();
            }
            catch (Exception ex)
            {
                RestoreFromTray();
                FileOperationList.Execute();
                canOpenServer = true;
                Common.Message(this, "Error launching game.", ex, MessageWindow.Flags.Error);
                return;
            }

            SystemTrayIcon.Text = "Looking for game process...";

            // enable the tray context menu
            TrayContextMenuEnable(true);
        }
Exemplo n.º 3
0
        private void uiPlayButton_Click(object sender, RoutedEventArgs e)
        {
            Demo demo = uiDemoListView.GetSelectedDemo();

            if (demo == null)
            {
                // shouldn't happen since the button should be disabled, but anyway...
                return;
            }

            // verify paths etc.
            launcher = LauncherFactory.CreateLauncher(demo);
            launcher.Owner = this;
            launcher.UseHlae = UseHlae(demo);
            launcher.Interface = (ILauncher)this;

            try
            {
                launcher.Verify();
            }
            catch (Launcher.AbortLaunchException)
            {
                return;
            }
            catch (ApplicationException ex)
            {
                Common.Message(this, null, ex);
                return;
            }
            catch (Exception ex)
            {
                Common.Message(this, null, ex, MessageWindow.Flags.Error);
                return;
            }

            // make sure source and destination filenames don't match (dickhead insurance)
            if (String.Equals(demo.FileFullPath, launcher.GameFullPath + "\\" + Config.LaunchDemoFileName, StringComparison.CurrentCultureIgnoreCase))
            {
                Common.Message(this, "Source and destination filenames are the same. Rename or move the source file and try again.");
                return;
            }

            // add the demo file path to the file operation manager
            FileOperationList.Add(new FileDeleteOperation(launcher.GameFullPath + "\\" + Config.LaunchDemoFileName));

            // stop the user from being able to open a new demo now
            canOpenDemo = false;

            // write the demo
            ProgressWindow writeDemoProgressWindow = new ProgressWindow() { Owner = this };
            writeDemoProgressWindow.Thread = demo.Write((IProgressWindow)writeDemoProgressWindow);
            writeDemoProgressWindow.ThreadParameter = launcher.GameFullPath + "\\" + Config.LaunchDemoFileName;
            if (writeDemoProgressWindow.ShowDialog() == false)
            {
                // user aborted writing
                FileOperationList.Execute();
                canOpenDemo = true;
                return;
            }

            // go to tray
            MinimiseToTray();

            // launch the game
            try
            {
                launcher.Run();
            }
            catch (Exception ex)
            {
                RestoreFromTray();
                FileOperationList.Execute();
                canOpenDemo = true;
                Common.Message(this, "Error launching game.", ex, MessageWindow.Flags.Error);
                return;
            }

            SystemTrayIcon.Text = "Looking for " + (launcher.UseHlae ? "HLAE" : "game") + " process...";

            // enable the tray context menu
            TrayContextMenuEnable(true);
        }