private void btReloadWindowPositionAndSize_Click(object sender, EventArgs e) { cptRect.GetGameWindowRect(this.tbProcess.Text, Profil); if ((!cbUseGDI.Checked) && (dx != null)) { dx.SetRect(cptRect.getRect()); } }
public void acceptCallback(IAsyncResult ar) { Socket listener = null; Socket handler = null; try { if (this.Profil != null) { listener = (Socket)ar.AsyncState; try { handler = listener.EndAccept(ar); } catch { if (TCPServer != null) { TCPServer.Close(); TCPServer = null; } return; } NetworkStream ns = new NetworkStream(handler, true); jgpEncoder = GDIGraphicTools.GetEncoder(ImageFormat.Jpeg); myEncoderParameters.Param[0] = new EncoderParameter(myEncoder, this.hScrollImageQuality.Value); cptRect.GetGameWindowRect(this.tbProcess.Text, Profil); // to split it will speed up the loop; keep it simple stupid if (cbUseGDI.Checked) { // gdi loop while ((handler.Connected) && (blStop == false)) { try { ms.SetLength(0); bm = CaptureSpecificWindow(cptRect.getRect()); if ((Profil.ShowCrosshair) || (Profil.ShowCursor)) { bm = GDIGraphicTools.DrawExtras(bm, cptRect.getRect(), Profil, Cursor.Position, myBrush); } bm.Save(ms, jgpEncoder, myEncoderParameters); } catch { ms.SetLength(0); } // send data try { if ((ms != null) && (ms.Length > 0)) { // may be put it on separate method byte[] mybyt = ms.ToArray(); if (mybyt.Length > 0) { lenght = mybyt.Length; lenbyte = BitConverter.GetBytes(lenght); ns.Write(lenbyte, 0, lenbyte.Length); ns.Flush(); ns.Write(mybyt, 0, mybyt.Length); ns.Flush(); } } } catch { blStop = true; } } // while } else { dx = new DirectX(); dx.SetRect(cptRect.getRect()); while ((handler.Connected) && (blStop == false)) { try { ms.SetLength(0); bm = dx.Capture(); if ((Profil.ShowCrosshair) || (Profil.ShowCursor)) { bm = GDIGraphicTools.DrawExtras(bm, cptRect.getRect(), Profil, Cursor.Position, myBrush); // needs to speed up } bm.Save(ms, jgpEncoder, myEncoderParameters); } catch { ms.SetLength(0); } // send data try { if ((ms != null) && (ms.Length > 0)) { // may be put it on separate method byte[] mybyt = ms.ToArray(); if (mybyt.Length > 0) { lenght = mybyt.Length; lenbyte = BitConverter.GetBytes(lenght); ns.Write(lenbyte, 0, lenbyte.Length); ns.Flush(); ns.Write(mybyt, 0, mybyt.Length); ns.Flush(); } } } catch { blStop = true; } } // while dx.close(); dx = null; } // gdi or directx Invoke((MethodInvoker) delegate { ServerStopped(); }); } } catch (Exception ex) { MessageBox.Show("Error on starting Server (Callback). \r\n" + ex.Message); blStop = true; } finally { if (ms != null) { try { ms.Close(); ms = null; } catch { } } if ((handler != null) && (handler.Connected)) { try { handler.Shutdown(SocketShutdown.Both); handler.Disconnect(false); } catch { } } if (TCPServer != null) { try { TCPServer.Close(); TCPServer = null; } catch { } } } } // acceptCallback
public void acceptCallback(IAsyncResult ar) { Socket listener = null; Socket handler = null; try { if (this.Profil != null) { listener = (Socket)ar.AsyncState; try { handler = listener.EndAccept(ar); } catch { if (TCPServer != null) { TCPServer.Close(); TCPServer = null; } return; } NetworkStream ns = new NetworkStream(handler, true); jgpEncoder = GDIGraphicTools.GetEncoder(ImageFormat.Jpeg); myEncoderParameters.Param[0] = new EncoderParameter(myEncoder, this.hScrollImageQuality.Value); cptRect.GetGameWindowRect(this.tbProcess.Text, Profil); // to split it will speed up the loop; keep it simple stupid if (cbUseGDI.Checked) { // gdi loop while ((handler.Connected) && (blStop == false)) { try { ms.SetLength(0); bm = CaptureSpecificWindow(cptRect.getRect()); if ((Profil.ShowCrosshair) || (Profil.ShowCursor)) bm = GDIGraphicTools.DrawExtras(bm, cptRect.getRect(), Profil, Cursor.Position, myBrush); bm.Save(ms, jgpEncoder, myEncoderParameters); } catch { ms.SetLength(0); } // send data try { if ((ms != null) && (ms.Length > 0)) { // may be put it on separate method byte[] mybyt = ms.ToArray(); if (mybyt.Length > 0) { lenght = mybyt.Length; lenbyte = BitConverter.GetBytes(lenght); ns.Write(lenbyte, 0, lenbyte.Length); ns.Flush(); ns.Write(mybyt, 0, mybyt.Length); ns.Flush(); } } } catch { blStop = true; } } // while } else { Thread STAThread = new Thread(() => { dx = new DirectX(); EffectShader LensCorrection = new EffectShader(1, Path.Combine(Path.Combine(Application.StartupPath, "shader"), "Shader.ps")); dx.SetRect(cptRect.getRect()); while ((handler.Connected) && (blStop == false)) { try { ms.SetLength(0); bm = dx.Capture(); if ((Profil.ShowCrosshair) || (Profil.ShowCursor)) bm = GDIGraphicTools.DrawExtras(bm, cptRect.getRect(), Profil, Cursor.Position, myBrush); // needs to speed up bm = LensCorrection.ApplyShader(bm); bm.Save(ms, jgpEncoder, myEncoderParameters); } catch(Exception ex) { ms.SetLength(0); } // send data try { if ((ms != null) && (ms.Length > 0)) { // may be put it on separate method byte[] mybyt = ms.ToArray(); if (mybyt.Length > 0) { lenght = mybyt.Length; lenbyte = BitConverter.GetBytes(lenght); ns.Write(lenbyte, 0, lenbyte.Length); ns.Flush(); ns.Write(mybyt, 0, mybyt.Length); ns.Flush(); } } } catch { blStop = true; } } // while dx.close(); dx = null; LensCorrection = null; }); STAThread.SetApartmentState(ApartmentState.STA); STAThread.Start(); STAThread.Join(); STAThread = null; } // gdi or directx Invoke((MethodInvoker)delegate { ServerStopped(); }); } } catch (Exception ex) { MessageBox.Show("Error on starting Server (Callback). \r\n" + ex.Message); blStop = true; } finally { if (ms != null) { try { ms.Close(); ms = null; } catch { } } if ((handler != null) && (handler.Connected)) { try { handler.Shutdown(SocketShutdown.Both); handler.Disconnect(false); } catch { } } if (TCPServer != null) { try { TCPServer.Close(); TCPServer = null; } catch { } } } }