Example #1
0
 public static void LoadSetttings()
 {
     LOG.Info("Loading settings from user.config");
     HyperionServerIp        = Settings.Default.hyperionServerIP;
     HyperionServerPort      = Settings.Default.hyperionServerPort;
     HyperionMessagePriority = Settings.Default.hyperionMessagePriority;
     HyperionMessageDuration = Settings.Default.hyperionMessageDuration;
     HyperionWidth           = Settings.Default.width;
     HyperionHeight          = Settings.Default.height;
     CaptureInterval         = Settings.Default.captureInterval;
     MonitorIndex            = Settings.Default.monitorIndex;
     NotificationLevel       = Settings.Default.notificationLevel;
     CaptureOnStartup        = Settings.Default.captureOnStartup;
     PauseOnUserSwitch       = Settings.Default.pauseOnUserSwitch;
     PauseOnSystemSuspend    = Settings.Default.pauseOnSystemSuspend;
     ApiPort    = Settings.Default.apiPort;
     ApiEnabled = Settings.Default.apiEnabled;
     ApiExcludedTimesEnabled = Settings.Default.apiExcludedTimesEnabled;
     ApiExcludeTimeStart     = Settings.Default.apiExcludeTimeStart;
     ApiExcludeTimeEnd       = Settings.Default.apiExcludeTimeEnd;
     CaptureMethod           = Settings.Default.captureMethod;
     Dx11MaxFps = Settings.Default.dx11MaxFps;
     Dx11FrameCaptureTimeout    = Settings.Default.dx11FrameCaptureTimeout;
     Dx11ImageScalingFactor     = Settings.Default.dx11ImageScalingFactor;
     Dx11AdapterIndex           = Settings.Default.dx11AdapterIndex;
     Dx11MonitorIndex           = Settings.Default.dx11MonitorIndex;
     CheckUpdateOnStartup       = Settings.Default.checkUpdateOnStartup;
     HyperionTaskConfigurations = JsonConvert.DeserializeObject <List <HyperionTaskConfiguration> >(Settings.Default.hyperionTaskConfigurations);
     LOG.Info("Loaded settings from user.config");
 }
 void IGXDLMSBase.Load(GXXmlReader reader)
 {
     Buffer = GXCommon.HexToBytes(reader.ReadElementContentAsString("Buffer"));
     CaptureObjects.Clear();
     if (reader.IsStartElement("CaptureObjects", true))
     {
         while (reader.IsStartElement("Item", true))
         {
             ObjectType          ot  = (ObjectType)reader.ReadElementContentAsInt("ObjectType");
             string              ln  = reader.ReadElementContentAsString("LN");
             int                 ai  = reader.ReadElementContentAsInt("Attribute");
             int                 di  = reader.ReadElementContentAsInt("Data");
             GXDLMSCaptureObject co  = new GXDLMSCaptureObject(ai, di);
             GXDLMSObject        obj = reader.Objects.FindByLN(ot, ln);
             if (obj == null)
             {
                 obj             = GXDLMSClient.CreateObject(ot);
                 obj.LogicalName = ln;
             }
             CaptureObjects.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, co));
         }
         reader.ReadEndElement("CaptureObjects");
     }
     TemplateId          = (byte)reader.ReadElementContentAsInt("TemplateId");
     TemplateDescription = GXCommon.HexToBytes(reader.ReadElementContentAsString("TemplateDescription"));
     CaptureMethod       = (CaptureMethod)reader.ReadElementContentAsInt("CaptureMethod");
 }
        private void EnableRelevantDxFields(CaptureMethod captureMethod)
        {
            switch (captureMethod)
            {
            case CaptureMethod.DX11:
                rbcmDx11.Checked                  = true;
                cbDx9MonitorIndex.Enabled         = false;
                tbDx9CaptureWidth.Enabled         = false;
                tbDx9CaptureHeight.Enabled        = false;
                tbDx9CaptureInterval.Enabled      = false;
                cbDx11AdapterIndex.Enabled        = true;
                cbDx11MonitorIndex.Enabled        = true;
                tbDx11FrameCaptureTimeout.Enabled = true;
                cbDx11ImageScalingFactor.Enabled  = true;
                tbDx11MaxFps.Enabled              = true;
                break;

            case CaptureMethod.DX9:
                rbcmDx9.Checked                   = true;
                cbDx11AdapterIndex.Enabled        = false;
                cbDx11MonitorIndex.Enabled        = false;
                tbDx11FrameCaptureTimeout.Enabled = false;
                cbDx11ImageScalingFactor.Enabled  = false;
                tbDx11MaxFps.Enabled              = false;
                cbDx9MonitorIndex.Enabled         = true;
                tbDx9CaptureWidth.Enabled         = true;
                tbDx9CaptureHeight.Enabled        = true;
                tbDx9CaptureInterval.Enabled      = true;
                break;

            default:
                throw new NotImplementedException($"The capture method {captureMethod} is not supported");
            }
        }
