public static void Capture(IntPtr hwnd, Direct3DVersion direct3DVersion = Direct3DVersion.AUTO_DETECT)
        {
            NativeUtils.GetWindowThreadProcessId(hwnd, out var processID);
            var process = Process.GetProcessById(processID);

            var captureConfig = new CaptureConfig
            {
                Direct3DVersion       = direct3DVersion,
                ShowOverlay           = true,
                CaptureMouseEvents    = true,
                CaptureKeyboardEvents = true
            };

            var captureInterface = new CaptureInterface();

            captureInterface.RemoteMessage += e =>
            {
                Debug.WriteLine(e.Message);
            };

            captureInterface.Connected += () =>
            {
                captureInterface.DrawOverlayInGame(new Overlay
                {
                    Elements = new List <IOverlayElement>
                    {
                        new RectangleElement
                        {
                            Colour   = Color.FromArgb(Color.Gray.ToArgb() ^ (0x33 << 24)),
                            Location = new Point(0, 0),
                            Width    = -1,
                            Height   = -1
                        },
                        new RectangleMouseHookElement
                        {
                            Colour = Color.FromArgb(Color.Green.ToArgb() ^ (0x33 << 24)),
                            Width  = 0,
                            Height = 0
                        },
                        new FramesPerSecond(new Font("Arial", 16, FontStyle.Bold))
                        {
                            Location    = new Point(0, 0),
                            Color       = Color.Red,
                            AntiAliased = true,
                            Text        = "{0:N0} FPS"
                        }
                    },
                    Hidden = false
                });
            };

            var captureProcess = new CaptureProcess(process, captureConfig, captureInterface);

            while (!captureProcess.IsDisposed)
            {
                Thread.Sleep(500);
            }

            Debug.WriteLine("Disconnected from DirectX Hook");
        }
        private void Inject()
        {
            bool newInstanceFound = false;

            while (!newInstanceFound)
            {
                if (_stopped)
                {
                    break;
                }
                Process[] processes = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(this.TargetProcess));
                foreach (Process process in processes)
                {
                    // Simply attach to the first one found.

                    // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                    if (process.MainWindowHandle == IntPtr.Zero)
                    {
                        continue;
                    }

                    _processId = process.Id;
                    _process   = process;

                    _capturedProcess = new CaptureProcess(process, new Capture.Interface.CaptureConfig {
                        ShowOverlay = false, Direct3DVersion = global::Capture.Interface.Direct3DVersion.AutoDetect
                    }, _captureInterface);

                    newInstanceFound = true;
                    break;
                }
                Thread.Sleep(10);
            }
        }
Exemple #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     HookManager.RemoveHookedProcess(_captureProcess.Process.Id);
     _captureProcess.CaptureInterface.Disconnect();
     _captureProcess = null;
     MessageBox.Show("Detached!");
 }
Exemple #4
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (_captureProcess != null)
     {
         HookManager.RemoveHookedProcess(_captureProcess.Process.Id);
         _captureProcess.CaptureInterface.Disconnect();
         _captureProcess = null;
     }
 }
        private void DettachHookFromProcess()
        {
            if (captureProcess != null)
            {
                captureInterface.RemoteMessage -= this.CaptureInterfaceOnRemoteMessage;
                captureProcess.Dispose();
                captureProcess = null;
                this.attached  = false;
            }

            for (int i = 0; i < 2; i++)
            {
                if (this.sharedTexturesAccess[i] != null)
                {
                    this.sharedTexturesAccess[i].SafeMemoryMappedViewHandle.ReleasePointer();
                    this.sharedTexturesAccess[i].Dispose();
                    this.sharedTexturesAccess[i] = null;
                }

                if (this.sharedTextures[i] != null)
                {
                    bool locked = false;
                    try
                    {
                        locked = sharedMemMutexes[i].WaitOne(1000);
                    }
                    catch (AbandonedMutexException ex)
                    {
                        locked = true;
                    }
                    finally
                    {
                        this.sharedTextures[i].Dispose();
                        this.sharedTextures[i] = null;
                        if (locked)
                        {
                            sharedMemMutexes[i].ReleaseMutex();
                        }
                    }
                }
            }

            if (copyDataMemAccess != null)
            {
                copyDataMemAccess.SafeMemoryMappedViewHandle.ReleasePointer();
                copyDataMemAccess.Dispose();
                copyDataMemAccess = null;
            }
            if (copyDataMem != null)
            {
                copyDataMem.Dispose();
                copyDataMem = null;
            }
            // lastCaptured = -1;
        }
