Ejemplo n.º 1
0
        protected override void VerifyRunningPrograms()
        {
            // verify that steam is running
            if (Common.FindProcess("Steam", Config.Settings.SteamExeFullPath) == null)
            {
                throw new ApplicationException("Steam is not running. Launch Steam, log into your account and try again.");
            }

            // verify that HLAE is not running
            if (UseHlae)
            {
                if (Common.FindProcess("hlae", Config.Settings.HlaeExeFullPath) != null)
                {
                    throw new ApplicationException("Cannot play a demo with HLAE when it's already running. Exit HLAE and try again.");
                }
            }

            // verify that the game is not running
            Game game = null;

            if (JoiningServer)
            {
                game = GameManager.Find((ServerSourceEngine ? Game.Engines.Source : Game.Engines.HalfLife), ServerGameFolderName);
            }
            else
            {
                game = GameManager.Find(Demo);
            }

            // even if HLAE is being used, still need to check that game isn't already running
            if (Demo.Engine == Demo.Engines.Source)
            {
                processExeFullPath = Path.GetDirectoryName(Config.Settings.SteamExeFullPath) + "\\SteamApps\\" + Config.Settings.SteamAccountFolder + "\\" + game.FolderExtended + "\\";
            }
            else
            {
                // steam half-life uses "Steam\steamapps\common\Half-Life" now.
                processExeFullPath = Path.GetDirectoryName(Config.Settings.SteamExeFullPath) + "\\SteamApps\\common\\Half-Life\\";
            }

            if ((JoiningServer && ServerSourceEngine) || (!JoiningServer && Demo.Engine == Demo.Engines.Source))
            {
                processExeFullPath += "hl2.exe";
            }
            else
            {
                processExeFullPath += "hl.exe";
            }

            if (Common.FindProcess(Path.GetFileNameWithoutExtension(processExeFullPath), processExeFullPath) != null)
            {
                throw new ApplicationException("Cannot play a demo while \"" + game.Name + "\" is already running. Exit the game and try again.");
            }

            if (UseHlae)
            {
                processExeFullPath = Config.Settings.HlaeExeFullPath;
            }
        }
Ejemplo n.º 2
0
        protected override void VerifyRunningPrograms()
        {
            Debug.Assert(gameFullPath != null);

            // verify that hl.exe is not running
            if (Common.FindProcess("hl", Config.Settings.HlExeFullPath) != null)
            {
                throw new ApplicationException("Cannot play a demo while a Half-Life engine game is already running. Exit the game and try again.");
            }

            processExeFullPath = Config.Settings.HlExeFullPath;
        }
Ejemplo n.º 3
0
        protected override void VerifyRunningPrograms()
        {
            Debug.Assert(gameFullPath != null);

            // cstrike.exe is just a launcher, hl.exe is the real process
            processExeFullPath = Path.Combine(Path.GetDirectoryName(Config.Settings.CstrikeExeFullPath), "hl.exe");

            // verify that hl.exe is not running
            if (Common.FindProcess("hl", processExeFullPath) != null)
            {
                throw new ApplicationException("Cannot play a demo while a Counter-Strike game is already running. Exit the game and try again.");
            }
        }