Example #4
0
        internal void Fill(PaymentInfo info)
        {
            captureMethod = info.CaptureMethod == CaptureMethod.EMV
                                ? CaptureMethod.EMV
                                : CaptureMethod.Magstripe;
            status         = info.Decision == Decision.Refused ? PaymentStatus.Rejected : PaymentStatus.Accepted;
            paymentMethod  = (PaymentMethod)info.ApplicationType;
            emv            = captureMethod == CaptureMethod.EMV ? GetString(info.EmvData, info.EmvDataLength) : null;
            pan            = GetString(info.Pan, info.PanLength);
            expirationDate = GetString(info.ExpirationDate);
            holderName     = info.HolderNameLength.ToInt32() > 0
                ? GetString(info.HolderName, info.HolderNameLength)
                : null;
            panSequenceNumber = info.PanSequenceNumber;
            pin         = null;
            pinKek      = null;
            isOnlinePin = info.IsOnlinePin != 0;
            requiredPin = info.PinRequired != 0;

            track1 = info.Track1Length.ToInt32() > 0 ? GetString(info.Track1, info.Track1Length) : null;
            track2 = GetString(info.Track2, info.Track2Length);
            track3 = info.Track3Length.ToInt32() > 0 ? GetString(info.Track3, info.Track3Length) : null;

            expirationDate = expirationDate.Substring(2, 2) + expirationDate.Substring(0, 2);
            if (holderName != null)
            {
                holderName = holderName.Trim().Split('/').Reverse().Aggregate((a, b) => a + ' ' + b);
            }

            if (requiredPin && isOnlinePin)
            {
                pin    = GetString(info.Pin);
                pinKek = GetString(info.PinKek);
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            globalStopwatch = new Stopwatch();
            globalStopwatch.Start();

            Thread.Sleep(5000);
            Console.CancelKeyPress +=
                new ConsoleCancelEventHandler((o, t) =>
            {
                captureMethod.Stop();       //Stop Capturing
            });

            captureMethod = new LocalCapture(bitmapBuffer);

            // Start Capture
            captureMethod.Start();

            // Start dispatch frames
            bitmapBuffer.StartDispatchToImageProcessBase();

            // arg[0]: Game type (String)
            // arg[1..n]: Name of outlet channels (String)
            FeatureExtractors arrivalEvents = FeatureExtractors.InitFeatureExtractor(
                (int)Enum.Parse(typeof(GameType), args[0]),
                args.Skip(1).ToArray()
                );

            // Do Cache Optimizer
            CacheOptimizer.Init();
            CacheOptimizer.ResetAllAffinity();
        }
Example #6
0
        public BitmapSource GetClientBitmap(CaptureMethod method, bool onlyTargetWindow)
        {
            if (GetClientRect(this.Handle, out var rect) == 0)
            {
                return(null);
            }

            var width  = rect.right - rect.left;
            var height = rect.bottom - rect.top;

            if (width <= 0 || height <= 0)
            {
                return(null);
            }

            var pt = new POINT {
                x = rect.left, y = rect.top
            };

            switch (method)
            {
            case CaptureMethod.Win32:
                return(CaptureWin32(pt, width, height, onlyTargetWindow));

            default:
                throw new ArgumentException();
            }
        }
Example #7
0
        private void SetCurrentEngine(CaptureMethod method)
        {
            var oldEngine = currentCaptureEngine;

            switch (method)
            {
            case CaptureMethod.AutoDetect:
            case CaptureMethod.BitBlt:
            case CaptureMethod.Wdm:
            case CaptureMethod.DirectX:
                currentCaptureEngine = autoCaptureEngine;
                break;

            case CaptureMethod.Log:
                currentCaptureEngine = logCaptureEngine;
                break;
            }

            if (oldEngine != currentCaptureEngine &&
                oldEngine.IsRunning)
            {
                oldEngine.Stop();
                currentCaptureEngine.StartAsync();
            }
        }
Example #8
0
        public static Bitmap CaptureWindow(IntPtr hWnd, CaptureMethod Method)
        {
            if (hWnd == IntPtr.Zero)
            {
                return(null);
            }

            int style = ExternalAPI.GetWindowLong(hWnd, -16);

            //int Exstyle = ExternalAPI.GetWindowLong(hWnd, -20);

            // Ignore Popup windows
            if ((style & 0x80000000) != 0)
            {
                return(null);
            }

            var winrect = new ExternalAPI.Rect();

            ExternalAPI.GetWindowRect(hWnd, ref winrect);

            var clientrec = new ExternalAPI.Rect();

            ExternalAPI.GetClientRect(hWnd, ref clientrec);

            int width  = clientrec.right - clientrec.left;
            int height = clientrec.bottom - clientrec.top;

            if (width <= 0 || height <= 0)
            {
                return(null);
            }

            var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (Graphics graphics = Graphics.FromImage(bmp))
            {
                if (Method == CaptureMethod.PaintWindow)
                {
                    IntPtr Handle = graphics.GetHdc();

                    ExternalAPI.PrintWindow(hWnd, Handle, 1);

                    graphics.ReleaseHdc(Handle);
                }
                else if (Method == CaptureMethod.DesktopCapture)
                {
                    var tempPoint = new Point();
                    tempPoint.x = clientrec.left;
                    tempPoint.y = clientrec.top;
                    ClientToScreen(hWnd, ref tempPoint);

                    graphics.CopyFromScreen(tempPoint.x, tempPoint.y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
                }
            }

            return(bmp);
        }
Example #9
0
        ///<summary>Must use a Synch capture type to work.</summary>
        public Texture2D GetScreenshot(CaptureMethod method)
        {
            if (method == CaptureMethod.AppCapture_Synch)
            {
                string tempFilePath = Environment.GetEnvironmentVariable("TEMP") + "/screenshotBuffer" + tempFileCount + ".png";
                tempFileCount++;
                Application.CaptureScreenshot(tempFilePath);
                WWW www = new WWW("file://" + tempFilePath.Replace(Path.DirectorySeparatorChar.ToString(), "/"));

                Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
                while (!www.isDone)
                {
                }
                www.LoadImageIntoTexture((Texture2D)texture);
                File.Delete(tempFilePath); //Can delete now

                return(texture);
            }
            else if (method == CaptureMethod.ReadPixels_Synch)
            {
                //Create a texture to pass to encoding
                Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

                //Put buffer into texture
                texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); //Unity complains about this line's call being made "while not inside drawing frame", but it works just fine.*

                return(texture);
            }
            else if (method == CaptureMethod.RenderToTex_Synch)
            {
                RenderTexture rt         = new RenderTexture(Screen.width, Screen.height, 24);
                Texture2D     screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

                Camera.main.targetTexture = rt;
                Camera.main.Render();

                //Render from all!
                //foreach (Camera cam in Camera.allCameras)
                //{
                //    cam.targetTexture = rt;
                //    cam.Render();
                //    cam.targetTexture = null;
                //}

                RenderTexture.active = rt;
                screenShot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
                Camera.main.targetTexture = null;
                RenderTexture.active      = null; //Added to avoid errors
                Destroy(rt);

                return(screenShot);
            }
            else
            {
                return(null);
            }
        }
Example #10
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x111) // WM_COMMAND
            {
                int ID = m.WParam.ToInt32();
                if ((ID & 0xFFFF) == 0x3000)
                {
                    CaptureOptionsWindow.WindowName  = WindowName;
                    CaptureOptionsWindow.WindowTitle = WindowTitle;
                    CaptureOptionsWindow.MatchTitle  = MatchWindowTitle;
                    CaptureOptionsWindow.TopmostOnly = TopmostOnly;
                    CaptureOptionsWindow.Method      = Method;

                    if (CaptureOptionsWindow.ShowDialog(this) == DialogResult.OK)
                    {
                        WindowName        = CaptureOptionsWindow.WindowName;
                        WindowTitle       = CaptureOptionsWindow.WindowTitle;
                        MatchWindowTitle  = CaptureOptionsWindow.MatchTitle;
                        MatchWindowHandle = CaptureOptionsWindow.WindowHandle;
                        TopmostOnly       = CaptureOptionsWindow.TopmostOnly;
                        Method            = CaptureOptionsWindow.Method;
                    }
                }
                else if ((ID & 0xFFFF) == 0x3001)
                {
                    SettingOptionsWindow.ResizeOutput       = ResizeOutput;
                    SettingOptionsWindow.ResizeOutputHeight = ResizeOutputHeight;
                    SettingOptionsWindow.ResizeOutputWidth  = ResizeOutputWidth;

                    SettingOptionsWindow.CroppingTop    = CroppingTop;
                    SettingOptionsWindow.CroppingBottom = CroppingBottom;
                    SettingOptionsWindow.CroppingLeft   = CroppingLeft;
                    SettingOptionsWindow.CroppingRight  = CroppingRight;

                    SettingOptionsWindow.CaptureRate = CaptureRate;

                    if (SettingOptionsWindow.ShowDialog(this) == DialogResult.OK)
                    {
                        ResizeOutput       = SettingOptionsWindow.ResizeOutput;
                        ResizeOutputHeight = SettingOptionsWindow.ResizeOutputHeight;
                        ResizeOutputWidth  = SettingOptionsWindow.ResizeOutputWidth;

                        CroppingTop    = SettingOptionsWindow.CroppingTop;
                        CroppingBottom = SettingOptionsWindow.CroppingBottom;
                        CroppingLeft   = SettingOptionsWindow.CroppingLeft;
                        CroppingRight  = SettingOptionsWindow.CroppingRight;
                        CaptureRate    = SettingOptionsWindow.CaptureRate;
                    }
                }
            }

            base.WndProc(ref m);
        }