Exemple #6
0
        private void AttachProcess()
        {
            m_InjectButton.Enabled = false;

            string exeName = Path.GetFileNameWithoutExtension(((IBotInfo)m_BotInfoComboBox.SelectedItem).GetExecutableName);

            Process[] processes = Process.GetProcessesByName(exeName);
            if (processes.Length == 0)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
                m_InjectButton.Enabled = true;
                return;
            }

            Process process = processes[0];

            // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
            if (process.MainWindowHandle == IntPtr.Zero)
            {
                return;
            }

            // Skip if the process is already hooked (and we want to hook multiple applications)
            if (HookManager.IsHooked(process.Id))
            {
                return;
            }

            CaptureConfig cc = new CaptureConfig()
            {
                Direct3DVersion = Direct3DVersion.AutoDetect, ShowOverlay = true
            };

            //captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
            m_captureProcess = new CaptureProcess(process, cc, new CaptureInterface());

            Thread.Sleep(10);

            IBot.print("Creating and attaching script: " + ((IBotInfo)m_BotInfoComboBox.SelectedItem).ToString() + " by " + ((IBotInfo)m_BotInfoComboBox.SelectedItem).Author);
            m_Bot = ((IBotInfo)m_BotInfoComboBox.SelectedItem).CreateBot;
            m_Bot.OnAttach();

            m_InjectButton.Text               = "Detach";
            m_InjectButton.Enabled            = true;
            m_SteppingEnabledCheckbox.Checked = true;
            m_SteppingEnabledCheckbox.Enabled = true;

            myTimer.Tick    += new EventHandler(TimerEventProcessor);
            myTimer.Interval = 100;
            myTimer.Start();

            CaptureScreenshot();
        }
Exemple #7
0
        public void AttachProcess()
        {
            Process[] processes = Process.GetProcessesByName("HuniePop 2 - Double Date");

            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                this.parent.launcHuniePop2Listener();
                hooked = false;
            }
            else
            {
                this.message.Foreground = new SolidColorBrush(Colors.DarkGreen);
                this.message.Text       = "Attached to game";
                hooked = true;
            }
        }
        private bool AttachHookToProcess()
        {
            if (this.attached)
            {
                return(true);
            }

            Process[] processes = Process.GetProcessesByName(HEARTHSTONE_PROCESS_NAME);

            if (processes.Length <= 0)
            {
                Log.Debug("GetProcessesByName failed.");
                return(false);
            }
            var process = processes[0];

            // Check incompatible modules:
            foreach (ProcessModule module in process.Modules)
            {
                if (module.ModuleName.ToLower().StartsWith("rtsshooks"))
                {
                    Publish(new IncompatibleHooksFound("RTSSHooks", "MSI Afterburner / Riva Tuner Statistics Server"));
                }
            }

            //if (process.MainWindowHandle == IntPtr.Zero)
            //{
            //    Log.Debug("Could not get MainWindowHandle.");
            //    return false;
            //}

            if (HookManager.IsHooked(process.Id))
            {
                return(true);
            }

            if (captureProcess != null)
            {
                Log.Warn("Call DettachHookFromProcess first");
                DettachHookFromProcess();
                extraDelay = 200;
                Thread.Sleep(200);
            }

            captureInterface = new CaptureInterface();
            captureInterface.RemoteMessage += this.CaptureInterfaceOnRemoteMessage;
            this.captureProcess             = new CaptureProcess(process, captureConfig, captureInterface);
            this.attached = true;
            return(true);
        }
