-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
352 lines (316 loc) · 13.6 KB
/
Form1.cs
File metadata and controls
352 lines (316 loc) · 13.6 KB
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Windows.Forms;
using System.Text;
namespace F_Tool
{
public class Form1 : Form
{
private Dictionary<UserControl1, int> timers = new Dictionary<UserControl1, int>();
private int windowHandle;
private Form1.States state = Form1.States.STOPPED;
private IContainer components = (IContainer)null;
internal Label Label5;
internal ComboBox ComboBoxWindows;
internal Label Label3;
internal TextBox TextBoxHwnd;
private Button button1;
private Panel panel1;
internal Button ButtonGetActive;
private Button button2;
private Timer timer1;
private static Dictionary<IntPtr, string> Windows = new Dictionary<IntPtr, string>();
private Form1.CallBackPtr callBackPtr;
private ListBox cmbWindowNames;
[DllImport("user32.dll")]
private static extern int EnumWindows(Form1.CallBackPtr callPtr, int lPar);
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
private static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int PostMessage(IntPtr hWnd, int Msg, uint wParam, int lParam);
public Form1() => this.InitializeComponent();
private void getWindowsList(object sender, EventArgs e)
{
this.ComboBoxWindows.Items.Clear();
this.windowHandle = 0;
TextBoxHwnd_KeyUp(null, null);
foreach (Object item in cmbWindowNames.Items)
{
//Console.WriteLine("getWindowsList: " + item.ToString());
ComboBoxWindows.Items.Add(item);
}
}
private void RefreshWindowsList()
{
Form1.Windows.Clear();
this.callBackPtr = new Form1.CallBackPtr(Form1.Report);
Form1.EnumWindows(this.callBackPtr, 0);
}
private void button1_Click(object sender, EventArgs e)
{
if (this.state == Form1.States.STOPPED)
{
UserControl1 key = new UserControl1();
this.panel1.Height += key.Height;
this.Height += key.Height;
key.Dock = DockStyle.Top;
this.panel1.Controls.Add((Control)key);
this.timers.Add(key, 0);
}
}
private void panel1_ControlRemoved(object sender, ControlEventArgs e)
{
this.panel1.Height -= e.Control.Height;
this.Height -= e.Control.Height;
this.timers.Remove((UserControl1)e.Control);
}
private void Form1_Load(object sender, EventArgs e)
{
if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))
return;
int num = (int)MessageBox.Show("Please Run with Admin privilege!");
Application.Exit();
}
private void timer1_Tick(object sender, EventArgs e)
{
foreach (KeyValuePair<UserControl1, int> pair in this.timers.ToList<KeyValuePair<UserControl1, int>>())
{
if (pair.Value <= 0)
{
this.pressKEy(pair);
this.timers[pair.Key] = pair.Key.getInterval();
}
else
{
Dictionary<UserControl1, int> timers;
UserControl1 key;
(timers = this.timers)[key = pair.Key] = timers[key] - 1;
}
}
}
private void pressKEy(KeyValuePair<UserControl1, int> pair)
{
Form1.PostMessage((IntPtr)this.windowHandle, 0x100, (uint)pair.Key.getKey(), 0);
Form1.PostMessage((IntPtr)this.windowHandle, 0x101, (uint)pair.Key.getKey(), 0);
}
private void button2_Click(object sender, EventArgs e)
{
if (this.state == Form1.States.STOPPED)
{
if (this.windowHandle == 0 || this.ComboBoxWindows.Text == "")
{
int num = (int)MessageBox.Show("Please make sure to choose a window before!");
}
else
{
foreach (UserControl1 key in this.timers.Keys.ToList<UserControl1>())
{
if (!key.isready())
return;
this.timers[key] = 0;
}
this.timer1.Start();
this.button2.Text = "Stop";
this.state = Form1.States.STARTED;
}
}
else
{
this.timer1.Stop();
this.button2.Text = "Start";
this.state = Form1.States.STOPPED;
}
}
private void ComboBoxWindows_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ComboBoxWindows.SelectedItem == null || this.ComboBoxWindows.Text == "")
{
int num = (int)MessageBox.Show("Please choose a window!");
}
WindowListItem item = (WindowListItem)this.ComboBoxWindows.SelectedItem;
//Console.WriteLine("SelectedItem: " + item.GetHwnd());
this.windowHandle = (int)item.GetHwnd();
}
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private void ButtonGetActive_Click_1(object sender, EventArgs e)
{
try
{
Form1.SetForegroundWindow(new IntPtr(this.windowHandle));
}
catch
{
int num = (int)MessageBox.Show("Window does not exist!");
}
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.cmbWindowNames = new System.Windows.Forms.ListBox();
this.Label5 = new System.Windows.Forms.Label();
this.ComboBoxWindows = new System.Windows.Forms.ComboBox();
this.Label3 = new System.Windows.Forms.Label();
this.TextBoxHwnd = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.ButtonGetActive = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// cmbWindowNames
//
this.cmbWindowNames.Location = new System.Drawing.Point(0, 0);
this.cmbWindowNames.Name = "cmbWindowNames";
this.cmbWindowNames.Size = new System.Drawing.Size(120, 96);
this.cmbWindowNames.TabIndex = 0;
//
// Label5
//
this.Label5.AutoSize = true;
this.Label5.Location = new System.Drawing.Point(5, 49);
this.Label5.Name = "Label5";
this.Label5.Size = new System.Drawing.Size(37, 13);
this.Label5.TabIndex = 33;
this.Label5.Text = "Select";
//
// ComboBoxWindows
//
this.ComboBoxWindows.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ComboBoxWindows.FormattingEnabled = true;
this.ComboBoxWindows.Location = new System.Drawing.Point(46, 44);
this.ComboBoxWindows.Name = "ComboBoxWindows";
this.ComboBoxWindows.Size = new System.Drawing.Size(178, 21);
this.ComboBoxWindows.TabIndex = 31;
this.ComboBoxWindows.SelectedIndexChanged += new System.EventHandler(this.ComboBoxWindows_SelectedIndexChanged);
this.ComboBoxWindows.Click += new System.EventHandler(this.getWindowsList);
//
// Label3
//
this.Label3.AllowDrop = true;
this.Label3.AutoSize = true;
this.Label3.Location = new System.Drawing.Point(5, 15);
this.Label3.Name = "Label3";
this.Label3.Size = new System.Drawing.Size(29, 13);
this.Label3.TabIndex = 32;
this.Label3.Text = "Filter";
//
// TextBoxHwnd
//
this.TextBoxHwnd.Location = new System.Drawing.Point(50, 12);
this.TextBoxHwnd.Name = "TextBoxHwnd";
this.TextBoxHwnd.Size = new System.Drawing.Size(245, 20);
this.TextBoxHwnd.TabIndex = 34;
this.TextBoxHwnd.Text = "Flyff Universe";
this.TextBoxHwnd.KeyUp += new System.Windows.Forms.KeyEventHandler(this.TextBoxHwnd_KeyUp);
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.button1.Location = new System.Drawing.Point(0, 90);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(307, 23);
this.button1.TabIndex = 35;
this.button1.Text = "Add";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(38, 74);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(223, 10);
this.panel1.TabIndex = 36;
this.panel1.ControlRemoved += new System.Windows.Forms.ControlEventHandler(this.panel1_ControlRemoved);
//
// ButtonGetActive
//
this.ButtonGetActive.Location = new System.Drawing.Point(229, 44);
this.ButtonGetActive.Name = "ButtonGetActive";
this.ButtonGetActive.Size = new System.Drawing.Size(67, 21);
this.ButtonGetActive.TabIndex = 37;
this.ButtonGetActive.Text = "Switch to";
this.ButtonGetActive.UseVisualStyleBackColor = true;
this.ButtonGetActive.Click += new System.EventHandler(this.ButtonGetActive_Click_1);
//
// button2
//
this.button2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.button2.Location = new System.Drawing.Point(0, 113);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(307, 23);
this.button2.TabIndex = 38;
this.button2.Text = "Start";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(307, 136);
this.Controls.Add(this.button1);
this.Controls.Add(this.button2);
this.Controls.Add(this.ButtonGetActive);
this.Controls.Add(this.Label5);
this.Controls.Add(this.ComboBoxWindows);
this.Controls.Add(this.Label3);
this.Controls.Add(this.TextBoxHwnd);
this.Controls.Add(this.panel1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Flyff-Tool";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
private enum States
{
STARTED,
STOPPED,
}
public delegate bool CallBackPtr(int hwnd, int lParam);
public static bool Report(int hWnd, int lParam)
{
StringBuilder lpString = new StringBuilder(Form1.GetWindowTextLength((IntPtr)hWnd) + 1);
Form1.GetWindowText((IntPtr)hWnd, lpString, lpString.Capacity);
string str = lpString.ToString();
Form1.Windows.Add((IntPtr)hWnd, str);
return true;
}
private void TextBoxHwnd_KeyUp(object sender, KeyEventArgs e)
{
this.RefreshWindowsList();
this.cmbWindowNames.Items.Clear();
if (this.TextBoxHwnd.Text.Length <= 0)
return;
foreach (KeyValuePair<IntPtr, string> keyValuePair in Form1.Windows.Where<KeyValuePair<IntPtr, string>>((Func<KeyValuePair<IntPtr, string>, bool>)(kp => kp.Value.StartsWith(this.TextBoxHwnd.Text.Trim(), StringComparison.InvariantCultureIgnoreCase))))
this.cmbWindowNames.Items.Add((object)new WindowListItem()
{
HWnd = keyValuePair.Key,
WindowName = keyValuePair.Value
});
}
}
}