-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
300 lines (247 loc) · 11 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using Interceptor;
namespace AzlBot
{
public delegate bool EnumDelegate(IntPtr hWnd, int lParam);
class Program
{
[DllImportAttribute("User32.dll")]
private static extern IntPtr FindWindow(String ClassName, String WindowName);
[DllImportAttribute("User32.dll")]
private static extern IntPtr SetForegroundWindow(IntPtr hWnd);
//static extern bool GetCursorPos(out uint lpPoint);
[DllImport("user32.dll")]
static extern bool EnumDelegate(IntPtr hDesktop, EnumDelegate lpfn, IntPtr lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "GetWindowText",
ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);
static int ctr = 0;
private static string _method { get; set; }
private static int _minute { get; set; }
#region callback
static void callback(object state)
{
Input input = new Input();
//Timer timer = new Timer(callback, "Run buff", TimeSpan.FromSeconds(320), TimeSpan.FromSeconds(320));
input.KeyboardFilterMode = KeyboardFilterMode.All;
input.Load();
var collection = new List<string>();
EnumDelegate filter = delegate (IntPtr hWnd, int lParam)
{
StringBuilder strbTitle = new StringBuilder(255);
int nLength = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
string strTitle = strbTitle.ToString();
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
{
collection.Add(strTitle);
}
return true;
};
if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
{
foreach (var item in collection)
{
if (item == "RF Online") //"RF Online"
{
Console.WriteLine("passing by");
IntPtr RFOnlineHandle = FindWindow(null, item);
if (RFOnlineHandle != IntPtr.Zero)
{
SetForegroundWindow(RFOnlineHandle);
input.KeyPressDelay = 1;
input.SendKeys(Keys.Nine);
input.Unload();
}
else
{
Console.WriteLine("Rf not running");
}
// Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
}
}
}
//input.Unload();
Console.WriteLine("Ticked at {0:HH:mm:ss.fff}", DateTime.Now);
Console.WriteLine("Called back with state = " + state + ctr++);
}
#endregion
static void Main(string[] args)
{
_method = args[0].ToString();
if (args.Count() == 1)
{
_minute = 0;
}
else
{
_minute = int.Parse(args[1].ToString());
}
//this will convert hours to minutes.
_minute = _minute * 60;
if (_method == string.Empty)
{
Console.WriteLine("No argument found");
return;
}
//if (_minute <= 0)
//{
// Console.WriteLine("Cannot set a zero minute");
// return;
//}
switch (_method)
{
case "-buff":
AutoBuff();
break;
case "-farm":
Farming();
break;
case "-help":
GetHelp();
break;
default:
Console.WriteLine("wrong argument, type -help for more information ");
break;
}
// Console.WriteLine("Ticked at {0:HH:mm:ss.fff}", DateTime.UtcNow.ToLocalTime());
}
private static void GetHelp()
{
Console.WriteLine("Displaying Help information");
Console.WriteLine("Format argument : AzlBOt.exe -method NoofHour");
Console.WriteLine("method [-farm] [-buff] hour/minute");
Console.WriteLine("For minutes use decimal .50 for 30minutes");
}
internal static void AutoBuff()
{
Console.WriteLine("Starting timer.");
Input input = new Input();
var starttime = DateTime.UtcNow;
Console.WriteLine("Execution starts @ " + starttime.ToLocalTime());
//Timer timer = new Timer(callback, "Run buff", TimeSpan.FromSeconds(320), TimeSpan.FromSeconds(320));
input.KeyboardFilterMode = KeyboardFilterMode.All;
input.Load();
var collection = new List<string>();
EnumDelegate filter = delegate (IntPtr hWnd, int lParam)
{
StringBuilder strbTitle = new StringBuilder(255);
int nLength = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
string strTitle = strbTitle.ToString();
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
{
collection.Add(strTitle);
}
return true;
};
if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
{
foreach (var item in collection)
{
if (item == "RF Online") //"RF Online"
{
Console.WriteLine("Do some push ups and coffee. This will take a while.");
IntPtr RFOnlineHandle = FindWindow(null, item);
if (RFOnlineHandle != IntPtr.Zero)
{
int ctr = 0;
//input.MoveMouseBy(730, 342,true); //x,y
//Console.WriteLine("x: " + System.Windows.Forms.Cursor.Position.X + " y: " + System.Windows.Forms.Cursor.Position.Y);
//input.SendLeftClick();
while (DateTime.UtcNow.ToLocalTime() - starttime.ToLocalTime() < TimeSpan.FromMinutes(_minute)) //14400000 ms
{
SetForegroundWindow(RFOnlineHandle);
input.KeyPressDelay = 20;
input.SendKey(Keys.Nine, KeyState.Down);
Thread.Sleep(1);
input.SendKey(Keys.Nine, KeyState.Up);
//Console.WriteLine(ctr);
Thread.Sleep(10000);
ctr++;
}
}
else
{
Console.WriteLine("Rf not running");
}
// Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
}
}
//}
input.Unload();
Thread.Sleep(2000);
Console.WriteLine("Ticked at {0:HH:mm:ss.fff}", DateTime.UtcNow.ToLocalTime());
}
}
internal static void Farming()
{
Console.WriteLine("Starting timer.");
Input input = new Input();
var starttime = DateTime.UtcNow;
//Timer timer = new Timer(callback, "Run buff", TimeSpan.FromSeconds(320), TimeSpan.FromSeconds(320));
input.KeyboardFilterMode = KeyboardFilterMode.All;
input.Load();
var collection = new List<string>();
EnumDelegate filter = delegate (IntPtr hWnd, int lParam)
{
StringBuilder strbTitle = new StringBuilder(255);
int nLength = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
string strTitle = strbTitle.ToString();
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
{
collection.Add(strTitle);
}
return true;
};
if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
{
foreach (var item in collection)
{
if (item == "RF Online") //"RF Online"
{
Console.WriteLine("Do some push ups and coffee. This will take a while.");
IntPtr RFOnlineHandle = FindWindow(null, item);
if (RFOnlineHandle != IntPtr.Zero)
{
int ctr = 0;
while (DateTime.UtcNow.ToLocalTime() - starttime.ToLocalTime() < TimeSpan.FromMinutes(_minute))
{
SetForegroundWindow(RFOnlineHandle);
input.KeyPressDelay = 20;
input.SendKey(Keys.Space, KeyState.Down);
Thread.Sleep(1);
input.SendKey(Keys.Space, KeyState.Up);
Thread.Sleep(1); // addtional only for looting
Console.WriteLine(ctr);
Thread.Sleep(1000);
ctr++;
}
}
else
{
Console.WriteLine("Rf not running");
}
// Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id);
}
}
//}
input.Unload();
Thread.Sleep(20000);
Console.WriteLine("Ticked at {0:HH:mm:ss.fff}", DateTime.Now);
}
}
//Console.Write(pts.ToString());
}
}