Ejemplo n.º 4
0
        static void Main(String[] args)
        {
            // read config.xml
            try
            {
                Config.Read();
            }
            catch (Exception ex)
            {
                Common.Message(null, "Error reading from the configuration file. Try deleting \"config.xml\" from  \"" + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + Config.ProgramName + "\".", ex, MessageWindow.Flags.Error);
                return;
            }

            // look for already running process with same name and path
            Process process = Common.FindProcess(Path.GetFileNameWithoutExtension(Config.ProgramExeFullPath), Config.ProgramExeFullPath, Process.GetCurrentProcess().Id);

            if (process != null)
            {
                // focus on process window
                SetForegroundWindow(process.MainWindowHandle);

                if (args.Length > 0)
                {
                    if (File.Exists(args[0]))
                    {
                        // send command line parameter to existing process
                        try
                        {
                            CreateClientChannel(args[0]);
                        }
                        catch (Exception ex)
                        {
                            Common.Message(null, "Error creating client IPC channel.", ex, MessageWindow.Flags.Error);
                        }
                    }
                }

                // another process already exists, end this one
                return;
            }
            else
            {
                try
                {
                    CreateServerChannel();
                }
                catch (Exception ex)
                {
                    Common.Message(null, "Error creating server IPC channel.", ex, MessageWindow.Flags.Error);
                    return; // quit
                }

                AllowSetForegroundWindow(Process.GetCurrentProcess().Id);
            }

            // read steam.xml
            try
            {
                GameManager.Initialise(Config.ProgramPath + "\\config");
            }
            catch (Exception ex)
            {
                Common.Message(null, "Error reading from \"steam.json\". Reinstalling may fix the problem.", ex, MessageWindow.Flags.Error);
                return;
            }

            // read fileoperationslog.xml
            try
            {
                FileOperationList.Initialise(Config.ProgramDataPath, "fileoperationslog.xml");
                FileOperationList.Execute();
            }
            catch (Exception ex)
            {
                Common.Message(null, "FileOperationList error. Try deleting \"fileoperationslog.xml\" from \"" + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + Config.ProgramName + "\" if the problem persists.", ex, MessageWindow.Flags.Error);
                return;
            }

            // file association
            if (Config.Settings.AssociateWithDemFiles)
            {
                try
                {
                    Config.AssociateWithDemFiles();
                }
                catch (UnauthorizedAccessException)
                {
                    Config.Settings.AssociateWithDemFiles = false;
                }
                catch (Exception ex)
                {
                    Common.Message(null, "Error associating with *.dem files.", ex, MessageWindow.Flags.Error);
                }
            }

            App app = new App();

            app.InitializeComponent();
            app.Run();
        }
Ejemplo n.º 5
0
        private void ProcessMonitorThread()
        {
            Process process = null;

            while (true)
            {
                if (process == null)
                {
                    // looking for process
                    process = Common.FindProcess(System.IO.Path.GetFileNameWithoutExtension(processExeFullPath), processExeFullPath);

                    if (process != null)
                    {
                        Interface.LaunchedProcessFound();

                        // set process priority
                        if (!UseHlae && Config.Settings.GameProcessPriority != ProcessPriorityClass.Normal)
                        {
                            process.PriorityClass = Config.Settings.GameProcessPriority;
                        }

                        if (UseHlae)
                        {
                            // open IPC channel
                            IpcChannel channel = new IpcChannel();
                            ChannelServices.RegisterChannel(channel, true);

                            try
                            {
                                IHlaeRemote_1 remote = (IHlaeRemote_1)Activator.GetObject(typeof(IHlaeRemote_1), "ipc://localhost:31337/Hlae.Remote.1");

                                // bleh
                                Boolean connected = false;
                                Int32   attempts  = 0;

                                do
                                {
                                    try
                                    {
                                        connected = true;
                                        remote.GetCustomArgs();
                                    }
                                    catch (RemotingException)
                                    {
                                        connected = false;
                                        attempts++;
                                        Thread.Sleep(50);
                                    }
                                }while (!connected && attempts < 10);

                                if (!connected)
                                {
                                    MessageBox.Show("Failed to communicate with the HLAE process remotely. You must manually launch the game and enter the command \"exec coldemoplayer.cfg\" in the console.", Config.ProgramName);
                                }
                                else
                                {
                                    if (remote.IsDeprecated())
                                    {
                                        MessageBox.Show("Warning: HLAE interface depreciated.");
                                    }

                                    try
                                    {
                                        remote.LaunchEx(remote.GetCustomArgs() + launchParameters);
                                    }
                                    catch (Exception e)
                                    {
                                        MessageBox.Show("Warning: " + e.Message, "IPC error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                    }
                                }
                            }
                            finally
                            {
                                ChannelServices.UnregisterChannel(channel);
                            }
                        }
                    }
                }
                else
                {
                    // found process, waiting for it to close
                    if (process.HasExited)
                    {
                        Interface.LaunchedProcessClosed();
                        return;
                    }
                }

                Thread.Sleep(250);
            }
        }