From c7b4f887a6e26bdbb089a0f2488912129350cb64 Mon Sep 17 00:00:00 2001 From: IBM5100 <141636677+IBM5100o@users.noreply.github.com> Date: Sun, 22 Oct 2023 20:57:19 +0800 Subject: [PATCH] version 1.3 See release for details --- HDT-BGhelper/BGhelper.cs | 42 ++++++-------- HDT-BGhelper/BGhelperPlugin.cs | 76 ++++++++++++------------- HDT-BGhelper/Properties/AssemblyInfo.cs | 5 +- 3 files changed, 56 insertions(+), 67 deletions(-) diff --git a/HDT-BGhelper/BGhelper.cs b/HDT-BGhelper/BGhelper.cs index da2cbed..7e26984 100644 --- a/HDT-BGhelper/BGhelper.cs +++ b/HDT-BGhelper/BGhelper.cs @@ -7,8 +7,8 @@ namespace HDT_BGhelper { - internal class BGhelper - { + internal class BGhelper + { private bool hookExist; private IKeyboardMouseEvents m_GlobalHook; private const int WM_LBUTTONDOWN = 0x201; @@ -21,24 +21,21 @@ public BGhelper() } [DllImport("user32.dll")] - private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); - - [DllImport("user32.dll", EntryPoint = "WindowFromPoint", CharSet = CharSet.Auto, ExactSpelling = true)] - public static extern IntPtr WindowFromPoint(Point point); + private static extern void SetCursorPos(int x, int y); [DllImport("user32.dll")] - static extern void SetCursorPos(int x, int y); + private static extern IntPtr WindowFromPoint(Point point); [DllImport("user32.dll")] - static extern bool GetCursorPos(out Point point); + private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); private static IntPtr CreateLParam(int LoWord, int HiWord) { return (IntPtr)((HiWord << 16) | (LoWord & 0xffff)); } - internal void GameStart() - { + internal void Activate() + { if (!hookExist) { m_GlobalHook.MouseDownExt += GlobalHookMouseDownExt; @@ -46,9 +43,13 @@ internal void GameStart() } } - internal void GameEnd() + internal void Deactivate() { - Disable(); + if (hookExist) + { + m_GlobalHook.MouseDownExt -= GlobalHookMouseDownExt; + hookExist = false; + } } private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e) @@ -64,11 +65,10 @@ private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e) var handle = WindowFromPoint(new Point(x, y)); var lparam = CreateLParam(dx, dy); - GetCursorPos(out Point oripos); SetCursorPos(x + dx, y + dy); SendMessage(handle, WM_LBUTTONDOWN, IntPtr.Zero, lparam); SendMessage(handle, WM_LBUTTONUP, IntPtr.Zero, lparam); - SetCursorPos(oripos.X, oripos.Y); + SetCursorPos(e.X, e.Y); } else if (e.Button == MouseButtons.Middle) { @@ -79,22 +79,12 @@ private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e) var handle = WindowFromPoint(new Point(x, y)); var lparam = CreateLParam(dx, dy); - GetCursorPos(out Point oripos); SetCursorPos(x + dx, y + dy); SendMessage(handle, WM_LBUTTONDOWN, IntPtr.Zero, lparam); SendMessage(handle, WM_LBUTTONUP, IntPtr.Zero, lparam); - SetCursorPos(oripos.X, oripos.Y); + SetCursorPos(e.X, e.Y); } } } - - public void Disable() - { - if (hookExist) - { - m_GlobalHook.MouseDownExt -= GlobalHookMouseDownExt; - hookExist = false; - } - } - } + } } \ No newline at end of file diff --git a/HDT-BGhelper/BGhelperPlugin.cs b/HDT-BGhelper/BGhelperPlugin.cs index 3f9c6e7..c709d9d 100644 --- a/HDT-BGhelper/BGhelperPlugin.cs +++ b/HDT-BGhelper/BGhelperPlugin.cs @@ -4,59 +4,59 @@ namespace HDT_BGhelper { - public class BGhelperPlugin : IPlugin - { - private BGhelper helper; + public class BGhelperPlugin : IPlugin + { + private BGhelper helper; public string Author - { - get { return "IBM5100"; } - } + { + get { return "IBM5100"; } + } - public string ButtonText - { - get { return "No Settings"; } - } + public string ButtonText + { + get { return "No Settings"; } + } - public string Description - { - get { return "A battleground plugin makes shortcuts for refresh and freeze.\n" + - "Right click = refresh, middle click = freeze"; } - } + public string Description + { + get { return "A battleground plugin makes shortcuts for refresh and freeze.\n" + + "Right click = refresh, middle click = freeze"; } + } - public System.Windows.Controls.MenuItem MenuItem - { - get { return null; } - } + public System.Windows.Controls.MenuItem MenuItem + { + get { return null; } + } - public string Name - { - get { return "HDT-BGhelper"; } - } + public string Name + { + get { return "HDT-BGhelper"; } + } - public void OnButtonPress() - { + public void OnButtonPress() + { } public void OnLoad() - { - helper = new BGhelper(); - GameEvents.OnGameStart.Add(helper.GameStart); - GameEvents.OnGameEnd.Add(helper.GameEnd); + { + helper = new BGhelper(); + GameEvents.OnGameStart.Add(helper.Activate); + GameEvents.OnInMenu.Add(helper.Deactivate); } public void OnUnload() - { - helper.Disable(); + { + helper.Deactivate(); } - public void OnUpdate() - { + public void OnUpdate() + { } - public Version Version - { - get { return new Version(1, 2); } - } - } + public Version Version + { + get { return new Version(1, 3); } + } + } } \ No newline at end of file diff --git a/HDT-BGhelper/Properties/AssemblyInfo.cs b/HDT-BGhelper/Properties/AssemblyInfo.cs index fa58596..aa0d6a2 100644 --- a/HDT-BGhelper/Properties/AssemblyInfo.cs +++ b/HDT-BGhelper/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -32,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2")] -[assembly: AssemblyFileVersion("1.2")] +[assembly: AssemblyVersion("1.3")] +[assembly: AssemblyFileVersion("1.3")]