protected void EnableAttactWindow() { if (_windowEventHook != IntPtr.Zero) { return; } try { WinEventHook.WinEventDelegate windowEventDelegate = new WinEventHook.WinEventDelegate(AttachWindowEventCallback); _windowEventGCHandle = GCHandle.Alloc(windowEventDelegate); _windowEventHook = WinEventHook.WinEventHookOne(WinEventHook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE, windowEventDelegate, (uint)_gameMemory.Process.Id, WinEventHook.GetWindowThread(_gameMemory.Process.WindowHandle)); } catch (Exception ex) { Plugin.ShowExceptionMessage(ex); } if (_windowEventHook == IntPtr.Zero) { DisableAttactWindow(); } }
private bool CreateOverlay() { if (_isOverlayInitialized && !_isOverlayReady && _gameMemory.Process.WindowHandle != IntPtr.Zero) { _window.Create(); _graphics.Width = _window.Width; _graphics.Height = _window.Height; _graphics.WindowHandle = _window.Handle; _graphics.Setup(); _window.SizeChanged += (object sender, OverlaySizeEventArgs e) => _graphics.Resize(_window.Width, _window.Height); _window.FitTo(_gameMemory.Process.WindowHandle, true); if (_windowEventDispatcher != null) { _windowEventDispatcher.Invoke(delegate { WinEventHook.WinEventDelegate windowEventDelegate = new WinEventHook.WinEventDelegate(MoveGameWindowEventCallback); _windowEventGCHandle = GCHandle.Alloc(windowEventDelegate); _windowEventHook = WinEventHook.WinEventHookOne(WinEventHook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE, windowEventDelegate, (uint)_gameMemory.Process.Id, WinEventHook.GetWindowThread(_gameMemory.Process.WindowHandle)); }); } //Get a refernence to the underlying RenderTarget from SharpDX. This'll be used to draw portions of images. _device = (SharpDX.Direct2D1.WindowRenderTarget) typeof(Graphics) .GetField("_device", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) .GetValue(_graphics); _consolas14Bold = _graphics.CreateFont("Consolas", 14, true); _consolas16Bold = _graphics.CreateFont("Consolas", 16, true); _consolas32Bold = _graphics.CreateFont("Consolas", 32, true); _black = _graphics.CreateSolidBrush(0, 0, 0, Config.Opacity); _white = _graphics.CreateSolidBrush(255, 255, 255, Config.Opacity); _green = _graphics.CreateSolidBrush(0, 128, 0, Config.Opacity); _lawngreen = _graphics.CreateSolidBrush(124, 252, 0, Config.Opacity); _red = _graphics.CreateSolidBrush(255, 0, 0, Config.Opacity); _darkred = _graphics.CreateSolidBrush(139, 0, 0, Config.Opacity); _grey = _graphics.CreateSolidBrush(128, 128, 128, Config.Opacity); _darkergrey = _graphics.CreateSolidBrush(60, 60, 60, Config.Opacity); _gold = _graphics.CreateSolidBrush(255, 215, 0, Config.Opacity); _goldenrod = _graphics.CreateSolidBrush(218, 165, 32, Config.Opacity); _violet = _graphics.CreateSolidBrush(238, 130, 238, Config.Opacity); _characterSheet = ImageLoader.LoadBitmap(_device, Properties.Resources.portraits); _inventorySheet = ImageLoader.LoadBitmap(_device, Properties.Resources.objects); _isOverlayReady = true; } return(_isOverlayReady); }