Example #11
0
        public void Start()
        {
            if (IsRunning)
            {
                Log.Warn("already running");
                return;
            }

            IsRunning = true;
            try
            {
                Log.Debug("Capture method: {0}, Version: {1}", CaptureMethod, Assembly.GetEntryAssembly().GetName().Version);
                lastCaptureMethod      = CaptureMethod;
                preferredCaptureMethod = CaptureMethod;
                OnStarted();

                while (IsRunning)
                {
                    var start = DateTime.Now.Ticks;

                    CaptureLoop();

                    if (IsRunning)
                    {
                        DelayInternal(start);
                    }
                }
            }
            finally
            {
                foreach (var imageScanner in imageScanners)
                {
                    imageScanner.Stop(null);
                    // imageScanner.Dispose();
                }

                windowLost           = false;
                windowFound          = false;
                windowMinimized      = false;
                currentCaptureMethod = null;
                averageCount         = 0;
                averageSpeed         = 0;
                attached             = false;
                extraDelay           = 0;
                lastImageHeight      = 0;
                directXErrorCount    = 0;
                dontUseDirectX       = false;
                // this.lastCaptured = -1;

                OnStopped();
            }
        }
        public void Start()
        {
            if (this.running)
            {
                Log.Warn("already running");
                return;
            }
            running = true;
            // this.scannerThread = new Thread(ScannerThread) { IsBackground = true };
            // this.scannerThread.Start();

            Log.Debug("Capture method: {0}, Version: {1}", CaptureMethod, Assembly.GetEntryAssembly().GetName().Version);
            lastCaptureMethod      = CaptureMethod;
            preferredCaptureMethod = CaptureMethod;
            while (running)
            {
                var start = DateTime.Now.Ticks;

                CaptureLoop();

                if (running)
                {
                    DelayInternal(start);
                }
            }

            foreach (var imageScanner in this.imageScanners)
            {
                imageScanner.Stop(null);
                // imageScanner.Dispose();
            }

            this.windowLost           = false;
            this.windowFound          = false;
            this.windowMinimized      = false;
            this.currentCaptureMethod = null;
            this.averageCount         = 0;
            this.averageSpeed         = 0;
            this.attached             = false;
            this.extraDelay           = 0;
            this.lastImageHeight      = 0;
            this.directXErrorCount    = 0;
            this.dontUseDirectX       = false;
            // this.lastCaptured = -1;

            OnStopped();
        }
Example #13
0
    /*void OnGUI() //For testing
     * {
     *  if(GUI.Button(new Rect(100 * 0, 0, 100, 30), "AppCapture_Asynch"))
     *      SaveScreenshot(CaptureMethod.AppCapture_Asynch, Application.dataPath + "/screen1.png");
     *  else if(GUI.Button(new Rect(100 * 1, 0, 100, 30), "AppCapture_Synch"))
     *      SaveScreenshot(CaptureMethod.AppCapture_Synch, Application.dataPath + "/screen2.png");
     *  else if(GUI.Button(new Rect(100 * 2, 0, 100, 30), "ReadPixels_Asynch"))
     *      SaveScreenshot(CaptureMethod.ReadPixels_Asynch, Application.dataPath + "/screen3.png");
     *  else if(GUI.Button(new Rect(100 * 3, 0, 100, 30), "ReadPixels_Synch"))
     *      SaveScreenshot(CaptureMethod.ReadPixels_Synch, Application.dataPath + "/screen4.png");
     *  else if(GUI.Button(new Rect(100 * 4, 0, 100, 30), "RenderToTex_Asynch"))
     *      SaveScreenshot(CaptureMethod.RenderToTex_Asynch, Application.dataPath + "/screen5.png");
     *  else if(GUI.Button(new Rect(100 * 5, 0, 100, 30), "RenderToTex_Synch"))
     *      SaveScreenshot(CaptureMethod.RenderToTex_Synch, Application.dataPath + "/screen6.png");
     * }*/

    public void SaveScreenshot(CaptureMethod method, string filePath, Camera cam = null)
    {
        if (method == CaptureMethod.AppCapture_Asynch)
        {
            ScreenCapture.CaptureScreenshot(filePath);
        }
        else if (method == CaptureMethod.AppCapture_Synch)
        {
            Texture2D texture = GetScreenshot(CaptureMethod.AppCapture_Synch);
            byte[]    bytes   = texture.EncodeToPNG();
            File.WriteAllBytes(filePath, bytes);
        }
        else if (method == CaptureMethod.ReadPixels_Asynch)
        {
            StartCoroutine(SaveScreenshot_ReadPixelsAsynch(filePath));
        }
        else if (method == CaptureMethod.ReadPixels_Synch)
        {
            Texture2D texture = GetScreenshot(CaptureMethod.ReadPixels_Synch);

            byte[] bytes = texture.EncodeToPNG();

            //Save our test image (could also upload to WWW)
            File.WriteAllBytes(filePath, bytes);

            //Tell unity to delete the texture, by default it seems to keep hold of it and memory crashes will occur after too many screenshots.
            Destroy(texture);
        }
        else if (method == CaptureMethod.RenderToTex_Asynch)
        {
            if (cam != null)
            {
                StartCoroutine(SaveScreenshot_RenderToTexAsynch(filePath, cam));
            }
            else
            {
                StartCoroutine(SaveScreenshot_RenderToTexAsynch(filePath));
            }
        }
        else
        {
            Texture2D screenShot = GetScreenshot(CaptureMethod.RenderToTex_Synch);
            byte[]    bytes      = screenShot.EncodeToPNG();
            File.WriteAllBytes(filePath, bytes);
        }
    }
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            switch (e.Index)
            {
            case 1:
                LogicalName = GXCommon.ToLogicalName(e.Value);
                break;

            case 2:
                if (e.Value is byte[])
                {
                    Buffer = (byte[])e.Value;
                }
                else if (e.Value is string)
                {
                    Buffer = GXCommon.HexToBytes((string)e.Value);
                }
                break;

            case 3:
                SetCaptureObjects(settings, CaptureObjects, (object[])e.Value);
                if (settings.IsServer)
                {
                    UpdateTemplateDescription();
                }
                break;

            case 4:
                TemplateId = (byte)e.Value;
                break;

            case 5:
                TemplateDescription = (byte[])e.Value;
                break;

            case 6:
                CaptureMethod = (CaptureMethod)Convert.ToByte(e.Value);
                break;

            default:
                e.Error = ErrorCode.ReadWriteDenied;
                break;
            }
        }
