Skip to content

Commit a058bb6

Browse files
Merge pull request #110 from daniel-widrick/issue-#91
Issue #91
2 parents 7ef5384 + aa54676 commit a058bb6

File tree

8 files changed

+137
-40
lines changed

8 files changed

+137
-40
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ node_modules/
163163
Generated_Code/
164164

165165
# Backup & report files from converting an old project file
166+
167+
# VS 2017 express files
168+
.vs/
166169
# to a newer Visual Studio version. Backup files are not needed,
167170
# because we have git ;-)
168171
_UpgradeReport_Files/

UltimateFishBot/Classes/BodyParts/Eyes.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ class Eyes
1616
int yPosMax;
1717
Rectangle wowRectangle;
1818
private Win32.CursorInfo m_noFishCursor;
19+
private IntPtr Wow;
20+
21+
public Eyes(IntPtr wowWindow)
22+
{
23+
this.Wow = wowWindow;
24+
}
1925

2026
public async Task<bool> LookForBobber(CancellationToken cancellationToken)
2127
{
22-
m_noFishCursor = Win32.GetNoFishCursor();
23-
wowRectangle = Win32.GetWowRectangle();
28+
m_noFishCursor = Win32.GetNoFishCursor(this.Wow);
29+
wowRectangle = Win32.GetWowRectangle(this.Wow);
2430

2531
if (!Properties.Settings.Default.customScanArea)
2632
{

UltimateFishBot/Classes/BodyParts/Hands.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading;
1+
using System;
2+
using System.Threading;
23
using System.Threading.Tasks;
34
using System.Windows.Forms;
45
using UltimateFishBot.Classes.Helpers;
@@ -10,13 +11,21 @@ class Hands
1011
private Cursor m_cursor;
1112
private int m_baitIndex;
1213
private string[] m_baitKeys;
14+
private IntPtr Wow;
1315

1416
public Hands()
1517
{
1618
m_baitIndex = 0;
1719
m_cursor = new Cursor(Cursor.Current.Handle);
1820
UpdateKeys();
1921
}
22+
public Hands(IntPtr wowWindow)
23+
{
24+
this.Wow = wowWindow;
25+
m_baitIndex = 0;
26+
m_cursor = new Cursor(Cursor.Current.Handle);
27+
UpdateKeys();
28+
}
2029

2130
public void UpdateKeys()
2231
{
@@ -34,8 +43,15 @@ public void UpdateKeys()
3443

3544
public async Task Cast(CancellationToken token)
3645
{
37-
Win32.ActivateWow();
38-
Win32.SendKey(Properties.Settings.Default.FishKey);
46+
Win32.ActivateWow(this.Wow);
47+
if (Properties.Settings.Default.RightClickCast)
48+
{
49+
Win32.SendMouseDblRightClick(this.Wow);
50+
}
51+
else
52+
{
53+
Win32.SendKey(Properties.Settings.Default.FishKey);
54+
}
3955
await Task.Delay(Properties.Settings.Default.CastingDelay, token);
4056
}
4157

@@ -106,7 +122,7 @@ public async Task DoAction(Manager.NeededAction action, Mouth mouth, Cancellatio
106122
return;
107123
}
108124

109-
Win32.ActivateWow();
125+
Win32.ActivateWow(this.Wow);
110126
Win32.SendKey(actionKey);
111127
await Task.Delay(sleepTime * 1000, cancellationToken);
112128
}

UltimateFishBot/Classes/Helpers/Win32.cs

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public enum keyState
4040
EXTENDEDKEY = 1,
4141
KEYUP = 2
4242
};
43+
private enum ShowWindowEnum
44+
{
45+
Hide = 0,
46+
ShowNormal = 1, ShowMinimized = 2, ShowMaximized = 3,
47+
Maximize = 3, ShowNormalNoActivate = 4, Show = 5,
48+
Minimize = 6, ShowMinNoActivate = 7, ShowNoActivate = 8,
49+
Restore = 9, ShowDefault = 10, ForceMinimized = 11
50+
};
4351

4452
[DllImport("user32.dll", EntryPoint = "FindWindow")]
4553
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
@@ -71,15 +79,20 @@ public enum keyState
7179
[DllImport("user32.dll")]
7280
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
7381

82+
[DllImport("user32.dll")]
83+
private static extern bool IsIconic(IntPtr hWnd);
84+
85+
[DllImport("user32.dll")]
86+
static extern bool ShowWindow(IntPtr hWnd, ShowWindowEnum flags);
87+
7488
private const uint WM_LBUTTONDOWN = 513;
7589
private const uint WM_LBUTTONUP = 514;
7690

7791
private const uint WM_RBUTTONDOWN = 516;
7892
private const uint WM_RBUTTONUP = 517;
7993

80-
public static Rectangle GetWowRectangle()
94+
public static Rectangle GetWowRectangle(IntPtr Wow)
8195
{
82-
IntPtr Wow = FindWindow("GxWindowClass", "World Of Warcraft");
8396
Rect Win32ApiRect = new Rect();
8497
GetWindowRect(Wow, ref Win32ApiRect);
8598
Rectangle myRect = new Rectangle();
@@ -90,6 +103,19 @@ public static Rectangle GetWowRectangle()
90103
return myRect;
91104
}
92105

106+
public static IntPtr FindWowWindow()
107+
{
108+
Process[] processlist = Process.GetProcesses();
109+
foreach(Process process in processlist)
110+
{
111+
if(process.MainWindowTitle.ToUpper().Equals("WORLD OF WARCRAFT"))
112+
{
113+
return process.MainWindowHandle;
114+
}
115+
}
116+
return new IntPtr();
117+
}
118+
93119
public static Bitmap GetCursorIcon(CursorInfo actualCursor, int width = 35, int height = 35)
94120
{
95121
Bitmap actualCursorIcon = null;
@@ -106,20 +132,19 @@ public static Bitmap GetCursorIcon(CursorInfo actualCursor, int width = 35, int
106132
return actualCursorIcon;
107133
}
108134

109-
static public void ActivateWow()
135+
static public void ActivateWow(IntPtr Wow)
110136
{
111-
ActivateApp(Properties.Settings.Default.ProcName);
112-
ActivateApp(Properties.Settings.Default.ProcName + "-64");
113-
ActivateApp("World Of Warcraft");
137+
ActivateApp(Wow);
114138
}
115139

116-
static public void ActivateApp(string processName)
140+
public static void ActivateApp(IntPtr Wow)
117141
{
118-
Process[] p = Process.GetProcessesByName(processName);
119-
120-
// Activate the first application we find with this name
121-
if (p.Count() > 0)
122-
SetForegroundWindow(p[0].MainWindowHandle);
142+
SetForegroundWindow(Wow);
143+
//AllowSetForegroundWindow(Process.GetCurrentProcess().Id);
144+
if (IsIconic(Wow))
145+
{
146+
ShowWindow(Wow, ShowWindowEnum.Restore);
147+
}
123148
}
124149

125150
public static void MoveMouse(int x, int y)
@@ -131,9 +156,9 @@ public static void MoveMouse(int x, int y)
131156
}
132157
}
133158