Exemple #9
0
        public void StartHook()
        {
            var exeName = "GTA5";

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (var process in processes)
            {
                if (process == null)
                {
                    continue;
                }
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3dVersion = Direct3DVersion.Direct3D11;

                /*
                 * switch (gameSettings.Graphics.DX_Version.Value)
                 * {
                 *  case 0:
                 *      direct3dVersion = Direct3DVersion.Direct3D10;
                 *      break;
                 *  case 1:
                 *      direct3dVersion = Direct3DVersion.Direct3D10_1;
                 *      break;
                 *  case 2:
                 *      direct3dVersion = Direct3DVersion.Direct3D11;
                 *      break;
                 * }*/

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3dVersion,
                    ShowOverlay     = true,
                };

                _gtaProcessId = process.Id;
                _gtaProcess   = process;

                var captureInterface = new CaptureInterface();
                _captureProcess = new CaptureProcess(process, cc, captureInterface);
                //Thread.Sleep(5000);
                //_captureProcess.CaptureInterface.DisplayInGameText("HELLO FROM PLAYMultiV!", TimeSpan.FromSeconds(60));
                //_captureProcess.CaptureInterface.up
            }
        }
Exemple #10
0
        public void AddHooks()
        {
            if (HookManager.IsHooked(_process.Id))
            {
                return;
            }

            var captureConfig = new CaptureConfig {
                Direct3DVersion = Direct3DVersion.AutoDetect,
                ShowOverlay     = true
            };
            var captureInterface = new CaptureInterface();

            captureInterface.RemoteMessage += CaptureInterfaceOnRemoteMessage;
            _captureProcess = new CaptureProcess(_process, captureConfig, captureInterface);
        }
Exemple #11
0
        private void AttachProcess()
        {
            string exeName = Path.GetFileNameWithoutExtension("Europa_Client.exe");

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true,
                    WallhackEnabled = checkBox1.Checked,
                    WeaponEnabled   = checkBox2.Checked
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
        }
Exemple #12
0
        private void CreateCaptureProcess(Process process)
        {
            _process = process;

            Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D10;

            if (rbDirect3D11.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D11;
            }
            else if (rbDirect3D10_1.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10_1;
            }
            else if (rbDirect3D10.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D10;
            }
            else if (rbDirect3D9.Checked)
            {
                direct3DVersion = Direct3DVersion.Direct3D9;
            }
            else if (rbAutodetect.Checked)
            {
                direct3DVersion = Direct3DVersion.AutoDetect;
            }

            var cc = new CaptureConfig
            {
                Direct3DVersion = direct3DVersion,
                ShowOverlay     = cbDrawOverlay.Checked,
                TestThisShit    = 300
            };

            var captureInterface = new CaptureInterface();

            if (frm2 != null)
            {
                frm2.Close();
                frm2.Dispose();
            }

            frm2 = new form2JT(captureInterface);

            captureInterface.RemoteMessage += CaptureInterface_RemoteMessage;
            _captureProcess = new CaptureProcess(process, cc, captureInterface);
        }
Exemple #13
0
        public void AttachProcess(string proc)
        {
            string exeName = Path.GetFileNameWithoutExtension(proc);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;
                

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay = true
                };

                ProcessID = process.Id;
                Process = process;

                var captureInterface = new CaptureInterface();
                CaptureProcess = new CaptureProcess(process, cc, captureInterface);
                break;
            }
            Thread.Sleep(10);

            if (CaptureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
                Environment.Exit(0);
            }
        }
Exemple #14
0
        private void AttachProcess()
        {
            string exeName = Path.GetFileNameWithoutExtension(_config.HellbladeExecutablePath);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = Direct3DVersion.AutoDetect,
                    ShowOverlay     = false
                };

                _process = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                throw new InvalidOperationException($"No executable found matching: '{exeName}''");
            }

            _isAttached = true;
        }
Exemple #15
0
        private void DetachProcess()
        {
            myTimer.Stop();

            m_InjectButton.Text               = "Inject";
            m_InjectButton.Enabled            = true;
            m_SteppingEnabledCheckbox.Checked = false;
            m_SteppingEnabledCheckbox.Enabled = false;

            IBot.print("Unloading script");
            m_Bot.OnDetach();
            m_Bot = null;

            HookManager.RemoveHookedProcess(m_captureProcess.Process.Id);
            m_captureProcess.CaptureInterface.Disconnect();
            m_captureProcess = null;

            m_DebugVisualizer.Image = null;
        }
Exemple #16
0
        void DetachFromHookedProcess()
        {
            if (HookedProcessId != 0)
            {
                log.InfoFormat("Detaching from hooked process {0}", HookedProcessId);

                if (captureProcess != null)
                {
                    captureProcess.CaptureInterface.Disconnect();
                }

                log.Info("Unhooking process");
                HookManager.RemoveHookedProcess((int)HookedProcessId);

                captureProcess   = null;
                captureInterface = null;

                HookedProcessId = 0;
            }
        }
