private static void InitScreen() { //performSearch = false; discBtn = new Gtk.Button("Disconnect"); discBtn.Clicked += (sender, args) => disconnectRequest = true; main.rightSide.Add(discBtn); main.ShowAll(); strWin = new StreamingWindow(); strWin.Show(); }
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); } } }
private static void DataListenLoop() { try { int cyclesCount = 0; System.Timers.Timer timer = new System.Timers.Timer(1000); timer.Elapsed += (sender, args) => { main.cycleSpeedReceive.Text = cyclesCount.ToString(); cyclesCount = 0; }; timer.Enabled = true; while (true) { Socket pipeListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); pipeListener.Bind(new IPEndPoint(localIP, 4578)); pipeListener.Listen(10); pipe = pipeListener.Accept(); //int startTime = DateTime.Now.Millisecond; while (pipe.Connected) { cyclesCount++; //main.cycleSpeedReceive.Text = (DateTime.Now.Millisecond - startTime).ToString(); //startTime = DateTime.Now.Millisecond; //Thread.Sleep(10); int bytes = 0; byte[] data = new byte[30000]; do { bytes = pipe.Receive(data); } while (pipe.Available > 0); try { object imgData = Serializer.BytesToObj(data, bytes); if (!(imgData is ImageStreamPart)) { throw new Exception("Wrong data!"); } data = (imgData as ImageStreamPart).bitmap; //decompressing byte[] decompressedImage = new byte[(imgData as ImageStreamPart).originalSize]; LZ4Codec.Decode(data, decompressedImage); strWin.img.Pixbuf = new Gdk.Pixbuf(decompressedImage); if (disconnectRequest) { pipe.Disconnect(true); pipe.Dispose(); pipe = null; discBtn.Hide(); discBtn.Destroy(); discBtn.Dispose(); disconnectRequest = false; strWin.Hide(); strWin.Dispose(); strWin = null; break; //searchTask.Start(); } } catch (Exception e1) { ConsoleLogic.WriteConsole("Error at converting received data"); } } } } catch (Exception e) { ConsoleLogic.WriteConsole("error at DataListenLoop"); } }