Example #15
0
        public void CaptureImages(CaptureMethod capturemethod, SaveMethod savemethod)
        {
            _saveMethod = savemethod;

            switch (capturemethod)
            {
            case CaptureMethod.Pixels:
                StartCoroutine(ReadPixels());
                break;

            case CaptureMethod.Tex:
                StartCoroutine(RenderToTex());
                break;

            case CaptureMethod.App:
                StartCoroutine(ScreenShot());
                break;
            }
        }
Example #16
0
        /// <summary>
        /// Parse Argument to get the Capture Method
        /// </summary>
        /// <param name="args">Args from Main</param>

        /*static void ArgumentParser(string[] args)
         * {
         *  if (String.Compare(args[0], "Local", StringComparison.OrdinalIgnoreCase) == 0)
         *      captureMethod = new LocalCapture(bitmapBuffer); //Default: Local Capture
         *  else if (String.Compare(args[0], "CaptureCard", StringComparison.OrdinalIgnoreCase) == 0)
         *      captureMethod = new CardCapture(bitmapBuffer);  //Fetch Image From Capture Card
         *  else
         *  {
         *      // Unknown Argument
         *      Console.WriteLine();
         *      Console.WriteLine("Wrong Argument!");
         *      Console.WriteLine("Usage:");
         *      Console.WriteLine($"\t{Process.GetCurrentProcess().ProcessName} [ImageSource]");
         *      Console.WriteLine($"\t[ImageSource]: Local or CaptureCard");
         *      Console.WriteLine();
         *      // Force close the process
         *      Process.GetCurrentProcess().Kill();
         *  }
         * }*/
        static void Main(string[] args)
        {
            globalStopwatch = new Stopwatch();
            globalStopwatch.Start();

            Thread.Sleep(5000);
            Console.CancelKeyPress +=
                new ConsoleCancelEventHandler((o, t) =>
            {
                captureMethod.Stop();       //Stop Capturing
            });

            captureMethod = new LocalCapture(bitmapBuffer);

            // Check the Capture Method from args
            //if (args.Length == 0)
            //    captureMethod = new LocalCapture(bitmapBuffer); // Default: Local Capture
            //else
            //    ArgumentParser(args); // Parse Arguments

            //if (captureMethod == null)
            //    throw new Exception("Error! CaptureMethod is null!");

            // Start Capture
            captureMethod.Start();

            // Start dispatch frames
            bitmapBuffer.StartDispatchToImageProcessBase();

            FeatureExtractors arrivalEvents = FeatureExtractors.InitFeatureExtractor(
                (int)Enum.Parse(typeof(GameType), args[0]),
                args.Skip(1).ToArray()
                );

            // Do Cache Optimizer
            CacheOptimizer.Init();
            CacheOptimizer.ResetAllAffinity();
        }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         if (e.Value is byte[])
         {
             Buffer = GXCommon.ToHex((byte[])e.Value, true);
         }
         else
         {
             Buffer = Convert.ToString(e.Value);
         }
     }
     else if (e.Index == 3)
     {
         CaptureObjects = e.Value;
     }
     else if (e.Index == 4)
     {
         TemplateId = (byte)e.Value;
     }
     else if (e.Index == 5)
     {
         TemplateDescription = (byte[])e.Value;
     }
     else if (e.Index == 6)
     {
         CaptureMethod = (CaptureMethod)e.Value;
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
        private void SetCurrentEngine(CaptureMethod method)
        {
            var oldEngine = currentCaptureEngine;
            switch (method)
            {
                case CaptureMethod.AutoDetect:
                case CaptureMethod.BitBlt:
                case CaptureMethod.Wdm:
                case CaptureMethod.DirectX:
                    currentCaptureEngine = autoCaptureEngine;
                    break;
                case CaptureMethod.Log:
                    currentCaptureEngine = logCaptureEngine;
                    break;
            }

            if (oldEngine != currentCaptureEngine
                && oldEngine.IsRunning)
            {
                oldEngine.Stop();
                currentCaptureEngine.StartAsync();
            }
        }
Example #19
0
        public static IServiceCollection AddCoreServices(this IServiceCollection services, CancellationToken token, Type stormReplayProvider)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .AddEnvironmentVariables("HEROES_REPLAY_")
                                .Build();

            CaptureMethod captureMethod = configuration.GetValue <CaptureMethod>("Settings:CaptureMethod");

            Type captureStrategy = captureMethod switch
            {
                CaptureMethod.None => typeof(StubCapture),
                CaptureMethod.BitBlt => typeof(CaptureBitBlt),
                CaptureMethod.CopyFromScreen => typeof(CaptureFromScreen),
                _ => typeof(CaptureBitBlt)
            };

            return(services
                   .AddLogging(builder => builder.AddConfiguration(configuration.GetSection("Logging")).AddConsole())
                   .AddSingleton <IConfiguration>(configuration)
                   .Configure <Settings>(configuration.GetSection("Settings"))
                   .AddSingleton(provider => new CancellationTokenProvider(token))
                   .AddSingleton(typeof(HeroesOfTheStorm), captureMethod switch { CaptureMethod.None => typeof(StubOfTheStorm), _ => typeof(HeroesOfTheStorm) })
Example #20
0
    public Texture2D GetScreenshot(CaptureMethod method, Vector2? from = null, Vector2? to = null)
    {
        if (from == null)
        {
            from = new Vector2(0, 0);
        }

        if (to == null)
        {
            to = new Vector2(Screen.width, Screen.height);
        }

        Vector2 imageDimension = to.Value - from.Value;

        if (method == CaptureMethod.AppCapture_Synch)
        {
            string tempFilePath = System.Environment.GetEnvironmentVariable("TEMP") + "/screenshotBuffer" + tempFileCount + ".png";
            tempFileCount++;
            Application.CaptureScreenshot(tempFilePath);
            WWW www = new WWW("file://" + tempFilePath.Replace(Path.DirectorySeparatorChar.ToString(), "/"));

            Texture2D texture = new Texture2D((int)imageDimension.x, (int)imageDimension.y, TextureFormat.RGB24, false);
            while (!www.isDone) { }
            www.LoadImageIntoTexture((Texture2D)texture);
            File.Delete(tempFilePath); //Can delete now

            return texture;
        }
        else if (method == CaptureMethod.ReadPixels_Synch)
        {
            //Create a texture to pass to encoding
            Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

            //Put buffer into texture
            texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); //Unity complains about this line's call being made "while not inside drawing frame", but it works just fine.*

            return texture;
        }


        ///GUARDA ME CHE HO MIRATO MALE
        else if (method == CaptureMethod.RenderToTex_Synch)
        {
            RenderTexture rt = new RenderTexture((int)imageDimension.x, (int)imageDimension.y, 24);
            Texture2D screenShot = new Texture2D((int)imageDimension.x, (int)imageDimension.y, TextureFormat.RGB24, false);

            //Camera.main.targetTexture = rt;
            //Camera.main.Render();

            //Render from all!
            foreach (Camera cam in Camera.allCameras)
            {
                cam.targetTexture = rt;
                cam.Render();
                cam.targetTexture = null;
            }

            RenderTexture.active = rt;
            screenShot.ReadPixels(new Rect(from.Value, imageDimension), (int)from.Value.x, (int)from.Value.y);
            Camera.main.targetTexture = null;
            RenderTexture.active = null; //Added to avoid errors
            Destroy(rt);

            return screenShot;
        }
        else
            return null;
    }
        private void CaptureLoop()
        {
            IntPtr wnd;

            try
            {
                wnd = HearthstoneHelper.GetHearthstoneWindow();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                OnWindowLost();
                return;
            }

            // Verify window exists
            if (wnd == IntPtr.Zero)
            {
                OnWindowLost();
                return;
            }

            ScreenshotResource img = null;

            try
            {
                if (currentCaptureMethod == null)
                {
                    currentCaptureMethod = CaptureMethod;
                }

                if (preferredCaptureMethod != CaptureMethod)
                {
                    // user changed capture method in settings
                    currentCaptureMethod   = CaptureMethod;
                    preferredCaptureMethod = CaptureMethod;
                }

                if (dontUseDirectX && currentCaptureMethod.Value == CaptureMethod.DirectX)
                {
                    Log.Info("DirectX gave too much errors, switching to Wdm.");
                    currentCaptureMethod = CaptureMethod.Wdm;
                }

                switch (currentCaptureMethod)
                {
                case CaptureMethod.AutoDetect:
                    var detectedMethod = DetectCaptureMethod(wnd, out img);
                    if (detectedMethod == null)
                    {
                        OnWindowMinimized();
                        extraDelay = 200;     // small delay, just enough to not be noticable, but less cpu
                        Thread.Sleep(extraDelay);
                        return;
                    }
                    currentCaptureMethod = detectedMethod.Value;
                    break;

                case CaptureMethod.DirectX:
                    img = CaptureDirectX(wnd);
                    break;

                case CaptureMethod.Wdm:
                    img = CaptureWdm(wnd);
                    break;

                case CaptureMethod.BitBlt:
                    img = CaptureWdm(wnd, false, true);
                    break;
                }

                if (lastCaptureMethod != currentCaptureMethod.Value)
                {
                    Log.Debug("Capture method changed from {0} to {1}", lastCaptureMethod, currentCaptureMethod.Value);
                    // Do not detach hook, so we can quickly switch again
                    //if (lastCaptureMethod == CaptureMethod.DirectX)
                    //{
                    //    DettachHookFromProcess();
                    //}
                    lastCaptureMethod = currentCaptureMethod.Value;
                }

                if (img == null || img.Bitmap == null)
                {
                    TraceLog.Log("No image data found.");
                    OnWindowMinimized();
                    extraDelay = 200; // small delay, just enough to not be noticable, but less cpu
                    Thread.Sleep(extraDelay);
                    return;
                }

                if (CaptureMethod == CaptureMethod.AutoDetect)
                {
                    if (lastImageHeight > 0 && lastImageHeight != img.Bitmap.Height)
                    {
                        // reset capture method so we detect again on next run
                        Log.Debug("Auto-detect: Image resolution changed from {0} to {1}, reset auto-detect.", lastImageHeight, img.Bitmap.Height);
                        currentCaptureMethod = null;
                    }

                    lastImageHeight = img.Bitmap.Height;
                }

                extraDelay = 0;
                OnWindowFound();

                if (this.PublishCapturedWindow)
                {
                    // Log.Diag("Window captured");
                    var bmpcpy = new Bitmap(img.Bitmap);
                    this.Publish(new WindowCaptured(bmpcpy), log: false);
                }

                var start = DateTime.Now.Ticks;

                try
                {
                    // scan areas, publish events;
                    foreach (var scanner in this.imageScanners)
                    {
                        scanner.Run(img.Bitmap, null);
                    }
                }
                finally
                {
                    try
                    {
                        if (img != null)
                        {
                            img.Dispose();
                        }
                    }
                    catch { }

                    var stop = DateTime.Now.Ticks;
                    var proc = TimeSpan.FromTicks(stop - start).Milliseconds;
                    TraceLog.Log("Scanner speed: {0}", proc);
                }
                // wait with passing next capture to scanner and signal scanner thread to process
                //this.captureWaitHandle.Wait();
                //this.captureWaitHandle.Reset();
                //if (this.currentImage != null)
                //{
                //    this.currentImage.Dispose();
                //    this.currentImage = null;
                //}
                //this.currentImage = img;
                //this.scannerWaitHandle.Set();
            }
            catch (ScreenshotCaptureException ex)
            {
                Log.Debug(ex.ToString());
                OnWindowLost();
                extraDelay = 2000;
                Thread.Sleep(extraDelay);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Example #22
0
        private void PerformWndCapture(UIElem uiElem)
        {
            if (m_bRegOrWnd == true)
            {
                // if a region was selected
                MessageBox.Show("You selected a region!");
                return;
            }

            if (uiElem == null)
            {
                return;
            }

            // get the text and font
            //stdole.IFontDisp font;
            string        strText    = "";
            CaptureMethod captMethod = GetCaptureMethod();

            if (captMethod == CaptureMethod.NATIVE)
            {
                try
                {
                    // preserve layout checkbox
                    if (checkLayout.Checked == true)
                    {
                        m_tCapture.FormattedText = true;
                    }
                    strText = m_tCapture.GetTextFromUIElem(uiElem);
                    //txtFont.Text = font.Name;
                    //txtFontSize.Text = font.Size.ToString();
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000); // sleep for 4 seconds
                        PerformWndCapture(uiElem);           // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else if (captMethod == CaptureMethod.FULL_TEXT)
            {
                try
                {
                    strText      = m_tFullTextCapt.GetFullTextFromUIElem(uiElem);
                    txtFont.Text = "";
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000); // sleep for 4 seconds
                        PerformWndCapture(uiElem);           // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else if (captMethod == CaptureMethod.OCR)
            {
                try
                {
                    string strLang = (string)comboLang.Items[comboLang.SelectedIndex];

                    strText      = m_tOCRCapture.GetTextFromUIElem(uiElem, strLang, false);
                    txtFont.Text = "";
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000); // sleep for 4 seconds
                        PerformWndCapture(uiElem);           // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            txtResult.Text = strText;
        }
Example #23
0
        public IActionResult CaptureMethod(int id)
        {
            CaptureMethod model = this.dataService.GetObjectByPropertyValue <CaptureMethod>("Id", id);

            return(this.View(model));
        }
        private void CaptureLoop()
        {
            IntPtr wnd;
            try
            {
                wnd = HearthstoneHelper.GetHearthstoneWindow();
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                OnWindowLost();
                return;
            }

            // Verify window exists
            if (wnd == IntPtr.Zero)
            {
                OnWindowLost();
                return;
            }

            ScreenshotResource img = null;
            try
            {
                if (currentCaptureMethod == null)
                {
                    currentCaptureMethod = CaptureMethod;
                }

                if (preferredCaptureMethod != CaptureMethod)
                {
                    // user changed capture method in settings
                    currentCaptureMethod = CaptureMethod;
                    preferredCaptureMethod = CaptureMethod;
                }

                if (dontUseDirectX && currentCaptureMethod.Value == CaptureMethod.DirectX)
                {
                    Log.Info("DirectX gave too much errors, switching to Wdm.");
                    currentCaptureMethod = CaptureMethod.Wdm;
                }

                switch (currentCaptureMethod)
                {
                    case CaptureMethod.AutoDetect:
                        var detectedMethod = DetectCaptureMethod(wnd, out img);
                        if (detectedMethod == null)
                        {
                            OnWindowMinimized();
                            extraDelay = 200; // small delay, just enough to not be noticable, but less cpu
                            Thread.Sleep(extraDelay);
                            return;
                        }
                        currentCaptureMethod = detectedMethod.Value;
                        break;
                    case CaptureMethod.DirectX:
                        img = CaptureDirectX(wnd);
                        break;
                    case CaptureMethod.Wdm:
                        img = CaptureWdm(wnd);
                        break;
                    case CaptureMethod.BitBlt:
                        img = CaptureWdm(wnd, false, true);
                        break;
                }

                if (lastCaptureMethod != currentCaptureMethod.Value)
                {
                    Log.Debug("Capture method changed from {0} to {1}", lastCaptureMethod, currentCaptureMethod.Value);
                    // Do not detach hook, so we can quickly switch again
                    //if (lastCaptureMethod == CaptureMethod.DirectX)
                    //{
                    //    DettachHookFromProcess();
                    //}
                    lastCaptureMethod = currentCaptureMethod.Value;
                }

                if (img == null
                    || img.Bitmap == null)
                {
                    TraceLog.Log("No image data found.");
                    OnWindowMinimized();
                    extraDelay = 200; // small delay, just enough to not be noticable, but less cpu
                    Thread.Sleep(extraDelay);
                    return;
                }

                if (CaptureMethod == CaptureMethod.AutoDetect)
                {
                    if (lastImageHeight > 0
                        && lastImageHeight != img.Bitmap.Height)
                    {
                        // reset capture method so we detect again on next run
                        Log.Debug("Auto-detect: Image resolution changed from {0} to {1}, reset auto-detect.", lastImageHeight, img.Bitmap.Height);
                        currentCaptureMethod = null;
                    }

                    lastImageHeight = img.Bitmap.Height;
                }

                extraDelay = 0;
                OnWindowFound();

                if (PublishCapturedWindow)
                {
                    // Log.Diag("Window captured");
                    var bmpcpy = new Bitmap(img.Bitmap);
                    Publish(new WindowCaptured(bmpcpy), log: false);
                }

                var start = DateTime.Now.Ticks;

                try
                {
                    // scan areas, publish events;
                    foreach (var scanner in imageScanners)
                    {
                        scanner.Run(img.Bitmap, null);
                    }
                }
                finally
                {
                    try
                    {
                        if (img != null)
                        {
                            img.Dispose();
                        }
                    }
                    catch
                    {
                    }

                    var stop = DateTime.Now.Ticks;
                    var proc = TimeSpan.FromTicks(stop - start).Milliseconds;
                    TraceLog.Log("Scanner speed: {0}", proc);
                }
                // wait with passing next capture to scanner and signal scanner thread to process
                //this.captureWaitHandle.Wait();
                //this.captureWaitHandle.Reset();
                //if (this.currentImage != null)
                //{
                //    this.currentImage.Dispose();
                //    this.currentImage = null;
                //}
                //this.currentImage = img;
                //this.scannerWaitHandle.Set();
            }
            catch (ScreenshotCaptureException ex)
            {
                Log.Debug(ex.ToString());
                OnWindowLost();
                extraDelay = 2000;
                Thread.Sleep(extraDelay);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
        public void Start()
        {
            if (IsRunning)
            {
                Log.Warn("already running");
                return;
            }

            IsRunning = true;
            try
            {
                Log.Debug("Capture method: {0}, Version: {1}", CaptureMethod, Assembly.GetEntryAssembly().GetName().Version);
                lastCaptureMethod = CaptureMethod;
                preferredCaptureMethod = CaptureMethod;
                OnStarted();

                while (IsRunning)
                {
                    var start = DateTime.Now.Ticks;

                    CaptureLoop();

                    if (IsRunning)
                    {
                        DelayInternal(start);
                    }
                }
            }
            finally
            {
                foreach (var imageScanner in imageScanners)
                {
                    imageScanner.Stop(null);
                    // imageScanner.Dispose();
                }

                windowLost = false;
                windowFound = false;
                windowMinimized = false;
                currentCaptureMethod = null;
                averageCount = 0;
                averageSpeed = 0;
                attached = false;
                extraDelay = 0;
                lastImageHeight = 0;
                directXErrorCount = 0;
                dontUseDirectX = false;
                // this.lastCaptured = -1;

                OnStopped();
            }
        }
Example #26
0
        private void PerformRegionCapture(int hwnd, int x, int y, int width, int height)
        {
            if (m_bRegOrWnd == false)
            {
                // if a window was selected
                MessageBox.Show("You selected a window!");
                return;
            }

            CaptureMethod currentMethod = GetCaptureMethod();
            string        strText       = "";

            if (currentMethod == CaptureMethod.NATIVE)
            {
                //stdole.IFontDisp font;
                try
                {
                    // preserve layout checkbox
                    if (checkLayout.Checked == true)
                    {
                        m_tCapture.FormattedText = true;
                    }
                    strText = m_tCapture.GetTextFromRect(hwnd, x, y, width, height);
                    //txtFont.Text = font.Name;
                    //txtFontSize.Text = font.Size.ToString();
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(4000);             // sleep for 4 seconds
                        PerformRegionCapture(hwnd, x, y, width, height); // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else if (currentMethod == CaptureMethod.FULL_TEXT)
            {
                try
                {
                    strText      = m_tFullTextCapt.GetFullTextFromRectangle(hwnd, x, y, width, height);
                    txtFont.Text = "";
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000);             // sleep for 4 seconds
                        PerformRegionCapture(hwnd, x, y, width, height); // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else if (currentMethod == CaptureMethod.OCR)
            {
                try
                {
                    string strLang = (string)comboLang.Items[comboLang.SelectedIndex];
                    strText      = m_tOCRCapture.GetTextFromRect(hwnd, x, y, width, height, strLang, false);
                    txtFont.Text = "";
                }
                catch (Exception ex)
                {
                    System.Runtime.InteropServices.COMException COMEx = (System.Runtime.InteropServices.COMException)ex;
                    if (COMEx.ErrorCode == -2147220989 && m_bCanTryAgain)
                    {
                        // this is the timeout exception

                        m_bCanTryAgain = false;
                        MessageBox.Show("Trying again!");
                        System.Threading.Thread.Sleep(5000);             // sleep for 4 seconds
                        PerformRegionCapture(hwnd, x, y, width, height); // and try again

                        return;
                    }
                    else
                    {
                        strText = "Capture Error!";
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            txtResult.Text = strText;
        }
    void OnGUI()
    {
        GUI.color = Color.white;
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);

        foldoutSettings = EditorGUILayout.Foldout(foldoutSettings, "Settings");

        if (foldoutSettings)
        {
            EditorGUILayout.BeginHorizontal();
            superSize = EditorGUILayout.IntSlider("size multiplier", superSize, 1, 16);
            EditorGUILayout.LabelField(getResolution(), EditorStyles.boldLabel, GUILayout.MaxWidth(100));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.SelectableLabel("folder: " + System.IO.Directory.GetCurrentDirectory() + @"\Screenshots\");

            customName = EditorGUILayout.TextField("custom name", customName);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("CamName"))
            {
                includeCamName = !includeCamName;
            }
            if (GUILayout.Button("Date"))
            {
                includeDate = !includeDate;
            }
            if (GUILayout.Button("Resolution"))
            {
                includeResolution = !includeResolution;
            }
            fileType = (FileType)EditorGUILayout.EnumPopup(fileType);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.LabelField("file name: " + getFileName(lastCamID));

            EditorGUILayout.Space();

            captureMethod = (CaptureMethod)EditorGUILayout.EnumPopup("capture method", captureMethod);
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();

        GUILayout.Label("Cameras:", EditorStyles.boldLabel);

        for (int i = 0; i < list.Count; i++)
        {
            ScreenshotCreator.CameraObject c = list[i];

            GUI.color = Color.white;
            EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);

            list[i].cam = (GameObject)EditorGUILayout.ObjectField(list[i].cam, typeof(GameObject), true);

            //EditorGUI.BeginDisabledGroup (!EditorApplication.isPlaying);
            if (list [i].cam != null)
            {
                if (GUILayout.Button("USE " + list [i].cam.name, new GUIStyle(EditorStyles.miniButtonLeft)))
                {
                    refreshRequests();
                    if (captureMethod == CaptureMethod.RenderTexture)
                    {
                        Camera attachedCam = list [i].cam.GetComponent <Camera> ();
                        if (attachedCam == null)
                        {
                            CaptureScreenshots(i, true);
                        }
                        else
                        {
                            CaptureRenderTexture(attachedCam, i);
                        }
                    }
                    else if (captureMethod == CaptureMethod.CaptureScreenshot)
                    {
                        CaptureScreenshots(i, false);
                    }

                    lastCam = list [lastCamID].cam.GetComponent <Camera> ();
                }
            }
            //EditorGUI.EndDisabledGroup();

            // the delete button
            if (c.deleteQuestion)
            {
                GUI.color = Color.red;
                if (GUILayout.Button("YES?", new GUIStyle(EditorStyles.miniButtonRight), GUILayout.MaxWidth(45), GUILayout.MaxHeight(14)))
                {
                    refreshRequests();
                    Delete(i);
                }
            }
            else
            {
                GUI.color = (Color.red + Color.white * 2f) / 3f;
                if (GUILayout.Button("X", new GUIStyle(EditorStyles.miniButtonRight), GUILayout.MaxWidth(45), GUILayout.MaxHeight(14)))
                {
                    refreshRequests();
                    RequestDelete(i);
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        GUI.color = new Color(0.54f, 0.68f, 0.95f);
        if (GUILayout.Button("ADD CAMERA", GUILayout.MaxWidth(100), GUILayout.MinWidth(100), GUILayout.MaxHeight(25), GUILayout.MinHeight(25)))
        {
            refreshRequests();
            Create();
        }
    }
Example #28
0
        public IActionResult CaptureMethod(CaptureMethod captureMethod)
        {
            this.dataService.DeleteCaptureMethod(captureMethod.Id);

            return(this.RedirectToAction("CaptureMethods", "Admin"));
        }
Example #29
0
 private void MethodDropdown_SelectedIndexChanged(object sender, EventArgs e)
 {
     Method = (CaptureMethod)MethodDropdown.SelectedIndex;
 }
    void OnGUI()
    {
        GUI.color = signatureColor;
        if (GUILayout.Button("TOGGLE SETTINGS", "toolbarButton", GUILayout.MaxWidth(120), GUILayout.MinWidth(120)))
        {
            refreshRequests();
            foldoutSettings = !foldoutSettings;
        }

        GUI.color = Color.white;

        if (foldoutSettings)
        {
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            EditorGUILayout.LabelField("CAPTURE SETTINGS", EditorStyles.boldLabel);

            GUI.color     = signatureColor;
            captureMethod = (ScreenshotCompanionWindow.CaptureMethod)EditorGUILayout.EnumPopup("capture method", captureMethod);

            GUI.color = Color.white;
            if (captureMethod == ScreenshotCompanionWindow.CaptureMethod.Cutout)
            {
                EditorGUILayout.HelpBox("This capture method is not supported in the Screenshot Companion Window. Please create an instance on a GameObject in your Scene.", MessageType.Info);
            }
            else if (captureMethod == ScreenshotCompanionWindow.CaptureMethod.RenderTexture)
            {
                EditorGUILayout.HelpBox("This capture method creates a RenderTexture that captures any Camera's " +
                                        "output in a custom resolution. This method also creates the sharpest upscaled images, but it can only use a single Camera.", MessageType.Info);

                EditorGUILayout.BeginHorizontal();

                GUI.color            = Color.white;
                renderSizeMultiplier = EditorGUILayout.Slider("Size Multiplyer (float)", renderSizeMultiplier, 0.1f, 10f);
                EditorGUILayout.LabelField(getResolution(), EditorStyles.boldLabel, GUILayout.MaxWidth(100));

                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.HelpBox("This capture method creates a screenshot that is upscaled by a rounded number multiplier. ", MessageType.Info);

                singleCameraToggle();

                EditorGUILayout.BeginHorizontal();

                GUI.color             = Color.white;
                captureSizeMultiplier = EditorGUILayout.IntSlider("Size Multiplyer (int)", captureSizeMultiplier, 1, 10);
                EditorGUILayout.LabelField(getResolution(), EditorStyles.boldLabel, GUILayout.MaxWidth(100));

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();

            if (captureMethod != ScreenshotCompanionWindow.CaptureMethod.Cutout)
            {
                EditorGUILayout.Space();

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                EditorGUILayout.LabelField("DIRECTORY SETTINGS", EditorStyles.boldLabel);

                customDirectory = EditorGUILayout.TextField("Custom Name", customDirectory);

                applicationPathToggle();

                GUI.color = Color.white;
                EditorGUILayout.SelectableLabel("Directory = " + getSaveDirectory(), GUILayout.MaxHeight(16));


                EditorGUILayout.EndVertical();

                EditorGUILayout.Space();


                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                EditorGUILayout.LabelField("FILE SETTINGS", EditorStyles.boldLabel);



                customName = EditorGUILayout.TextField("Custom Name", customName);

                fileName();

                EditorGUILayout.LabelField("File Name = " + getFileName(lastCamID));

                EditorGUILayout.Space();



                fileTypeGUI();

                EditorGUILayout.Space();

                EditorGUILayout.EndVertical();
            }
        }

        if (captureMethod != ScreenshotCompanionWindow.CaptureMethod.Cutout)
        {
            EditorGUILayout.Space();

            GUI.color = signatureColor;



            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            GUI.color = Color.white;

            GUILayout.Label("Cameras:", EditorStyles.boldLabel);

            for (int i = 0; i < list.Count; i++)
            {
                CameraObject c = list[i];

                GUI.color = Color.white;
                EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);

                list[i].cam = (GameObject)EditorGUILayout.ObjectField(list[i].cam, typeof(GameObject), true);

                EditorGUI.BeginDisabledGroup(captureMethod == ScreenshotCompanionWindow.CaptureMethod.Cutout && !EditorApplication.isPlaying);
                if (list[i].cam != null)
                {
                    if (GUILayout.Button("USE " + list[i].cam.name, new GUIStyle(EditorStyles.miniButtonLeft)))
                    {
                        refreshRequests();
                        if (captureMethod == CaptureMethod.RenderTexture)
                        {
                            Camera attachedCam = list[i].cam.GetComponent <Camera>();
                            if (attachedCam == null)
                            {
                                CaptureScreenshots(i, true);
                            }
                            else
                            {
                                CaptureRenderTexture(attachedCam, i);
                            }
                        }
                        else if (captureMethod == CaptureMethod.CaptureScreenshot)
                        {
                            CaptureScreenshots(i, false);
                        }

                        lastCam = list[lastCamID].cam.GetComponent <Camera>();
                    }
                }
                EditorGUI.EndDisabledGroup();

                // the delete button
                if (c.deleteQuestion)
                {
                    GUI.color = Color.red;
                    if (GUILayout.Button("YES?", new GUIStyle(EditorStyles.miniButtonRight), GUILayout.MaxWidth(45), GUILayout.MaxHeight(14)))
                    {
                        refreshRequests();
                        Delete(i);
                    }
                }
                else
                {
                    GUI.color = (Color.red + Color.white * 2f) / 3f;
                    if (GUILayout.Button("X", new GUIStyle(EditorStyles.miniButtonRight), GUILayout.MaxWidth(45), GUILayout.MaxHeight(14)))
                    {
                        refreshRequests();
                        RequestDelete(i);
                    }
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();



            EditorGUILayout.Space();

            GUI.color = signatureColor;
            if (GUILayout.Button("ADD CAMERA", "toolbarButton", GUILayout.MaxWidth(120), GUILayout.MinWidth(120)))
            {
                refreshRequests();
                Create();
            }

            EditorGUILayout.Space();
        }
    }
        public void Start()
        {
            if (this.running)
            {
                Log.Warn("already running");
                return;
            }
            running = true;
            // this.scannerThread = new Thread(ScannerThread) { IsBackground = true };
            // this.scannerThread.Start();

            Log.Debug("Capture method: {0}, Version: {1}", CaptureMethod, Assembly.GetEntryAssembly().GetName().Version);
            lastCaptureMethod = CaptureMethod;
            preferredCaptureMethod = CaptureMethod;
            while (running)
            {
                var start = DateTime.Now.Ticks;

                CaptureLoop();

                if (running)
                {
                    DelayInternal(start);
                }
            }

            foreach (var imageScanner in this.imageScanners)
            {
                imageScanner.Stop(null);
                // imageScanner.Dispose();
            }

            this.windowLost = false;
            this.windowFound = false;
            this.windowMinimized = false;
            this.currentCaptureMethod = null;
            this.averageCount = 0;
            this.averageSpeed = 0;
            this.attached = false;
            this.extraDelay = 0;
            this.lastImageHeight = 0;
            this.directXErrorCount = 0;
            this.dontUseDirectX = false;
            // this.lastCaptured = -1;

            OnStopped();
        }