Exemple #17
0
        public static void AttachProcess(string name)
        {
            if (CaptureProcess != null)
            {
                HookManager.RemoveHookedProcess(CaptureProcess.Process.Id);
                CaptureProcess.CaptureInterface.Disconnect();
                CaptureProcess = null;
            }

            try
            {
                Process[] processes = Process.GetProcessesByName(name);
                foreach (Process p in processes)
                {
                    if (p.MainWindowHandle == IntPtr.Zero)
                    {
                        continue;
                    }

                    if (HookManager.IsHooked(p.Id))
                    {
                        continue;
                    }

                    CaptureConfig cc = new CaptureConfig()
                    {
                        Direct3DVersion = Direct3DVersion.AutoDetect,
                        ShowOverlay     = true
                    };

                    var captureInterface = new CaptureInterface();
                    CaptureProcess = new CaptureProcess(p, cc, captureInterface);
                }

                Log.Write("Process attached: " + name + " (Width: " + Width + "; Height: " + Height + ")");
            }
            catch (Exception e)
            {
                Log.Write(e.Message);
            }
        }
Exemple #18
0
        private void AttachProcess(string proc)
        {
            string exeName = Path.GetFileNameWithoutExtension(proc);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.AutoDetect;

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = true
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                //captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage); //DEBUG
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            }
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
        }
Exemple #19
0
        private void btnInject_Click(object sender, EventArgs e)
        {
            if (_captureProcess == null)
            {
                btnInject.Enabled = false;

                if (cbAutoGAC.Checked)
                {
                    // NOTE: On some 64-bit setups this doesn't work so well.
                    //       Sometimes if using a 32-bit target, it will not find the GAC assembly
                    //       without a machine restart, so requires manual insertion into the GAC
                    // Alternatively if the required assemblies are in the target applications
                    // search path they will load correctly.

                    // Must be running as Administrator to allow dynamic registration in GAC
                    Config.Register("Capture",
                                    "Capture.dll");
                }

                AttachProcess();
            }
            else
            {
                HookManager.RemoveHookedProcess(_captureProcess.Process.Id);
                _captureProcess.CaptureInterface.Disconnect();
                _captureProcess = null;
            }

            if (_captureProcess != null)
            {
                btnInject.Text    = "Detach";
                btnInject.Enabled = true;
            }
            else
            {
                btnInject.Text    = "Inject";
                btnInject.Enabled = true;
            }
        }
Exemple #20
0
        private void AttachProcess()
        {
            if (HookManager.IsHooked(gameProcess.Id))
            {
                return;
            }

            CaptureConfig captureConfig = new CaptureConfig()
            {
                Direct3DVersion = Direct3DVersion.AutoDetect
            };

            var captureInterface = new CaptureInterface();

            captureProcess = new CaptureProcess(gameProcess, captureConfig, captureInterface);

            Thread.Sleep(10);

            if (captureProcess == null)
            {
                throw new Exception("Capture Process could not be started");
            }
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (captureProcess != null)
            {
                captureProcess.Dispose();
                captureProcess = null;
            }

            for (int i = 0; i < 2; i++)
            {
                if (this.sharedTexturesAccess[i] != null)
                {
                    this.sharedTexturesAccess[i].SafeMemoryMappedViewHandle.ReleasePointer();
                    this.sharedTexturesAccess[i].Dispose();
                    this.sharedTexturesAccess[i] = null;
                }

                if (this.sharedTextures[i] != null)
                {
                    this.sharedTextures[i].Dispose();
                    this.sharedTextures[i] = null;
                }
            }

            if (copyDataMemAccess != null)
            {
                copyDataMemAccess.SafeMemoryMappedViewHandle.ReleasePointer();
                copyDataMemAccess.Dispose();
                copyDataMemAccess = null;
            }

            if (copyDataMem != null)
            {
                copyDataMem.Dispose();
                copyDataMem = null;
            }
        }
