fixed the issue where overlay doesn't starting

added code for keypresses
master
Zaafar Ahmed 7 years ago
parent d046a5c326
commit c8a82072e7
  1. 4
      ClickableTransparentOverlay/ClickableTransparentOverlay.csproj
  2. 16
      ClickableTransparentOverlay/HookController.cs
  3. 2
      ClickableTransparentOverlay/ImGuiController.cs
  4. 62
      ClickableTransparentOverlay/NativeMethods.cs
  5. 21
      ClickableTransparentOverlay/Overlay.cs
  6. 2
      DriverProgram/DriverProgram.csproj
  7. 14
      DriverProgram/Program.cs

@ -53,6 +53,8 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>
</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Gma.System.MouseKeyHook, Version=5.6.130.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Gma.System.MouseKeyHook, Version=5.6.130.0, Culture=neutral, processorArchitecture=MSIL">
@ -258,7 +260,7 @@
<Compile Include="ImGuiController.cs" /> <Compile Include="ImGuiController.cs" />
<Compile Include="Overlay.cs" /> <Compile Include="Overlay.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WinApi.cs" /> <Compile Include="NativeMethods.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />

@ -166,15 +166,21 @@
{ {
return; return;
} }
// TODO:
var io = ImGui.GetIO();
if (io.KeyAlt) // Ignoring ALT key so we can do ALT+TAB or ALT+F4 etc. Not sure if ImGUI uses ALT key in anyway.
return;
if (io.WantTextInput || io.WantCaptureKeyboard)
{
io.AddInputCharacter(e.KeyChar);
e.Handled = true;
}
} }
private void _hook_KeyUp(object sender, KeyEventArgs e) private void _hook_KeyUp(object sender, KeyEventArgs e)
{ {
if (!Enable)
{
return;
}
// TODO: // TODO:
} }

@ -13,7 +13,7 @@
/// A modified version of ImGui.NET.SampleProgram's ImGuiController. /// A modified version of ImGui.NET.SampleProgram's ImGuiController.
/// Manages input for ImGui and handles rendering ImGui's DrawLists with Veldrid. /// Manages input for ImGui and handles rendering ImGui's DrawLists with Veldrid.
/// </summary> /// </summary>
public class ImGuiController : IDisposable public sealed class ImGuiController : IDisposable
{ {
private GraphicsDevice _gd; private GraphicsDevice _gd;
private bool _frameBegun; private bool _frameBegun;

@ -3,27 +3,35 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public static class WinApi public static class NativeMethods
{ {
private const int GWL_EXSTYLE = -20; private const int GWL_EXSTYLE = -20;
private const int WS_EX_LAYERED = 0x80000; private const int WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20; private const int WS_EX_TRANSPARENT = 0x20;
private const int LWA_ALPHA = 0x02;
private const int LWA_COLORKEY = 0x01;
private const int SW_HIDE = 0x00; private const int SW_HIDE = 0x00;
private const int SW_SHOW = 0x05; private const int SW_SHOW = 0x05;
public static void EnableTransparent(IntPtr handle, System.Drawing.Rectangle size) public static void EnableTransparent(IntPtr handle, System.Drawing.Rectangle size)
{ {
int windowLong = GetWindowLong(handle, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT; IntPtr windowLong = GetWindowLongPtr(handle, GWL_EXSTYLE);
SetWindowLong(handle, GWL_EXSTYLE, new IntPtr(windowLong)); windowLong = new IntPtr(windowLong.ToInt64() | WS_EX_LAYERED | WS_EX_TRANSPARENT);
//SetLayeredWindowAttributes(handle, 0, 255, LWA_ALPHA /*| LWA_COLORKEY*/ ); SetWindowLongPtr(handle, GWL_EXSTYLE, windowLong);
Margins margins = Margins.FromRectangle(size); Margins margins = Margins.FromRectangle(size);
DwmExtendFrameIntoClientArea(handle, ref margins); DwmExtendFrameIntoClientArea(handle, ref margins);
} }
#region Structures public static void HideConsoleWindow()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
}
public static void ShowConsoleWindow()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_SHOW);
}
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
private struct Margins private struct Margins
@ -43,47 +51,19 @@
} }
} }
[StructLayout(LayoutKind.Sequential)]
private struct Rect
{
private readonly int left, top, right, bottom;
public System.Drawing.Rectangle ToRectangle(System.Drawing.Point point)
{
return new System.Drawing.Rectangle(point.X, point.Y, right - left, bottom - top);
}
}
#endregion Structures
public static void HideConsoleWindow()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
}
public static void ShowConsoleWindow()
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_SHOW);
}
[DllImport("dwmapi.dll")] [DllImport("dwmapi.dll")]
private static extern IntPtr DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset); private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong); private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
private static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, byte bAlpha, uint dwFlags); private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("kernel32.dll")] [DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow(); static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")] [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
} }
} }