134-
public static CursorInfo GetNoFishCursor()
159+
public static CursorInfo GetNoFishCursor(IntPtr Wow)
135160
{
136-
Rectangle WoWRect = Win32.GetWowRectangle();
161+
Rectangle WoWRect = Win32.GetWowRectangle(Wow);
137162
Win32.MoveMouse((WoWRect.X + 10), (WoWRect.Y + 45));
138163
LastRectX = WoWRect.X;
139164
LastRectY = WoWRect.Y;
@@ -167,7 +192,7 @@ public static void SendKey(string sKeys)
167192

168193
public static void SendMouseClick()
169194
{
170-
IntPtr Wow = FindWindow("GxWindowClass", "World Of Warcraft");
195+
IntPtr Wow = FindWowWindow();
171196
long dWord = MakeDWord((LastX - LastRectX), (LastY - LastRectY));
172197

173198
if (Properties.Settings.Default.ShiftLoot)
@@ -181,6 +206,34 @@ public static void SendMouseClick()
181206
SendKeyboardAction(16, keyState.KEYUP);
182207
}
183208

209+
public static void SendMouseClick(IntPtr Wow)
210+
{
211+
long dWord = MakeDWord((LastX - LastRectX), (LastY - LastRectY));
212+
213+
if (Properties.Settings.Default.ShiftLoot)
214+
SendKeyboardAction(16, keyState.KEYDOWN);
215+
216+
SendNotifyMessage(Wow, WM_RBUTTONDOWN, (UIntPtr)1, (IntPtr)dWord);
217+
Thread.Sleep(100);
218+
SendNotifyMessage(Wow, WM_RBUTTONUP, (UIntPtr)1, (IntPtr)dWord);
219+
220+
if (Properties.Settings.Default.ShiftLoot)
221+
SendKeyboardAction(16, keyState.KEYUP);
222+
}
223+
public static void SendMouseDblRightClick(IntPtr Wow)
224+
{
225+
//long dWord = MakeDWord((LastX - LastRectX), (LastY - LastRectY));
226+
Rectangle wowRect = Win32.GetWowRectangle(Wow);
227+
long dWord = MakeDWord( (wowRect.Width/2), (wowRect.Height/2) );
228+
SendNotifyMessage(Wow, WM_RBUTTONDOWN, (UIntPtr)1, (IntPtr)dWord);
229+
Thread.Sleep(100);
230+
SendNotifyMessage(Wow, WM_RBUTTONUP, (UIntPtr)1, (IntPtr)dWord);
231+
Thread.Sleep(100);
232+
SendNotifyMessage(Wow, WM_RBUTTONDOWN, (UIntPtr)1, (IntPtr)dWord);
233+
Thread.Sleep(100);
234+
SendNotifyMessage(Wow, WM_RBUTTONUP, (UIntPtr)1, (IntPtr)dWord);
235+
}
236+
184237
public static bool SendKeyboardAction(Keys key, keyState state)
185238
{
186239
return SendKeyboardAction((byte)key.GetHashCode(), state);
@@ -196,10 +249,10 @@ private static long MakeDWord(int LoWord, int HiWord)
196249
return (HiWord << 16) | (LoWord & 0xFFFF);
197250
}
198251

199-
static private int LastRectX;
200-
static private int LastRectY;
252+
private static int LastRectX;
253+
private static int LastRectY;
201254

202-
static private int LastX;
203-
static private int LastY;
255+
private static int LastX;
256+
private static int LastY;
204257
}
205258
}

