public static void FramingThread() { MainUI.SetCulture(); int wishedW = 1024, wishedH = 600; while (true) // Make screenshots forever >:) { long millis = DateTimeOffset.Now.Ticks / TimeSpan.TicksPerMillisecond; if (streaming & unityWindow != IntPtr.Zero && MainUI.isHost && MainUI.screenPartner != null) { Image gameScreen = GetImageFromWindow(); int width = gameScreen.Width; int height = gameScreen.Height; while (width > wishedW) { width -= (int)((float)width * 0.2f); } while (height > wishedH) { height -= (int)((float)height * 0.2f); // Get the right resolution } Bitmap resizedScreen = new Bitmap(width, height); Graphics g = Graphics.FromImage(resizedScreen); g.CompositingMode = CompositingMode.SourceCopy; g.DrawImage(gameScreen, 0, 0, width, height); // Resize the image g.Dispose(); gameScreen.Dispose(); UpdateChanges(resizedScreen); } long dMillis = (DateTimeOffset.Now.Ticks / TimeSpan.TicksPerMillisecond) - millis; Thread.Sleep(Math.Max(1, (1000 / FPS) - (int)dMillis)); } }
public static void UdpThread() { MainUI.SetCulture(); while (true) { var listenStuff = !MainUI.isHost ? MainUI.screenPartner : new IPEndPoint(IPAddress.Any, 8042); byte[] data = MainUI.screenClient.Receive(ref listenStuff); if (MainUI.screenPartner == null) { MainUI.screenPartner = listenStuff; } if (data.Length > 4 && !MainUI.isHost) { datas.Add(data); } } }