@ -24,6 +24,7 @@
private static Vector2 _future_size; private static Vector2 _future_size;
private static int _fps; private static int _fps;
private static bool _is_visible; private static bool _is_visible;
private static bool _is_closed;
private static bool _require_resize; private static bool _require_resize;
private static bool _start_resizing; private static bool _start_resizing;
private static object _resize_thread_lock; private static object _resize_thread_lock;
@ -33,6 +34,7 @@
_clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f); _clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
_fps = fps; _fps = fps;
_is_visible = true; _is_visible = true;
_is_closed = false;
// Stuff related to (thread safe) resizing of SDL2Window // Stuff related to (thread safe) resizing of SDL2Window
_require_resize = false; _require_resize = false;
_start_resizing = false; _start_resizing = false;
@ -43,7 +45,7 @@
_window = new Sdl2Window("Overlay", x, x, width, height, SDL_WindowFlags.Borderless | SDL_WindowFlags.AlwaysOnTop | SDL_WindowFlags.SkipTaskbar, true); _window = new Sdl2Window("Overlay", x, x, width, height, SDL_WindowFlags.Borderless | SDL_WindowFlags.AlwaysOnTop | SDL_WindowFlags.SkipTaskbar, true);
// TODO: Create a new branch for Non-Veldrid dependent version. Ideally, we can directly use SDL2Window. // TODO: Create a new branch for Non-Veldrid dependent version. Ideally, we can directly use SDL2Window.
_gd = VeldridStartup.CreateGraphicsDevice(_window, new GraphicsDeviceOptions(true, null, true), GraphicsBackend.Direct3D11); _gd = VeldridStartup.CreateGraphicsDevice(_window, new GraphicsDeviceOptions(true, null, true), GraphicsBackend.Direct3D11);
WinApi.EnableTransparent(_window.Handle, new System.Drawing.Rectangle(_window.X , _window.Y, _window.Width, _window.Height)); NativeMethods.EnableTransparent(_window.Handle, new System.Drawing.Rectangle(_window.X , _window.Y, _window.Width, _window.Height));
_window.Resized += () => _window.Resized += () =>
{ {
_gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height); _gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height);
@ -54,6 +56,10 @@
_start_resizing = false; _start_resizing = false;
} }
}; };
_window.Closed += () =>
{
_is_closed = true;
};
_cl = _gd.ResourceFactory.CreateCommandList(); _cl = _gd.ResourceFactory.CreateCommandList();
_im_controller = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height, _fps); _im_controller = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height, _fps);
@ -65,7 +71,7 @@
{ {
_ui_thread.Start(); _ui_thread.Start();
_hook_controller.EnableHooks(); _hook_controller.EnableHooks();
WinApi.HideConsoleWindow(); NativeMethods.HideConsoleWindow();
Application.Run(new ApplicationContext()); Application.Run(new ApplicationContext());
} }
@ -73,13 +79,20 @@
{ {
_is_visible = false; _is_visible = false;
_window.Close(); _window.Close();
while (!_is_closed)
{
Thread.Sleep(10);
}
_ui_thread.Join(); _ui_thread.Join();
_gd.WaitForIdle(); _gd.WaitForIdle();
_im_controller.Dispose(); _im_controller.Dispose();
_cl.Dispose(); _cl.Dispose();
_gd.Dispose(); _gd.Dispose();
_hook_controller.Dispose(); _hook_controller.Dispose();
WinApi.ShowConsoleWindow(); NativeMethods.ShowConsoleWindow();
_resize_thread_lock = null;
SubmitUI = null;
Console.WriteLine("All Overlay resources are cleared."); Console.WriteLine("All Overlay resources are cleared.");
} }
@ -91,7 +104,7 @@
_future_size.Y = height; _future_size.Y = height;
// TODO: move following two lines to _window.Moved // TODO: move following two lines to _window.Moved
_hook_controller.UpdateWindowPosition(x, y); _hook_controller.UpdateWindowPosition(x, y);
WinApi.EnableTransparent(_window.Handle, new System.Drawing.Rectangle(x, y, width, height)); NativeMethods.EnableTransparent(_window.Handle, new System.Drawing.Rectangle(x, y, width, height));
_require_resize = true; _require_resize = true;
} }

@ -53,6 +53,8 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>
</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ImGui.NET, Version=1.66.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ImGui.NET, Version=1.66.0.0, Culture=neutral, processorArchitecture=MSIL">

@ -7,14 +7,14 @@
class Program class Program
{ {
private static Overlay demo; private static Overlay demo;
private static int Width; private static int Width = 2560;
private static int Height; private static int Height = 1440;
private static int Fps; private static int Fps = 144;
static void Main(string[] args) static void Main(string[] args)
{ {
Width = int.Parse(System.IO.File.ReadAllText("config/width.txt")); //Width = int.Parse(System.IO.File.ReadAllText("config/width.txt"));
Height = int.Parse(System.IO.File.ReadAllText("config/height.txt")); //Height = int.Parse(System.IO.File.ReadAllText("config/height.txt"));
Fps = int.Parse(System.IO.File.ReadAllText("config/fps.txt")); //Fps = int.Parse(System.IO.File.ReadAllText("config/fps.txt"));
var EndDemo = new Thread(DistroyDemo); var EndDemo = new Thread(DistroyDemo);
EndDemo.Start(); EndDemo.Start();
StartDemo(); StartDemo();
@ -30,7 +30,7 @@
public static void DistroyDemo() public static void DistroyDemo()
{ {
Thread.Sleep(10000); Thread.Sleep(10000);
demo.ResizeWindow(100, 100, 1024, 1024); demo.ResizeWindow(0, 0, 2560, 1440);
Thread.Sleep(10000); Thread.Sleep(10000);
demo.HideWindow(); demo.HideWindow();
Thread.Sleep(10000); Thread.Sleep(10000);

Loading…
Cancel
Save