Exemple #22
0
        private void AttachProcessEx(int processID)
        {
            string exeName = Path.GetFileNameWithoutExtension(textBox1.Text);

            Process process = Process.GetProcessById(processID);

            if (process != null)
            {
                textBox1.Text = process.ProcessName;
            }
            do
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    break;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    break;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D10;

                if (rbDirect3D11.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D11;
                }
                else if (rbDirect3D10_1.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D10_1;
                }
                else if (rbDirect3D10.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D10;
                }
                else if (rbDirect3D9.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D9;
                }
                else if (rbAutodetect.Checked)
                {
                    direct3DVersion = Direct3DVersion.AutoDetect;
                }

                CaptureConfig cc = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    ShowOverlay     = cbDrawOverlay.Checked
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, cc, captureInterface);

                break;
            } while (false);
            Thread.Sleep(10);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
            else
            {
                btnLoadTest.Enabled = true;
                btnCapture.Enabled  = true;
            }
        }
Exemple #23
0
        void HandleFullScreenApplicationChanged(object sender, ChangedEventArgs e)
        {
            Process p = Process.GetProcessById((int)e.ProcessId);
            String  processFileName = "";

            /*
             * if (e.ProcessId != 0)
             * {
             *  processFileName = Path.GetFileName(p.MainModule.FileName).ToLower();
             * }
             */

            if (e.FullScreen && !processFileName.Contains("powerptn.exe"))
            {
                if (HookedProcessId != e.ProcessId)
                {
                    //Disable capture while hooking into process
                    CaptureMode = CaptureModeEnum.None;

                    HookedProcessId = e.ProcessId;

                    if (HookManager.IsHooked((int)e.ProcessId))
                    {
                        log.InfoFormat("Process {0} is already hooked", HookedProcessId);
                    }
                    else
                    {
                        log.InfoFormat("Hooking into {0}", HookedProcessId);

                        CaptureConfig cc = new CaptureConfig()
                        {
                            Direct3DVersion = Direct3DVersion.AutoDetect,
                            ShowOverlay     = false
                        };

                        captureInterface = new CaptureInterface();
                        captureInterface.RemoteMessage += HandleRemoteMessage;

                        Process process = Process.GetProcessById((int)HookedProcessId);

                        log.InfoFormat("Starting {0}:{1} process capture", HookedProcessId, process.MainWindowTitle);
                        try
                        {
                            captureProcess = new CaptureProcess(process, cc, captureInterface);
                            log.InfoFormat("Hooking into {0} complete", HookedProcessId);
                        }
                        catch (Exception ex)
                        {
                            log.ErrorFormat("Failed to hook into process {0}", ex);
                        }
                    }
                }

                CaptureMode = CaptureModeEnum.Application;
            }
            else
            {
                CaptureMode = CaptureModeEnum.Desktop;

                DetachFromHookedProcess();
            }
        }
Exemple #24
0
        private void AttachProcess()
        {
            string exeName = Path.GetFileNameWithoutExtension(textBox1.Text);

            Process[] processes = Process.GetProcessesByName(exeName);
            foreach (Process process in processes)
            {
                // Simply attach to the first one found.

                // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc)
                if (process.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                // Skip if the process is already hooked (and we want to hook multiple applications)
                if (HookManager.IsHooked(process.Id))
                {
                    continue;
                }

                Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D9;

                if (rbDirect3D9.Checked)
                {
                    direct3DVersion = Direct3DVersion.Direct3D9;
                }

                CaptureConfig captureConfig = new CaptureConfig()
                {
                    Direct3DVersion = direct3DVersion,
                    CaptureWidth    = 720,
                    CaptureHeight   = 540
                };

                processId = process.Id;
                _process  = process;

                var captureInterface = new CaptureInterface();
                captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage);
                _captureProcess = new CaptureProcess(process, captureConfig, captureInterface);

                break;
            }
            Thread.Sleep(50);

            if (_captureProcess == null)
            {
                MessageBox.Show("No executable found matching: '" + exeName + "'");
            }
            else
            {
                IntPtr windowHandle = StreamingWindow.FindStreamingPanel(_captureProcess.Process);
                windowControl = new WindowControl(_captureProcess.Process.MainWindowHandle, windowHandle);

                Size size = windowControl.GetWindowSize();
                if (size.Width < (int)numUpDownWidth.Value || size.Height < (int)numUpDownHeight.Value)
                {
                    windowControl.ResizeWindow(new Size((int)numUpDownWidth.Value, (int)numUpDownHeight.Value), false);
                }
            }
        }