2
0

ModWatcher.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading;
  10. using Microsoft.VisualBasic.CompilerServices;
  11. namespace PCL
  12. {
  13. // Token: 0x020000BA RID: 186
  14. [StandardModule]
  15. public sealed class ModWatcher
  16. {
  17. // Token: 0x0600058B RID: 1419 RVA: 0x0002F888 File Offset: 0x0002DA88
  18. private static void WatcherStateChanged()
  19. {
  20. bool flag = false;
  21. bool triggerLauncherShutdown = true;
  22. try
  23. {
  24. foreach (ModWatcher.Watcher watcher in ModWatcher.dicField)
  25. {
  26. if (watcher.State != ModWatcher.Watcher.MinecraftState.Loading)
  27. {
  28. if (watcher.State != ModWatcher.Watcher.MinecraftState.Running)
  29. {
  30. if (watcher.State == ModWatcher.Watcher.MinecraftState.Crashed || watcher.State == ModWatcher.Watcher.MinecraftState.Canceled)
  31. {
  32. triggerLauncherShutdown = false;
  33. continue;
  34. }
  35. continue;
  36. }
  37. }
  38. flag = true;
  39. break;
  40. }
  41. }
  42. finally
  43. {
  44. List<ModWatcher.Watcher>.Enumerator enumerator;
  45. ((IDisposable)enumerator).Dispose();
  46. }
  47. if (ModWatcher.m_HelperField != flag)
  48. {
  49. ModWatcher.m_HelperField = flag;
  50. if (ModWatcher.m_HelperField)
  51. {
  52. ModWatcher.MinecraftStart();
  53. return;
  54. }
  55. ModWatcher.MinecraftStop(triggerLauncherShutdown);
  56. }
  57. }
  58. // Token: 0x0600058C RID: 1420 RVA: 0x00004F2F File Offset: 0x0000312F
  59. private static void MinecraftStart()
  60. {
  61. ModLaunch.McLaunchLog("[全局] 出现运行中的 Minecraft");
  62. ModWatcher._IssuerField = true;
  63. ModMain._ProcessIterator.BtnExtraShutdown.ShowRefresh();
  64. }
  65. // Token: 0x0600058D RID: 1421 RVA: 0x0002F924 File Offset: 0x0002DB24
  66. private static void MinecraftStop(bool TriggerLauncherShutdown)
  67. {
  68. ModLaunch.McLaunchLog("[全局] 已无运行中的 Minecraft");
  69. ModWatcher._IssuerField = false;
  70. ModMain._ProcessIterator.BtnExtraShutdown.ShowRefresh();
  71. if (Conversions.ToBoolean(ModBase.m_IdentifierRepository.Get("UiMusicStop", null)))
  72. {
  73. ModBase.RunInUi((ModWatcher._Closure$__.$I6-0 == null) ? (ModWatcher._Closure$__.$I6-0 = delegate()
  74. {
  75. if (ModMusic.MusicResume())
  76. {
  77. ModBase.Log("[Music] 已根据设置,在结束后开始音乐播放", ModBase.LogLevel.Normal, "出现错误");
  78. }
  79. }) : ModWatcher._Closure$__.$I6-0, false);
  80. }
  81. else if (Conversions.ToBoolean(ModBase.m_IdentifierRepository.Get("UiMusicStart", null)))
  82. {
  83. ModBase.RunInUi((ModWatcher._Closure$__.$I6-1 == null) ? (ModWatcher._Closure$__.$I6-1 = delegate()
  84. {
  85. if (ModMusic.MusicPause())
  86. {
  87. ModBase.Log("[Music] 已根据设置,在结束后暂停音乐播放", ModBase.LogLevel.Normal, "出现错误");
  88. }
  89. }) : ModWatcher._Closure$__.$I6-1, false);
  90. }
  91. object left = ModBase.m_IdentifierRepository.Get("LaunchArgumentVisible", null);
  92. if (!Operators.ConditionalCompareObjectEqual(left, 2, false))
  93. {
  94. if (Operators.ConditionalCompareObjectEqual(left, 3, false))
  95. {
  96. ModBase.RunInUi((ModWatcher._Closure$__.$I6-4 == null) ? (ModWatcher._Closure$__.$I6-4 = delegate()
  97. {
  98. ModMain._ProcessIterator.Hidden = false;
  99. }) : ModWatcher._Closure$__.$I6-4, false);
  100. }
  101. return;
  102. }
  103. if (TriggerLauncherShutdown)
  104. {
  105. ModBase.RunInUi((ModWatcher._Closure$__.$I6-2 == null) ? (ModWatcher._Closure$__.$I6-2 = delegate()
  106. {
  107. ModMain._ProcessIterator.EndProgram(false);
  108. }) : ModWatcher._Closure$__.$I6-2, false);
  109. return;
  110. }
  111. ModBase.RunInUi((ModWatcher._Closure$__.$I6-3 == null) ? (ModWatcher._Closure$__.$I6-3 = delegate()
  112. {
  113. ModMain._ProcessIterator.Hidden = false;
  114. }) : ModWatcher._Closure$__.$I6-3, false);
  115. }
  116. // Token: 0x0400030A RID: 778
  117. public static List<ModWatcher.Watcher> dicField = new List<ModWatcher.Watcher>();
  118. // Token: 0x0400030B RID: 779
  119. private static bool m_HelperField = false;
  120. // Token: 0x0400030C RID: 780
  121. public static bool _IssuerField = false;
  122. // Token: 0x020000BB RID: 187
  123. public class Watcher
  124. {
  125. // Token: 0x0600058E RID: 1422 RVA: 0x0002FA88 File Offset: 0x0002DC88
  126. public Watcher(ModLoader.LoaderTask<Process, int> Loader, ModMinecraft.McVersion Version, string WindowTitle)
  127. {
  128. ModWatcher.Watcher._Closure$__5-0 CS$<>8__locals1 = new ModWatcher.Watcher._Closure$__5-0(CS$<>8__locals1);
  129. CS$<>8__locals1.$VB$Local_Loader = Loader;
  130. CS$<>8__locals1.$VB$Local_WindowTitle = WindowTitle;
  131. base..ctor();
  132. CS$<>8__locals1.$VB$Me = this;
  133. this._SpecificationTest = "";
  134. this.m_DicTest = ModWatcher.Watcher.MinecraftState.Loading;
  135. this._HelperTest = new List<string>(1000);
  136. this.m_IssuerTest = RuntimeHelpers.GetObjectValue(new object());
  137. this.indexerTest = new Queue<string>();
  138. this.m_InterpreterTest = 0;
  139. this.m_SerializerTest = false;
  140. this.watcherTest = false;
  141. this._RequestTest = CS$<>8__locals1.$VB$Local_Loader;
  142. this._ContextTest = Version;
  143. this._SpecificationTest = CS$<>8__locals1.$VB$Local_WindowTitle;
  144. this.m_MockTest = CS$<>8__locals1.$VB$Local_Loader.Input.Id;
  145. this.WatcherLog("开始 Minecraft 日志监控");
  146. if (Operators.CompareString(this._SpecificationTest, "", false) != 0)
  147. {
  148. this.WatcherLog("要求窗口标题:" + CS$<>8__locals1.$VB$Local_WindowTitle);
  149. }
  150. List<ModWatcher.Watcher> list = new List<ModWatcher.Watcher>();
  151. try
  152. {
  153. foreach (ModWatcher.Watcher watcher in ModWatcher.dicField)
  154. {
  155. if (watcher.State != ModWatcher.Watcher.MinecraftState.Crashed && watcher.State != ModWatcher.Watcher.MinecraftState.Ended && watcher.State != ModWatcher.Watcher.MinecraftState.Canceled)
  156. {
  157. list.Add(watcher);
  158. }
  159. }
  160. }
  161. finally
  162. {
  163. List<ModWatcher.Watcher>.Enumerator enumerator;
  164. ((IDisposable)enumerator).Dispose();
  165. }
  166. list.Add(this);
  167. ModWatcher.dicField = list;
  168. ModWatcher.WatcherStateChanged();
  169. this.m_ErrorTest = CS$<>8__locals1.$VB$Local_Loader.Input;
  170. this.m_ErrorTest.BeginOutputReadLine();
  171. this.m_ErrorTest.BeginErrorReadLine();
  172. this.m_ErrorTest.OutputDataReceived += this.LogReceived;
  173. this.m_ErrorTest.ErrorDataReceived += this.LogReceived;
  174. ModBase.RunInNewThread(checked(delegate
  175. {
  176. try
  177. {
  178. while (CS$<>8__locals1.$VB$Me.State != ModWatcher.Watcher.MinecraftState.Ended && CS$<>8__locals1.$VB$Me.State != ModWatcher.Watcher.MinecraftState.Crashed && CS$<>8__locals1.$VB$Me.State != ModWatcher.Watcher.MinecraftState.Canceled)
  179. {
  180. if (CS$<>8__locals1.$VB$Local_Loader.State == ModBase.LoadState.Aborted)
  181. {
  182. break;
  183. }
  184. CS$<>8__locals1.$VB$Me.TimerWindow();
  185. CS$<>8__locals1.$VB$Me.TimerLog();
  186. int num = 1;
  187. do
  188. {
  189. if (CS$<>8__locals1.$VB$Me.watcherTest && CS$<>8__locals1.$VB$Me.m_SerializerTest && Operators.CompareString(CS$<>8__locals1.$VB$Local_WindowTitle, "", false) != 0 && CS$<>8__locals1.$VB$Me.State == ModWatcher.Watcher.MinecraftState.Running && !CS$<>8__locals1.$VB$Me.m_ErrorTest.HasExited)
  190. {
  191. string text = CS$<>8__locals1.$VB$Local_WindowTitle.Replace("{date}", DateTime.Now.ToString("yyyy/M/d")).Replace("{time}", DateTime.Now.ToString("HH:mm:ss"));
  192. int hWnd = (int)CS$<>8__locals1.$VB$Me._IdentifierTest;
  193. string text2 = new string(text.ToCharArray());
  194. ModWatcher.Watcher.SetWindowTextA(hWnd, ref text2);
  195. }
  196. Thread.Sleep(64);
  197. num++;
  198. }
  199. while (num <= 3);
  200. }
  201. CS$<>8__locals1.$VB$Me.WatcherLog("Minecraft 日志监控已退出");
  202. }
  203. catch (Exception ex)
  204. {
  205. ModBase.Log(ex, "Minecraft 日志监控主循环出错", ModBase.LogLevel.Feedback, "出现错误");
  206. CS$<>8__locals1.$VB$Me.State = ModWatcher.Watcher.MinecraftState.Ended;
  207. }
  208. }), "Minecraft Watcher PID " + Conversions.ToString(this.m_MockTest), ThreadPriority.Normal);
  209. }
  210. // Token: 0x17000090 RID: 144
  211. // (get) Token: 0x0600058F RID: 1423 RVA: 0x00004F50 File Offset: 0x00003150
  212. // (set) Token: 0x06000590 RID: 1424 RVA: 0x00004F58 File Offset: 0x00003158
  213. public ModWatcher.Watcher.MinecraftState State
  214. {
  215. get
  216. {
  217. return this.m_DicTest;
  218. }
  219. set
  220. {
  221. if (this.m_DicTest != value)
  222. {
  223. this.m_DicTest = value;
  224. ModWatcher.WatcherStateChanged();
  225. }
  226. }
  227. }
  228. // Token: 0x06000591 RID: 1425 RVA: 0x0002FC68 File Offset: 0x0002DE68
  229. private void LogReceived(object sender, DataReceivedEventArgs e)
  230. {
  231. object issuerTest = this.m_IssuerTest;
  232. ObjectFlowControl.CheckForSyncLockOnValueType(issuerTest);
  233. lock (issuerTest)
  234. {
  235. this._HelperTest.Add(e.Data);
  236. }
  237. }
  238. // Token: 0x06000592 RID: 1426 RVA: 0x0002FCBC File Offset: 0x0002DEBC
  239. private void TimerLog()
  240. {
  241. try
  242. {
  243. List<string> list = new List<string>();
  244. object issuerTest = this.m_IssuerTest;
  245. ObjectFlowControl.CheckForSyncLockOnValueType(issuerTest);
  246. lock (issuerTest)
  247. {
  248. if (!Enumerable.Any<string>(this._HelperTest))
  249. {
  250. return;
  251. }
  252. list = this._HelperTest;
  253. this._HelperTest = new List<string>(1000);
  254. }
  255. try
  256. {
  257. foreach (string text in list)
  258. {
  259. this.GameLog(text);
  260. }
  261. }
  262. finally
  263. {
  264. List<string>.Enumerator enumerator;
  265. ((IDisposable)enumerator).Dispose();
  266. }
  267. if (this.State == ModWatcher.Watcher.MinecraftState.Loading)
  268. {
  269. this.ProgressUpdate();
  270. }
  271. if (this.m_ErrorTest.HasExited)
  272. {
  273. this.WatcherLog("Minecraft 已退出,返回值:" + Conversions.ToString(this.m_ErrorTest.ExitCode));
  274. if (this.State == ModWatcher.Watcher.MinecraftState.Loading)
  275. {
  276. this.WatcherLog("Minecraft 尚未加载完成,可能已崩溃");
  277. this.Crashed();
  278. }
  279. else if (this.m_ErrorTest.ExitCode != 0 && this.State == ModWatcher.Watcher.MinecraftState.Running && this._ContextTest._RegistryMap.Year >= 2012)
  280. {
  281. this.WatcherLog("Minecraft 返回值异常,可能已崩溃");
  282. this.Crashed();
  283. }
  284. else if (this.State != ModWatcher.Watcher.MinecraftState.Crashed)
  285. {
  286. this.State = ModWatcher.Watcher.MinecraftState.Ended;
  287. }
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. ModBase.Log(ex, "输出 Minecraft 日志失败", ModBase.LogLevel.Feedback, "出现错误");
  293. }
  294. }
  295. // Token: 0x06000593 RID: 1427 RVA: 0x0002FE68 File Offset: 0x0002E068
  296. private void GameLog(string Text)
  297. {
  298. if (Text != null)
  299. {
  300. Text = Text.Replace("\r\n", "\r").Replace("\n", "\r").Replace("\r", "\r\n");
  301. this.indexerTest.Enqueue(Text);
  302. if (this.indexerTest.Count >= 501)
  303. {
  304. this.indexerTest.Dequeue();
  305. }
  306. if (this.m_InterpreterTest < 1)
  307. {
  308. this.WatcherLog("日志 1/5:已出现日志输出");
  309. this.m_InterpreterTest = 1;
  310. }
  311. if (this.m_InterpreterTest < 2 && Text.Contains("Setting user:"))
  312. {
  313. this.WatcherLog("日志 2/5:游戏用户已设置");
  314. this.m_InterpreterTest = 2;
  315. }
  316. else if (this.m_InterpreterTest < 3 && Text.ContainsF("lwjgl version", true))
  317. {
  318. this.WatcherLog("日志 3/5:LWJGL 版本已确认");
  319. this.m_InterpreterTest = 3;
  320. }
  321. else if (this.m_InterpreterTest < 4 && (Text.Contains("OpenAL initialized") || Text.Contains("Starting up SoundSystem")))
  322. {
  323. this.WatcherLog("日志 4/5:OpenAL 已加载");
  324. this.m_InterpreterTest = 4;
  325. }
  326. else if (this.m_InterpreterTest < 5 && ((Text.Contains("Created") && Text.Contains("textures") && Text.Contains("-atlas")) || Text.Contains("Found animation info")))
  327. {
  328. this.WatcherLog("日志 5/5:材质已加载");
  329. this.m_InterpreterTest = 5;
  330. }
  331. if (!Text.Contains("[CHAT]"))
  332. {
  333. if (Text.Contains("Someone is closing me!") || Text.Contains("Restarting Minecraft with command"))
  334. {
  335. this.WatcherLog("识别为关闭的 Log:" + Text);
  336. this.State = ModWatcher.Watcher.MinecraftState.Ended;
  337. return;
  338. }
  339. if (Text.Contains("Crash report saved to") || Text.Contains("This crash report has been saved to:"))
  340. {
  341. this.WatcherLog("识别为崩溃的 Log:" + Text);
  342. this.Crashed();
  343. return;
  344. }
  345. if (Text.Contains("Could not save crash report to"))
  346. {
  347. this.WatcherLog("识别为崩溃的 Log:" + Text);
  348. this.Crashed();
  349. return;
  350. }
  351. if (Text.Contains("/ERROR]: Unable to launch") || Text.Contains("An exception was thrown, the game will display an error screen and halt."))
  352. {
  353. this.WatcherLog("识别为崩溃的 Log:" + Text);
  354. this.Crashed();
  355. }
  356. }
  357. }
  358. }
  359. // Token: 0x06000594 RID: 1428 RVA: 0x00004F6F File Offset: 0x0000316F
  360. private void WatcherLog(string Text)
  361. {
  362. ModLaunch.McLaunchLog("[" + Conversions.ToString(this.m_MockTest) + "] " + Text);
  363. }
  364. // Token: 0x06000595 RID: 1429 RVA: 0x000300A4 File Offset: 0x0002E2A4
  365. private void ProgressUpdate()
  366. {
  367. double progress;
  368. if (!this.m_SerializerTest)
  369. {
  370. if (this.m_InterpreterTest != 5)
  371. {
  372. progress = (double)Math.Min(this.m_InterpreterTest, 3) / 3.0 * 0.9;
  373. goto IL_54;
  374. }
  375. }
  376. progress = 0.95;
  377. this.WatcherLog("Minecraft 加载已完成");
  378. this.State = ModWatcher.Watcher.MinecraftState.Running;
  379. IL_54:
  380. this._RequestTest.Progress = progress;
  381. }
  382. // Token: 0x06000596 RID: 1430 RVA: 0x00030114 File Offset: 0x0002E314
  383. private void TimerWindow()
  384. {
  385. try
  386. {
  387. if (!this.m_ErrorTest.HasExited)
  388. {
  389. if (!this.watcherTest)
  390. {
  391. KeyValuePair<IntPtr, string>? keyValuePair = null;
  392. try
  393. {
  394. keyValuePair = this.TryGetMinecraftWindow();
  395. }
  396. catch (Win32Exception ex)
  397. {
  398. ModBase.Log(ex, "由于反作弊或安全软件拦截,PCL 无法操作游戏窗口", ModBase.LogLevel.Hint, "出现错误");
  399. this.watcherTest = true;
  400. }
  401. if (keyValuePair != null)
  402. {
  403. string value = keyValuePair.Value.Value;
  404. IntPtr MinecraftWindowHandle = keyValuePair.Value.Key;
  405. if (!value.StartsWithF("FML", false))
  406. {
  407. this._IdentifierTest = MinecraftWindowHandle;
  408. this.WatcherLog(string.Format("Minecraft 窗口已加载:{0}({1})", value, MinecraftWindowHandle.ToInt64()));
  409. this.watcherTest = true;
  410. if (Operators.ConditionalCompareObjectEqual(ModBase.m_IdentifierRepository.Get("LaunchArgumentWindowType", null), 4, false))
  411. {
  412. ModBase.RunInNewThread(delegate
  413. {
  414. try
  415. {
  416. Thread.Sleep(2000);
  417. ModWatcher.Watcher.ShowWindow(this._IdentifierTest, 3U);
  418. this.WatcherLog(string.Format("已最大化 Minecraft 窗口:{0}", MinecraftWindowHandle.ToInt64()));
  419. }
  420. catch (Exception ex3)
  421. {
  422. ModBase.Log(ex3, "最大化 Minecraft 窗口时出现错误", ModBase.LogLevel.Debug, "出现错误");
  423. }
  424. }, "MinecraftWindowMaximize", ThreadPriority.Normal);
  425. }
  426. }
  427. else if (!this.m_SerializerTest)
  428. {
  429. this.WatcherLog(string.Concat(new string[]
  430. {
  431. "FML 窗口已加载:",
  432. value,
  433. "(",
  434. Conversions.ToString(MinecraftWindowHandle.ToInt64()),
  435. ")"
  436. }));
  437. }
  438. this.m_SerializerTest = true;
  439. }
  440. }
  441. }
  442. }
  443. catch (Exception ex2)
  444. {
  445. ModBase.Log(ex2, "检查 Minecraft 窗口失败", ModBase.LogLevel.Feedback, "出现错误");
  446. }
  447. }
  448. // Token: 0x06000597 RID: 1431 RVA: 0x00004F91 File Offset: 0x00003191
  449. private KeyValuePair<IntPtr, string>? TryGetMinecraftWindow()
  450. {
  451. KeyValuePair<IntPtr, string>? TryGetMinecraftWindow = null;
  452. ModWatcher.Watcher.EnumWindows(delegate(IntPtr hwnd, int lParam)
  453. {
  454. if (TryGetMinecraftWindow == null)
  455. {
  456. StringBuilder stringBuilder = new StringBuilder(512);
  457. ModWatcher.Watcher.GetClassNameA((int)hwnd, stringBuilder, stringBuilder.Capacity);
  458. string left = stringBuilder.ToString();
  459. if (Operators.CompareString(left, "GLFW30", false) == 0 || Operators.CompareString(left, "LWJGL", false) == 0 || Operators.CompareString(left, "SunAwtFrame", false) == 0)
  460. {
  461. stringBuilder = new StringBuilder(512);
  462. ModWatcher.Watcher.GetWindowTextA((int)hwnd, stringBuilder, stringBuilder.Capacity);
  463. string text = stringBuilder.ToString();
  464. if (text.StartsWithF("FML", false) || (Operators.CompareString(text, "PopupMessageWindow", false) != 0 && !text.StartsWithF("GLFW", false)))
  465. {
  466. int processId;
  467. ModWatcher.Watcher.GetWindowThreadProcessId(hwnd, ref processId);
  468. try
  469. {
  470. if (DateTime.Compare(Process.GetProcessById(processId).StartTime, this.m_ErrorTest.StartTime) < 0)
  471. {
  472. return;
  473. }
  474. }
  475. catch (Exception ex)
  476. {
  477. ModBase.Log(ex, "枚举 Minecraft 窗口进程失败", ModBase.LogLevel.Debug, "出现错误");
  478. return;
  479. }
  480. TryGetMinecraftWindow = new KeyValuePair<IntPtr, string>?(new KeyValuePair<IntPtr, string>(hwnd, text));
  481. }
  482. }
  483. }
  484. }, 0);
  485. TryGetMinecraftWindow = TryGetMinecraftWindow;
  486. return TryGetMinecraftWindow;
  487. }
  488. // Token: 0x06000598 RID: 1432
  489. [DllImport("user32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  490. private static extern bool EnumWindows(ModWatcher.Watcher.EnumWindowsSub hWnd, int lParam);
  491. // Token: 0x06000599 RID: 1433
  492. [DllImport("user32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  493. private static extern int GetClassNameA(int hWnd, StringBuilder str, int maxCount);
  494. // Token: 0x0600059A RID: 1434
  495. [DllImport("user32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  496. private static extern int GetWindowTextA(int hWnd, StringBuilder str, int maxCount);
  497. // Token: 0x0600059B RID: 1435
  498. [DllImport("user32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  499. private static extern bool SetWindowTextA(int hWnd, [MarshalAs(UnmanagedType.VBByRefStr)] ref string str);
  500. // Token: 0x0600059C RID: 1436
  501. [DllImport("user32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  502. private static extern bool ShowWindow(IntPtr hWnd, uint cmdWindow);
  503. // Token: 0x0600059D RID: 1437
  504. [DllImport("user32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
  505. private static extern int GetWindowThreadProcessId(IntPtr hWnd, ref int lpdwProcessId);
  506. // Token: 0x0600059E RID: 1438 RVA: 0x000302DC File Offset: 0x0002E4DC
  507. private void Crashed()
  508. {
  509. if (this.State != ModWatcher.Watcher.MinecraftState.Crashed && this.State != ModWatcher.Watcher.MinecraftState.Ended)
  510. {
  511. this.State = ModWatcher.Watcher.MinecraftState.Crashed;
  512. this.WatcherLog("Minecraft 已崩溃,将在 2 秒后开始崩溃分析");
  513. ModMain.Hint("检测到 Minecraft 出现错误,错误分析已开始……", ModMain.HintType.Info, true);
  514. ModBase.FeedbackInfo();
  515. ModBase.RunInNewThread(delegate
  516. {
  517. try
  518. {
  519. Thread.Sleep(2000);
  520. this.WatcherLog("崩溃分析开始");
  521. CrashAnalyzer crashAnalyzer = new CrashAnalyzer(this.m_MockTest);
  522. crashAnalyzer.Collect(this._ContextTest.ChangeMapper(), Enumerable.ToList<string>(this.indexerTest));
  523. crashAnalyzer.Prepare();
  524. crashAnalyzer.Analyze(this._ContextTest);
  525. crashAnalyzer.Output(false, new List<string>
  526. {
  527. this._ContextTest.Path + this._ContextTest.Name + ".json",
  528. ModBase.Path + "PCL\\Log1.txt",
  529. ModBase.Path + "PCL\\LatestLaunch.bat"
  530. });
  531. }
  532. catch (Exception ex)
  533. {
  534. ModBase.Log(ex, "崩溃分析失败", ModBase.LogLevel.Feedback, "出现错误");
  535. }
  536. }, "Crash Analyzer", ThreadPriority.Normal);
  537. }
  538. }
  539. // Token: 0x0600059F RID: 1439 RVA: 0x00030338 File Offset: 0x0002E538
  540. public void Kill()
  541. {
  542. this.State = ModWatcher.Watcher.MinecraftState.Canceled;
  543. this.WatcherLog("尝试强制结束 Minecraft 进程");
  544. try
  545. {
  546. if (!this.m_ErrorTest.HasExited)
  547. {
  548. this.m_ErrorTest.Kill();
  549. }
  550. this.WatcherLog("已强制结束 Minecraft 进程");
  551. }
  552. catch (Exception ex)
  553. {
  554. ModBase.Log(ex, "强制结束 Minecraft 进程失败", ModBase.LogLevel.Hint, "出现错误");
  555. }
  556. }
  557. // Token: 0x0400030D RID: 781
  558. public Process m_ErrorTest;
  559. // Token: 0x0400030E RID: 782
  560. public ModMinecraft.McVersion _ContextTest;
  561. // Token: 0x0400030F RID: 783
  562. private string _SpecificationTest;
  563. // Token: 0x04000310 RID: 784
  564. private int m_MockTest;
  565. // Token: 0x04000311 RID: 785
  566. public ModLoader.LoaderTask<Process, int> _RequestTest;
  567. // Token: 0x04000312 RID: 786
  568. private ModWatcher.Watcher.MinecraftState m_DicTest;
  569. // Token: 0x04000313 RID: 787
  570. public List<string> _HelperTest;
  571. // Token: 0x04000314 RID: 788
  572. private readonly object m_IssuerTest;
  573. // Token: 0x04000315 RID: 789
  574. public Queue<string> indexerTest;
  575. // Token: 0x04000316 RID: 790
  576. private int m_InterpreterTest;
  577. // Token: 0x04000317 RID: 791
  578. private bool m_SerializerTest;
  579. // Token: 0x04000318 RID: 792
  580. private bool watcherTest;
  581. // Token: 0x04000319 RID: 793
  582. private IntPtr _IdentifierTest;
  583. // Token: 0x020000BC RID: 188
  584. public enum MinecraftState
  585. {
  586. // Token: 0x0400031B RID: 795
  587. Loading,
  588. // Token: 0x0400031C RID: 796
  589. Running,
  590. // Token: 0x0400031D RID: 797
  591. Crashed,
  592. // Token: 0x0400031E RID: 798
  593. Ended,
  594. // Token: 0x0400031F RID: 799
  595. Canceled
  596. }
  597. // Token: 0x020000BD RID: 189
  598. // (Invoke) Token: 0x060005A5 RID: 1445
  599. private delegate void EnumWindowsSub(IntPtr hwnd, int lParam);
  600. }
  601. }
  602. }