2
0

ModEvent.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using Microsoft.VisualBasic.CompilerServices;
  5. namespace PCL
  6. {
  7. // Token: 0x0200008A RID: 138
  8. [StandardModule]
  9. public sealed class ModEvent
  10. {
  11. // Token: 0x06000390 RID: 912 RVA: 0x00026118 File Offset: 0x00024318
  12. public static void TryStartEvent(string Type, string Data)
  13. {
  14. if (!string.IsNullOrWhiteSpace(Type))
  15. {
  16. string[] data = new string[]
  17. {
  18. ""
  19. };
  20. if (Data != null)
  21. {
  22. data = Data.Split("|");
  23. }
  24. ModEvent.StartEvent(Type, data);
  25. }
  26. }
  27. // Token: 0x06000391 RID: 913 RVA: 0x00026154 File Offset: 0x00024354
  28. public static void StartEvent(string Type, string[] Data)
  29. {
  30. checked
  31. {
  32. try
  33. {
  34. ModBase.Log("[Control] 执行自定义事件:" + Type + ", " + Data.Join(", "), ModBase.LogLevel.Normal, "出现错误");
  35. string $VB$Local_Type = Type;
  36. uint num = <PrivateImplementationDetails>.ComputeStringHash($VB$Local_Type);
  37. if (num <= 1214012690U)
  38. {
  39. if (num <= 213330431U)
  40. {
  41. if (num != 46857845U)
  42. {
  43. if (num != 87465761U)
  44. {
  45. if (num != 213330431U)
  46. {
  47. goto IL_5DB;
  48. }
  49. if (Operators.CompareString($VB$Local_Type, "打开文件", false) != 0)
  50. {
  51. goto IL_5DB;
  52. }
  53. goto IL_612;
  54. }
  55. else
  56. {
  57. if (Operators.CompareString($VB$Local_Type, "复制文本", false) == 0)
  58. {
  59. ModBase.ClipboardSet(Data.Join("|"), true);
  60. goto IL_623;
  61. }
  62. goto IL_5DB;
  63. }
  64. }
  65. else
  66. {
  67. if (Operators.CompareString($VB$Local_Type, "今日人品", false) == 0)
  68. {
  69. PageOtherTest.Jrrp();
  70. goto IL_623;
  71. }
  72. goto IL_5DB;
  73. }
  74. }
  75. else if (num <= 790387239U)
  76. {
  77. if (num != 425440694U)
  78. {
  79. if (num != 790387239U)
  80. {
  81. goto IL_5DB;
  82. }
  83. if (Operators.CompareString($VB$Local_Type, "清理垃圾", false) == 0)
  84. {
  85. ModBase.RunInThread((ModEvent._Closure$__.$I1-2 == null) ? (ModEvent._Closure$__.$I1-2 = delegate()
  86. {
  87. PageOtherTest.RubbishClear();
  88. }) : ModEvent._Closure$__.$I1-2);
  89. goto IL_623;
  90. }
  91. goto IL_5DB;
  92. }
  93. else if (Operators.CompareString($VB$Local_Type, "安装整合包", false) != 0)
  94. {
  95. goto IL_5DB;
  96. }
  97. }
  98. else if (num != 1018565114U)
  99. {
  100. if (num != 1214012690U)
  101. {
  102. goto IL_5DB;
  103. }
  104. if (Operators.CompareString($VB$Local_Type, "内存优化", false) == 0)
  105. {
  106. ModBase.RunInThread((ModEvent._Closure$__.$I1-1 == null) ? (ModEvent._Closure$__.$I1-1 = delegate()
  107. {
  108. PageOtherTest.MemoryOptimize(true);
  109. }) : ModEvent._Closure$__.$I1-1);
  110. goto IL_623;
  111. }
  112. goto IL_5DB;
  113. }
  114. else
  115. {
  116. if (Operators.CompareString($VB$Local_Type, "刷新主页", false) != 0)
  117. {
  118. goto IL_5DB;
  119. }
  120. ModMain.m_ServiceIterator.ForceRefresh();
  121. if (Operators.CompareString(Data[0], "", false) == 0)
  122. {
  123. ModMain.Hint("已刷新主页!", ModMain.HintType.Finish, true);
  124. goto IL_623;
  125. }
  126. goto IL_623;
  127. }
  128. }
  129. else if (num <= 2917375879U)
  130. {
  131. if (num <= 1629407123U)
  132. {
  133. if (num != 1534644891U)
  134. {
  135. if (num != 1629407123U)
  136. {
  137. goto IL_5DB;
  138. }
  139. if (Operators.CompareString($VB$Local_Type, "启动游戏", false) != 0)
  140. {
  141. goto IL_5DB;
  142. }
  143. if (Operators.CompareString(Data[0], "\\current", false) == 0)
  144. {
  145. if (ModMinecraft.AddClient() == null)
  146. {
  147. ModMain.Hint("请先选择一个 Minecraft 版本!", ModMain.HintType.Critical, true);
  148. return;
  149. }
  150. Data[0] = ModMinecraft.AddClient().Name;
  151. }
  152. if (ModLaunch.McLaunchStart(new ModLaunch.McLaunchOptions
  153. {
  154. m_MockMap = ((Data.Length >= 2) ? Data[1] : null),
  155. _DicMap = new ModMinecraft.McVersion(Data[0])
  156. }))
  157. {
  158. ModMain.Hint("正在启动 " + Data[0] + "……", ModMain.HintType.Info, true);
  159. goto IL_623;
  160. }
  161. goto IL_623;
  162. }
  163. else
  164. {
  165. if (Operators.CompareString($VB$Local_Type, "切换页面", false) == 0)
  166. {
  167. ModMain._ProcessIterator.PageChange((FormMain.PageType)Math.Round(ModBase.Val(Data[0])), (FormMain.PageSubType)Math.Round(ModBase.Val(Data[1])));
  168. goto IL_623;
  169. }
  170. goto IL_5DB;
  171. }
  172. }
  173. else if (num != 1804229068U)
  174. {
  175. if (num != 2917375879U)
  176. {
  177. goto IL_5DB;
  178. }
  179. if (Operators.CompareString($VB$Local_Type, "刷新帮助", false) == 0)
  180. {
  181. PageOtherLeft.RefreshHelp();
  182. goto IL_623;
  183. }
  184. goto IL_5DB;
  185. }
  186. else
  187. {
  188. if (Operators.CompareString($VB$Local_Type, "弹出窗口", false) == 0)
  189. {
  190. ModMain.MyMsgBox(Data[1].Replace("\\n", "\r\n"), Data[0].Replace("\\n", "\r\n"), "确定", "", "", false, true, false, null, null, null);
  191. goto IL_623;
  192. }
  193. goto IL_5DB;
  194. }
  195. }
  196. else if (num <= 3824712473U)
  197. {
  198. if (num != 3277022720U)
  199. {
  200. if (num != 3824712473U)
  201. {
  202. goto IL_5DB;
  203. }
  204. if (Operators.CompareString($VB$Local_Type, "导入整合包", false) != 0)
  205. {
  206. goto IL_5DB;
  207. }
  208. }
  209. else
  210. {
  211. if (Operators.CompareString($VB$Local_Type, "打开网页", false) != 0)
  212. {
  213. goto IL_5DB;
  214. }
  215. Data[0] = Data[0].Replace("\\", "/");
  216. if (Data[0].Contains("://") && !Data[0].StartsWithF("file", true))
  217. {
  218. ModMain.Hint("正在开启中,请稍候……", ModMain.HintType.Info, true);
  219. ModBase.OpenWebsite(Data[0]);
  220. goto IL_623;
  221. }
  222. ModMain.MyMsgBox("EventData 必须为一个网址。\r\n如果想要启动程序,请将 EventType 改为 打开文件。", "事件执行失败", "确定", "", "", false, true, false, null, null, null);
  223. return;
  224. }
  225. }
  226. else
  227. {
  228. if (num != 3900623875U)
  229. {
  230. if (num != 4108293856U)
  231. {
  232. goto IL_5DB;
  233. }
  234. if (Operators.CompareString($VB$Local_Type, "下载文件", false) != 0)
  235. {
  236. goto IL_5DB;
  237. }
  238. Data[0] = Data[0].Replace("\\", "/");
  239. if (!Data[0].StartsWithF("http://", true) && !Data[0].StartsWithF("https://", true))
  240. {
  241. ModMain.MyMsgBox("EventData 必须为以 http:// 或 https:// 开头的网址。\r\nPCL 不支持其他乱七八糟的下载协议。", "事件执行失败", "确定", "", "", false, true, false, null, null, null);
  242. return;
  243. }
  244. try
  245. {
  246. int num2 = Data.Length;
  247. if (num2 != 1)
  248. {
  249. if (num2 != 2)
  250. {
  251. PageOtherTest.StartCustomDownload(Data[0], Data[1], Data[2]);
  252. }
  253. else
  254. {
  255. PageOtherTest.StartCustomDownload(Data[0], Data[1], null);
  256. }
  257. }
  258. else
  259. {
  260. PageOtherTest.StartCustomDownload(Data[0], ModBase.GetFileNameFromPath(Data[0]), null);
  261. }
  262. goto IL_623;
  263. }
  264. catch (Exception ex)
  265. {
  266. PageOtherTest.StartCustomDownload(Data[0], "未知", null);
  267. goto IL_623;
  268. }
  269. }
  270. if (Operators.CompareString($VB$Local_Type, "打开帮助", false) != 0)
  271. {
  272. goto IL_5DB;
  273. }
  274. goto IL_612;
  275. }
  276. ModBase.RunInUi((ModEvent._Closure$__.$I1-3 == null) ? (ModEvent._Closure$__.$I1-3 = delegate()
  277. {
  278. ModModpack.ModpackInstall();
  279. }) : ModEvent._Closure$__.$I1-3, false);
  280. goto IL_623;
  281. IL_5DB:
  282. ModMain.MyMsgBox("未知的事件类型:" + Type + "\r\n请检查事件类型填写是否正确,或者 PCL 是否为最新版本。", "事件执行失败", "确定", "", "", false, true, false, null, null, null);
  283. goto IL_623;
  284. IL_612:
  285. ModBase.RunInThread(delegate
  286. {
  287. try
  288. {
  289. string[] eventAbsoluteUrls = ModEvent.GetEventAbsoluteUrls(Data[0], Type);
  290. string text = eventAbsoluteUrls[0];
  291. string text2 = eventAbsoluteUrls[1];
  292. ModBase.Log(string.Format("[Control] 打开类自定义事件实际路径:{0},工作目录:{1}", text, text2), ModBase.LogLevel.Normal, "出现错误");
  293. if (Operators.CompareString(Type, "打开文件", false) == 0)
  294. {
  295. Process.Start(new ProcessStartInfo
  296. {
  297. Arguments = ((Data.Length >= 2) ? Data[1] : ""),
  298. FileName = text,
  299. WorkingDirectory = text2
  300. });
  301. }
  302. else
  303. {
  304. PageOtherHelp.EnterHelpPage(text);
  305. }
  306. }
  307. catch (Exception ex3)
  308. {
  309. ModBase.Log(ex3, "执行打开类自定义事件失败", ModBase.LogLevel.Msgbox, "出现错误");
  310. }
  311. });
  312. IL_623:;
  313. }
  314. catch (Exception ex2)
  315. {
  316. ModBase.Log(ex2, "事件执行失败", ModBase.LogLevel.Msgbox, "出现错误");
  317. }
  318. }
  319. }
  320. // Token: 0x06000392 RID: 914 RVA: 0x000267DC File Offset: 0x000249DC
  321. public static string[] GetEventAbsoluteUrls(string RelativeUrl, string EventType)
  322. {
  323. if (RelativeUrl.StartsWithF("http", true))
  324. {
  325. if (ModBase.RunInUi())
  326. {
  327. throw new Exception("能打开联网帮助页面的 MyListItem 必须手动设置 Title、Info 属性!");
  328. }
  329. string fileNameFromPath;
  330. try
  331. {
  332. fileNameFromPath = ModBase.GetFileNameFromPath(RelativeUrl);
  333. if (!fileNameFromPath.EndsWithF(".json", true))
  334. {
  335. throw new Exception("未指向 .json 后缀的文件");
  336. }
  337. }
  338. catch (Exception innerException)
  339. {
  340. throw new Exception("联网帮助页面须指向一个帮助 JSON 文件,并在同路径下包含相应 XAML 文件!\r\n例如:\r\n - https://www.baidu.com/test.json(填写这个路径)\r\n - https://www.baidu.com/test.xaml(同时也需要包含这个文件)", innerException);
  341. }
  342. string text = ModBase.m_DecoratorRepository + "CustomEvent\\" + fileNameFromPath;
  343. ModBase.m_DecoratorRepository + "CustomEvent\\" + fileNameFromPath.Replace(".json", ".xaml");
  344. ModBase.Log("[Event] 转换网络资源:" + RelativeUrl + " -> " + text, ModBase.LogLevel.Normal, "出现错误");
  345. try
  346. {
  347. ModNet.NetDownload(RelativeUrl, text, false);
  348. ModNet.NetDownload(RelativeUrl.Replace(".json", ".xaml"), text.Replace(".json", ".xaml"), false);
  349. }
  350. catch (Exception innerException2)
  351. {
  352. throw new Exception("下载指定的文件失败!\r\n注意,联网帮助页面须指向一个帮助 JSON 文件,并在同路径下包含相应 XAML 文件!\r\n例如:\r\n - https://www.baidu.com/test.json(填写这个路径)\r\n - https://www.baidu.com/test.xaml(同时也需要包含这个文件)", innerException2);
  353. }
  354. RelativeUrl = text;
  355. }
  356. RelativeUrl = RelativeUrl.Replace("/", "\\").ToLower().TrimStart(new char[]
  357. {
  358. '\\'
  359. });
  360. string text2 = ModBase.Path + "PCL";
  361. ModMain.HelpTryExtract();
  362. string text3;
  363. if (RelativeUrl.Contains(":\\"))
  364. {
  365. text3 = RelativeUrl;
  366. ModBase.Log("[Control] 自定义事件中由绝对路径" + EventType + ":" + text3, ModBase.LogLevel.Normal, "出现错误");
  367. }
  368. else if (File.Exists(ModBase.Path + "PCL\\" + RelativeUrl))
  369. {
  370. text3 = ModBase.Path + "PCL\\" + RelativeUrl;
  371. ModBase.Log("[Control] 自定义事件中由相对 PCL 文件夹的路径" + EventType + ":" + text3, ModBase.LogLevel.Normal, "出现错误");
  372. }
  373. else if (File.Exists(ModBase.Path + "PCL\\Help\\" + RelativeUrl))
  374. {
  375. text3 = ModBase.Path + "PCL\\Help\\" + RelativeUrl;
  376. text2 = ModBase.Path + "PCL\\Help\\";
  377. ModBase.Log("[Control] 自定义事件中由相对 PCL 本地帮助文件夹的路径" + EventType + ":" + text3, ModBase.LogLevel.Normal, "出现错误");
  378. }
  379. else if (Operators.CompareString(EventType, "打开帮助", false) == 0 && File.Exists(ModBase.m_DecoratorRepository + "Help\\" + RelativeUrl))
  380. {
  381. text3 = ModBase.m_DecoratorRepository + "Help\\" + RelativeUrl;
  382. text2 = ModBase.m_DecoratorRepository + "Help\\";
  383. ModBase.Log("[Control] 自定义事件中由相对 PCL 自带帮助文件夹的路径" + EventType + ":" + text3, ModBase.LogLevel.Normal, "出现错误");
  384. }
  385. else
  386. {
  387. if (Operators.CompareString(EventType, "打开文件", false) != 0)
  388. {
  389. throw new FileNotFoundException("未找到 EventData 指向的本地 xaml 文件:" + RelativeUrl, RelativeUrl);
  390. }
  391. text3 = RelativeUrl;
  392. ModBase.Log("[Control] 自定义事件中直接" + EventType + ":" + text3, ModBase.LogLevel.Normal, "出现错误");
  393. }
  394. return new string[]
  395. {
  396. text3,
  397. text2
  398. };
  399. }
  400. }
  401. }