UltimateFishBot/Classes/Manager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ public enum NeededAction
5959
private const int SECOND = 1000;
6060
private const int MINUTE = 60 * SECOND;
6161

62+
private IntPtr WowWindowPointer;
63+
6264
public Manager(IManagerEventHandler managerEventHandler, IProgress<string> progressHandle)
6365
{
6466
m_managerEventHandler = managerEventHandler;
67+
this.WowWindowPointer = Helpers.Win32.FindWowWindow();
6568

66-
m_eyes = new Eyes();
67-
m_hands = new Hands();
69+
m_eyes = new Eyes(this.WowWindowPointer);
70+
m_hands = new Hands(this.WowWindowPointer);
6871
m_ears = new Ears();
6972
m_mouth = new Mouth(progressHandle);
7073
m_legs = new Legs();

UltimateFishBot/Forms/frmSettings.Designer.cs

Lines changed: 25 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UltimateFishBot/Forms/frmSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private void buttonSave_Click(object sender, EventArgs e)
251251
Properties.Settings.Default.AutoLure = cbAutoLure.Checked;
252252
Properties.Settings.Default.SwapGear = cbHearth.Checked;
253253
Properties.Settings.Default.UseAltKey = cbAlt.Checked;
254+
Properties.Settings.Default.RightClickCast = cbDblRclickCast.Checked;
254255

255256
Properties.Settings.Default.FishKey = txtFishKey.Text;
256257
Properties.Settings.Default.LureKey = txtLureKey.Text;
@@ -450,5 +451,6 @@ private void btnReset_Click(object sender, EventArgs e)
450451
}
451452
}
452453

454+
453455
}
454456
}

UltimateFishBot/Properties/Settings.Designer.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)