/// <summary>
        /// Initializes a new instance of the <see cref="Overlay"/> class.
        /// </summary>
        static Overlay()
        {
            clearColor   = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
            loadedImages = new Dictionary <string, Texture>();
            window       = new Sdl2Window(
                "Overlay",
                0,
                0,
                2560,
                1440,
                SDL_WindowFlags.Borderless |
                SDL_WindowFlags.AlwaysOnTop |
                SDL_WindowFlags.SkipTaskbar,
                false);
            graphicsDevice = VeldridStartup.CreateDefaultD3D11GraphicsDevice(
                new GraphicsDeviceOptions(false, null, true),
                window);
            commandList  = graphicsDevice.ResourceFactory.CreateCommandList();
            imController = new ImGuiController(
                graphicsDevice,
                graphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                window.Width,
                window.Height);
            window.Resized += () =>
            {
                graphicsDevice.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);
                imController.WindowResized(window.Width, window.Height);
            };

            NativeMethods.InitTransparency(window.Handle);
            NativeMethods.SetOverlayClickable(window.Handle, false);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Overlay"/> class.
        /// </summary>
        /// <param name="x">
        /// x position of the overlay
        /// </param>
        /// <param name="y">
        /// y position of the overlay
        /// </param>
        /// <param name="width">
        /// width of the overlay
        /// </param>
        /// <param name="height">
        /// height of the Overlay
        /// </param>
        /// <param name="fps">
        /// fps of the overlay
        /// </param>
        /// <param name="debug">
        /// In this mode, overlay will not hide the Console
        /// </param>
        public Overlay(int x, int y, int width, int height, int fps, bool debug)
        {
            clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
            myFps      = fps;
            isClosed   = false;
            debugMode  = debug;

            // Stuff related to (thread safe) resizing of SDL2Window
            requireResize = false;
            futureSize    = Vector2.Zero;
            futurePos     = Vector2.Zero;

            window         = new Sdl2Window("Overlay", x, y, width, height, SDL_WindowFlags.Borderless | SDL_WindowFlags.AlwaysOnTop | SDL_WindowFlags.SkipTaskbar, false);
            graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, new GraphicsDeviceOptions(true, null, true), GraphicsBackend.Direct3D11);

            // graphicsDevice = VeldridStartup.CreateDefaultD3D11GraphicsDevice(new GraphicsDeviceOptions(true, null, true), window);
            NativeMethods.EnableTransparent(window.Handle, new System.Drawing.Rectangle(window.X, window.Y, window.Width, window.Height));
            window.Resized += () =>
            {
                graphicsDevice.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);
                imController.WindowResized(window.Width, window.Height);
                futureSize    = Vector2.Zero;
                futurePos     = Vector2.Zero;
                requireResize = false;
            };
            window.Closed += () =>
            {
                isClosed = true;
            };

            commandList    = graphicsDevice.ResourceFactory.CreateCommandList();
            imController   = new ImGuiController(graphicsDevice, graphicsDevice.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height, myFps);
            uiThread       = new Thread(this.WhileLoop);
            hookController = new HookController(window.X, window.Y);
        }
Esempio n. 3
0
        /// <summary>
        /// Starts the overlay
        /// </summary>
        /// <returns>A Task that finishes once the overlay window is ready</returns>
        public async Task Start()
        {
            cancellationTokenSource = new CancellationTokenSource();
            renderThread            = new Thread(async() =>
            {
                window = new Sdl2Window(
                    "Overlay",
                    0,
                    0,
                    2560,
                    1440,
                    SDL_WindowFlags.Borderless |
                    SDL_WindowFlags.AlwaysOnTop |
                    SDL_WindowFlags.SkipTaskbar,
                    false);
                graphicsDevice = VeldridStartup.CreateGraphicsDevice(window,
                                                                     new GraphicsDeviceOptions(false, null, true),
                                                                     GraphicsBackend.Direct3D11);
                commandList  = graphicsDevice.ResourceFactory.CreateCommandList();
                imController = new ImGuiController(
                    graphicsDevice,
                    graphicsDevice.MainSwapchain.Framebuffer.OutputDescription,
                    window.Width,
                    window.Height);
                window.Resized += () =>
                {
                    graphicsDevice.MainSwapchain.Resize((uint)window.Width, (uint)window.Height);
                    imController.WindowResized(window.Width, window.Height);
                };

                NativeMethods.InitTransparency(window.Handle);
                NativeMethods.SetOverlayClickable(window.Handle, false);
                if (!overlayIsReady)
                {
                    overlayIsReady = true;
                }

                await RunInfiniteLoop(cancellationTokenSource.Token);
            });

            renderThread.Start();
            await WaitHelpers.SpinWait(() => overlayIsReady);
        }