Repository navigation
Expand file tree
/
Copy pathWindow1.xaml.cs
More file actions
445 lines (322 loc) · 10.2 KB
/
Copy pathWindow1.xaml.cs
File metadata and controls
445 lines (322 loc) · 10.2 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
using System;
using System.Windows;
using System.Windows.Documents;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Interop;
using System.IO;
//using System.Collections.Generic;
namespace eflayMH_WPF
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
this.notifyIcon = new NotifyIcon();
this.notifyIcon.BalloonTipText = "最小化到托盘";
this.notifyIcon.Text = "eflayMH";
this.notifyIcon.Icon = Resource.lvdou;//new System.Drawing.Icon("NotifyIcon.ico");
//this.notifyIcon.Visible = true;
notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;
ContextMenuStrip cmc = new ContextMenuStrip();
System.Windows.Forms.ToolStripMenuItem ExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
System.Windows.Forms.ToolStripMenuItem 显示主界面ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
cmc.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
显示主界面ToolStripMenuItem,ExitToolStripMenuItem
});
ExitToolStripMenuItem.Name = "ExitToolStripMenuItem";
ExitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
ExitToolStripMenuItem.Text = "退出";
ExitToolStripMenuItem.Click += new EventHandler(ExitToolStripMenuItem_Click);
//
// 显示主界面ToolStripMenuItem
//
显示主界面ToolStripMenuItem.Name = "显示主界面ToolStripMenuItem";
显示主界面ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
显示主界面ToolStripMenuItem.Text = "显示主界面";
显示主界面ToolStripMenuItem.Click += OnNotifyIconDoubleClick;
notifyIcon.ContextMenuStrip = cmc;
this.notifyIcon.ShowBalloonTip(1000);
richTextBox1.Document.AddHandler(Hyperlink.ClickEvent, new RoutedEventHandler(HandleHyperlinkClick));
string skinDictPath = @".\Resources\Skins\Skin1.xaml";
Uri skinDictUri = new Uri(skinDictPath, UriKind.Relative);
// Tell the Application to load the skin resources.
App app = System.Windows.Application.Current as App;
app.ApplySkin(skinDictUri);
this.checkBoxxsdw.Checked += delegate(object sender,RoutedEventArgs e)
{
checkBoxbxdw.IsChecked = false;
};
this.checkBoxbxdw.Checked += delegate(object sender,RoutedEventArgs e)
{
checkBoxxsdw.IsChecked = false;
checkBoxswdx.IsChecked = false;
checkBoxxssf.IsChecked = false;
};
//this.Title = "MH from Breeze356.5d6d.com";
//new Thread((ThreadStart)delegate(){Thread.Sleep(60000*5);this.Dispatcher.Invoke((MethodInvoker)delegate(){this.Title = "";});}).Start();
}
void ExitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.notifyIcon.Visible = false;
this.Close();
}
NotifyIcon notifyIcon;
private void OnNotifyIconDoubleClick(object sender, EventArgs e)
{
this.Show();
this.notifyIcon.Visible = false;
this.Activate();
this.WindowState = WindowState.Normal;
this.Topmost = true;
this.Topmost = false;
}
private void Window_StateChanged(object sender, EventArgs e)
{
if (this.WindowState == WindowState.Minimized)
{
Hide();
this.notifyIcon.Visible = true;
}
}
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, System.Windows.Forms.Keys vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
/// <summary>
/// RichTextBox中的链接被点击时触发
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void HandleHyperlinkClick(object sender, RoutedEventArgs args)
{
Hyperlink link = args.Source as Hyperlink;
//...
Process.Start(link.NavigateUri.ToString());
}
private static ProcessC war3;
//public delegate void findwar3delegate();
//findwar3delegate find = null;
string ProcessVersion;
/// <summary>
/// 表示是否手动关闭,同时表示:MH自动开启时为false,手动开启时为true
/// </summary>
bool forceOff = true;
public enum KeyModifiers
{ None = 0, Alt = 1, Ctrl = 2, Shift = 4, Windows = 8 }
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Process.EnterDebugMode();
Thread war3mhtd = new Thread(new ThreadStart(war3mh));
war3mhtd.IsBackground = true;
war3mhtd.Start();
//Dispatcher.BeginInvoke(find, null);
LoadConfig();
}
/// <summary>
/// 处理消息
/// </summary>
/// <param name="hwnd"></param>
/// <param name="msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <param name="handle"></param>
/// <returns></returns>
IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handle)
{
switch (msg)
{
case 0x312:
switch (wParam.ToInt32())
{
case 101:
buttonON_Click(buttonON, new RoutedEventArgs());
//此处填写快捷键响应代码
break;
case 102:
buttonOFF_Click(buttonOFF, new RoutedEventArgs());
break;
default:
break;
}
break;
}
return IntPtr.Zero;
}
bool isMHON = false;
//private void foundwar3proc(IAsyncResult e)
//{
// find.EndInvoke(e);
//}
/// <summary>
/// 找到魔兽进程进行初始化
/// </summary>
/// <returns></returns>
private bool findwar3process()
{
Process[] war3p = Process.GetProcessesByName("war3");
if (war3p != null && war3p.Length >= 1)
{
if (war3!=null&&war3.Pid == war3p[0].Id)
{
return true;
}
war3 = new ProcessC(war3p[0]);
war3.pname.Exited += new EventHandler(war3_pname_Exited);
//只在第一次见到魔兽时触发
if (war3start_event != null)
war3start_event(war3);
//没找到game.dll的话默认值
war3.DllBaseAddress = 0x6F000000;
foreach (Module md in war3.Modules)
{
string filename = Path.GetFileName(md.FullName).ToLower();
if (filename == "game.dll" || filename == "game124.dll")//||filename.Contains("game")
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(md.FullName);
try
{
//if (fvi.OriginalFilename.ToLower() == "game.dll")
//{
war3.DllBaseAddress = md.BaseAddress;
war3.Version = fvi.FileVersion.Replace(", ", ".");
//}
}
catch (NullReferenceException)
{ }
Dispatcher.Invoke((ThreadStart)(delegate() { textBlock1.Text = "魔兽已启动,PID:" + war3.Pid + ",版本:" + war3.Version; }), null);
return true;
}
}
Dispatcher.Invoke(new ThreadStart(delegate() { textBlock1.Text = "魔兽已启动,PID:" + war3.Pid + ",游戏还未加载完毕" ;}), null);
return false;
}
return false;
}
void war3_pname_Exited(object sender, EventArgs e)
{
//用此事件判断进程退出并不及时,不用也罢
Dispatcher.BeginInvoke(new ThreadStart(delegate() { textBlock1.Text = "魔兽已关闭"; }), null);
//
}
public delegate void war3runningdelegate(ProcessC war3);
public event war3runningdelegate war3start_event;
public event war3runningdelegate war3isrunning_event;
/// <summary>
/// 主功能线程循环
/// </summary>
private void war3mh()
{
while (true)
{
#if RELEASE
try
{
#endif
Thread.Sleep(2000);
//Thread.SpinWait(3000);
Process[] processes = Process.GetProcessesByName("war3");
if (processes != null && processes.Length > 0)//发现魔兽进程
{
if (war3 == null || war3.Pid != processes[0].Id)
{
Thread.Sleep(2000);
}
if (!findwar3process())
{
continue;
}
//每次见到魔兽都触发
if (war3isrunning_event != null)
war3isrunning_event(war3);
if (isMHON == false && forceOff == false)
{
lock (war3)
{
War3MHon(true);
}
}
SetWar3Windows();
}
else //没发现魔兽进程
{
Dispatcher.BeginInvoke(new ThreadStart(delegate() { textBlock1.Text = "魔兽未启动"; }), null);
isMHON = false;
//forceOff = false;
}
bool isdesjoyAA = false;
Dispatcher.Invoke((MethodInvoker)delegate
{ isdesjoyAA = CheckBoxDesjoyAA.IsChecked.Value; }
);
if (isdesjoyAA == true)
{
new Thread((ThreadStart)DesjoyAA).Start();
}
#if RELEASE
}
//catch (Exception)
//{
// //this.Dispatcher.Invoke((MethodInvoker)delegate
// //{
// // throw ex;
// //});
//}
catch
{ }
#endif
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
SaveConfig();
this.notifyIcon.Visible = false;
//Environment.Exit(0);
}
private void gotobreeze_Click(object sender, RoutedEventArgs e)
{
Process.Start("http://breeze356.5d6d.com/?fromuid=424");
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void checkBoxzdkq_Checked(object sender, RoutedEventArgs e)
{
forceOff = false;
}
private void checkBoxzdkq_Unchecked(object sender, RoutedEventArgs e)
{
forceOff = true;
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
//快捷键相关
IntPtr whandle = new System.Windows.Interop.WindowInteropHelper(this).Handle;
RegisterHotKey(whandle, 101, KeyModifiers.Ctrl | KeyModifiers.Alt, Keys.O);
RegisterHotKey(whandle, 102, KeyModifiers.Ctrl | KeyModifiers.Alt, Keys.P);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
//SetWindowLong(whandle, -16, 0);
}
private void checkBoxqzbb_Checked(object sender, RoutedEventArgs e)
{
ComboBoxVersion.IsEnabled = true;
}
private void checkBoxqzbb_Unchecked(object sender, RoutedEventArgs e)
{
ComboBoxVersion.IsEnabled = false;
}
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
this.DragMove();
}
} //end of public partial class Window1 : Window
}