ModLoader.cs 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Threading;
  8. using System.Windows.Shell;
  9. using Microsoft.VisualBasic;
  10. using Microsoft.VisualBasic.CompilerServices;
  11. namespace PCL
  12. {
  13. // Token: 0x02000121 RID: 289
  14. [StandardModule]
  15. public sealed class ModLoader
  16. {
  17. // Token: 0x06000C92 RID: 3218 RVA: 0x0000859C File Offset: 0x0000679C
  18. public static void LoaderTaskbarAdd<T>(ModLoader.LoaderCombo<T> Loader)
  19. {
  20. if (ModMain._MessageIterator != null)
  21. {
  22. ModMain._MessageIterator.TaskRemove(Loader);
  23. }
  24. ModLoader.LoaderTaskbar.Add(Loader);
  25. ModBase.Log(string.Format("[Taskbar] {0} 已加入任务列表", Loader.Name), ModBase.LogLevel.Normal, "出现错误");
  26. }
  27. // Token: 0x06000C93 RID: 3219 RVA: 0x00054480 File Offset: 0x00052680
  28. public static void LoaderTaskbarProgressRefresh()
  29. {
  30. try
  31. {
  32. double num = ModLoader.LoaderTaskbarProgressGet();
  33. bool flag = true;
  34. try
  35. {
  36. List<ModLoader.LoaderBase>.Enumerator enumerator = Enumerable.ToList<ModLoader.LoaderBase>(ModLoader.LoaderTaskbar).GetEnumerator();
  37. while (enumerator.MoveNext())
  38. {
  39. if (enumerator.Current.State == ModBase.LoadState.Loading)
  40. {
  41. flag = false;
  42. }
  43. }
  44. }
  45. finally
  46. {
  47. List<ModLoader.LoaderBase>.Enumerator enumerator;
  48. ((IDisposable)enumerator).Dispose();
  49. }
  50. try
  51. {
  52. foreach (ModLoader.LoaderBase loaderBase in Enumerable.ToList<ModLoader.LoaderBase>(ModLoader.LoaderTaskbar))
  53. {
  54. if (flag || loaderBase.State == ModBase.LoadState.Aborted || loaderBase.State == ModBase.LoadState.Waiting)
  55. {
  56. if (ModMain._MessageIterator != null)
  57. {
  58. ModMain._MessageIterator.TaskRefresh(loaderBase);
  59. }
  60. ModLoader.LoaderTaskbar.Remove(loaderBase);
  61. ModBase.Log(string.Format("[Taskbar] {0} 已移出任务列表", loaderBase.Name), ModBase.LogLevel.Normal, "出现错误");
  62. }
  63. }
  64. }
  65. finally
  66. {
  67. List<ModLoader.LoaderBase>.Enumerator enumerator2;
  68. ((IDisposable)enumerator2).Dispose();
  69. }
  70. if (num > 0.0 && num < 1.0 && ModLoader.LoaderTaskbarProgress <= num)
  71. {
  72. ModLoader.LoaderTaskbarProgress = ModLoader.LoaderTaskbarProgress * 0.9 + num * 0.1;
  73. }
  74. else
  75. {
  76. ModLoader.LoaderTaskbarProgress = num;
  77. }
  78. ModBase.RunInUi((ModLoader._Closure$__.$I8-0 == null) ? (ModLoader._Closure$__.$I8-0 = delegate()
  79. {
  80. ModMain._ProcessIterator.BtnExtraDownload.Progress = ModLoader.LoaderTaskbarProgress;
  81. }) : ModLoader._Closure$__.$I8-0, false);
  82. TaskbarItemProgressState taskbarItemProgressState;
  83. if (Enumerable.Any<ModLoader.LoaderBase>(ModLoader.LoaderTaskbar))
  84. {
  85. if (ModLoader.LoaderTaskbarProgress != 1.0)
  86. {
  87. if (ModLoader.LoaderTaskbarProgress < 0.015)
  88. {
  89. taskbarItemProgressState = TaskbarItemProgressState.Indeterminate;
  90. goto IL_18B;
  91. }
  92. taskbarItemProgressState = TaskbarItemProgressState.Normal;
  93. ModMain._ProcessIterator.TaskbarItemInfo.ProgressValue = ModLoader.LoaderTaskbarProgress;
  94. goto IL_18B;
  95. }
  96. }
  97. taskbarItemProgressState = TaskbarItemProgressState.None;
  98. IL_18B:
  99. if (ModLoader.LoaderTaskbarProgressLast != taskbarItemProgressState)
  100. {
  101. ModLoader.LoaderTaskbarProgressLast = taskbarItemProgressState;
  102. ModMain._ProcessIterator.TaskbarItemInfo.ProgressState = taskbarItemProgressState;
  103. ModMain._ProcessIterator.BtnExtraDownload.ShowRefresh();
  104. }
  105. }
  106. catch (Exception ex)
  107. {
  108. ModBase.Log(ex, "刷新任务栏进度显示失败", ModBase.LogLevel.Feedback, "出现错误");
  109. }
  110. }
  111. // Token: 0x06000C94 RID: 3220 RVA: 0x000546B4 File Offset: 0x000528B4
  112. public static double LoaderTaskbarProgressGet()
  113. {
  114. double result;
  115. try
  116. {
  117. if (!Enumerable.Any<ModLoader.LoaderBase>(ModLoader.LoaderTaskbar))
  118. {
  119. result = 1.0;
  120. }
  121. else
  122. {
  123. result = ModBase.MathClamp(Enumerable.Average(Enumerable.Select<ModLoader.LoaderBase, double>(ModLoader.LoaderTaskbar, (ModLoader._Closure$__.$I9-0 == null) ? (ModLoader._Closure$__.$I9-0 = ((ModLoader.LoaderBase e) => e.Progress)) : ModLoader._Closure$__.$I9-0)), 0.0, 1.0);
  124. }
  125. }
  126. catch (Exception ex)
  127. {
  128. ModBase.Log(ex, "获取任务栏进度出错", ModBase.LogLevel.Feedback, "出现错误");
  129. result = 0.5;
  130. }
  131. return result;
  132. }
  133. // Token: 0x06000C95 RID: 3221 RVA: 0x00054760 File Offset: 0x00052960
  134. public static bool LoaderFolderRun(ModLoader.LoaderBase Loader, string FolderPath, ModLoader.LoaderFolderRunType Type, int MaxDepth = 0, string ExtraPath = "", bool WaitForExit = false)
  135. {
  136. ModLoader.LoaderFolderDictionaryEntry value = default(ModLoader.LoaderFolderDictionaryEntry);
  137. value.FolderPath = FolderPath + ExtraPath;
  138. value.LastCheckTime = null;
  139. try
  140. {
  141. DirectoryInfo directoryInfo = new DirectoryInfo(FolderPath + ExtraPath);
  142. value.LastCheckTime = (directoryInfo.Exists ? new DateTime?(ModLoader.GetActualLastWriteTimeUtc(directoryInfo, MaxDepth)) : ((DateTime?)null));
  143. if (Type == ModLoader.LoaderFolderRunType.RunOnUpdated && ModLoader.LoaderFolderDictionary.ContainsKey(Loader))
  144. {
  145. if (directoryInfo.Exists)
  146. {
  147. ModLoader.LoaderFolderDictionaryEntry loaderFolderDictionaryEntry = ModLoader.LoaderFolderDictionary[Loader];
  148. if (loaderFolderDictionaryEntry.LastCheckTime != null && value.Equals(ModLoader.LoaderFolderDictionary[Loader]))
  149. {
  150. return false;
  151. }
  152. }
  153. else
  154. {
  155. ModLoader.LoaderFolderDictionaryEntry loaderFolderDictionaryEntry = ModLoader.LoaderFolderDictionary[Loader];
  156. if (loaderFolderDictionaryEntry.LastCheckTime == null)
  157. {
  158. return false;
  159. }
  160. }
  161. }
  162. }
  163. catch (Exception ex)
  164. {
  165. ModBase.Log(ex, "文件夹加载器启动检测出错", ModBase.LogLevel.Debug, "出现错误");
  166. }
  167. ModLoader.LoaderFolderDictionary[Loader] = value;
  168. bool result;
  169. if (Type == ModLoader.LoaderFolderRunType.UpdateOnly)
  170. {
  171. result = false;
  172. }
  173. else
  174. {
  175. if (WaitForExit)
  176. {
  177. Loader.WaitForExit(FolderPath, null, true);
  178. }
  179. else
  180. {
  181. Loader.Start(FolderPath, true);
  182. }
  183. result = true;
  184. }
  185. return result;
  186. }
  187. // Token: 0x06000C96 RID: 3222 RVA: 0x00054898 File Offset: 0x00052A98
  188. private static DateTime GetActualLastWriteTimeUtc(DirectoryInfo FolderInfo, int MaxDepth)
  189. {
  190. DateTime dateTime = FolderInfo.LastWriteTimeUtc;
  191. if (MaxDepth > 0)
  192. {
  193. try
  194. {
  195. foreach (DirectoryInfo folderInfo in FolderInfo.EnumerateDirectories())
  196. {
  197. DateTime actualLastWriteTimeUtc = ModLoader.GetActualLastWriteTimeUtc(folderInfo, checked(MaxDepth - 1));
  198. if (DateTime.Compare(actualLastWriteTimeUtc, dateTime) > 0)
  199. {
  200. dateTime = actualLastWriteTimeUtc;
  201. }
  202. }
  203. }
  204. finally
  205. {
  206. IEnumerator<DirectoryInfo> enumerator;
  207. if (enumerator != null)
  208. {
  209. enumerator.Dispose();
  210. }
  211. }
  212. }
  213. return dateTime;
  214. }
  215. // Token: 0x04000658 RID: 1624
  216. public static ModBase.SafeList<ModLoader.LoaderBase> LoaderTaskbar = new ModBase.SafeList<ModLoader.LoaderBase>();
  217. // Token: 0x04000659 RID: 1625
  218. public static double LoaderTaskbarProgress = 0.0;
  219. // Token: 0x0400065A RID: 1626
  220. private static TaskbarItemProgressState LoaderTaskbarProgressLast = TaskbarItemProgressState.None;
  221. // Token: 0x0400065B RID: 1627
  222. private static Dictionary<ModLoader.LoaderBase, ModLoader.LoaderFolderDictionaryEntry> LoaderFolderDictionary = new Dictionary<ModLoader.LoaderBase, ModLoader.LoaderFolderDictionaryEntry>();
  223. // Token: 0x02000122 RID: 290
  224. public abstract class LoaderBase : ILoadingTrigger
  225. {
  226. // Token: 0x06000C97 RID: 3223 RVA: 0x00054900 File Offset: 0x00052B00
  227. protected LoaderBase()
  228. {
  229. this.IsLoader = 1;
  230. this.Uuid = ModBase.GetUuid();
  231. this.Name = "未命名任务 " + Conversions.ToString(this.Uuid) + "#";
  232. this.LockState = RuntimeHelpers.GetObjectValue(new object());
  233. this.Parent = null;
  234. this.HasOnStateChangedThread = false;
  235. this._State = ModBase.LoadState.Waiting;
  236. this._LoadingState = MyLoading.MyLoadingState.Stop;
  237. this.Error = null;
  238. this.Block = true;
  239. this.Show = true;
  240. this.IsForceRestarting = false;
  241. this._Progress = -1.0;
  242. this.ProgressWeight = 1.0;
  243. }
  244. // Token: 0x170001FE RID: 510
  245. // (get) Token: 0x06000C98 RID: 3224 RVA: 0x000085D6 File Offset: 0x000067D6
  246. public bool IsLoader { get; }
  247. // Token: 0x170001FF RID: 511
  248. // (get) Token: 0x06000C99 RID: 3225 RVA: 0x000549AC File Offset: 0x00052BAC
  249. public ModLoader.LoaderBase RealParent
  250. {
  251. get
  252. {
  253. ModLoader.LoaderBase loaderBase;
  254. try
  255. {
  256. loaderBase = this.Parent;
  257. while (loaderBase != null && loaderBase.Parent != null)
  258. {
  259. loaderBase = loaderBase.Parent;
  260. }
  261. }
  262. catch (Exception ex)
  263. {
  264. ModBase.Log(ex, "获取父加载器失败(" + this.Name + ")", ModBase.LogLevel.Feedback, "出现错误");
  265. loaderBase = null;
  266. }
  267. return loaderBase;
  268. }
  269. }
  270. // Token: 0x06000C9A RID: 3226 RVA: 0x000085DE File Offset: 0x000067DE
  271. public virtual void InitParent(ModLoader.LoaderBase Parent)
  272. {
  273. this.Parent = Parent;
  274. }
  275. // Token: 0x1400000D RID: 13
  276. // (add) Token: 0x06000C9B RID: 3227 RVA: 0x00054A18 File Offset: 0x00052C18
  277. // (remove) Token: 0x06000C9C RID: 3228 RVA: 0x00054A50 File Offset: 0x00052C50
  278. public event ModLoader.LoaderBase.OnStateChangedThreadEventHandler OnStateChangedThread;
  279. // Token: 0x1400000E RID: 14
  280. // (add) Token: 0x06000C9D RID: 3229 RVA: 0x00054A88 File Offset: 0x00052C88
  281. // (remove) Token: 0x06000C9E RID: 3230 RVA: 0x00054AC0 File Offset: 0x00052CC0
  282. public event ModLoader.LoaderBase.OnStateChangedUiEventHandler OnStateChangedUi;
  283. // Token: 0x17000200 RID: 512
  284. // (set) Token: 0x06000C9F RID: 3231 RVA: 0x00054AF8 File Offset: 0x00052CF8
  285. public Action<ModLoader.LoaderBase> OnStateChanged
  286. {
  287. set
  288. {
  289. this.OnStateChangedUi += delegate(ModLoader.LoaderBase Loader, ModBase.LoadState NewState, ModBase.LoadState OldState)
  290. {
  291. value(Loader);
  292. };
  293. }
  294. }
  295. // Token: 0x1400000F RID: 15
  296. // (add) Token: 0x06000CA0 RID: 3232 RVA: 0x00054B24 File Offset: 0x00052D24
  297. // (remove) Token: 0x06000CA1 RID: 3233 RVA: 0x00054B5C File Offset: 0x00052D5C
  298. public event ModLoader.LoaderBase.PreviewFinishEventHandler PreviewFinish;
  299. // Token: 0x06000CA2 RID: 3234 RVA: 0x00054B94 File Offset: 0x00052D94
  300. protected void RaisePreviewFinish()
  301. {
  302. ModLoader.LoaderBase.PreviewFinishEventHandler previewFinishEvent = this.PreviewFinishEvent;
  303. if (previewFinishEvent != null)
  304. {
  305. previewFinishEvent(this);
  306. }
  307. }
  308. // Token: 0x17000201 RID: 513
  309. // (get) Token: 0x06000CA3 RID: 3235 RVA: 0x000085E7 File Offset: 0x000067E7
  310. // (set) Token: 0x06000CA4 RID: 3236 RVA: 0x00054BB4 File Offset: 0x00052DB4
  311. public ModBase.LoadState State
  312. {
  313. get
  314. {
  315. return this._State;
  316. }
  317. set
  318. {
  319. if (this._State != value)
  320. {
  321. ModBase.LoadState OldState = this._State;
  322. if (Conversions.ToBoolean(value == ModBase.LoadState.Finished && Conversions.ToBoolean(ModBase.m_IdentifierRepository.Get("SystemDebugDelay", null))))
  323. {
  324. Thread.Sleep(ModBase.RandomInteger(100, 2000));
  325. }
  326. this._State = value;
  327. ModBase.Log("[Loader] 加载器 " + this.Name + " 状态改变:" + ModBase.GetStringFromEnum(value), ModBase.LogLevel.Normal, "出现错误");
  328. ModBase.RunInUi(delegate()
  329. {
  330. ModBase.LoadState $VB$Local_value = value;
  331. if ($VB$Local_value != ModBase.LoadState.Loading)
  332. {
  333. if ($VB$Local_value != ModBase.LoadState.Failed)
  334. {
  335. this.LoadingState = MyLoading.MyLoadingState.Stop;
  336. }
  337. else
  338. {
  339. this.LoadingState = MyLoading.MyLoadingState.Error;
  340. }
  341. }
  342. else
  343. {
  344. this.LoadingState = MyLoading.MyLoadingState.Run;
  345. }
  346. ModLoader.LoaderBase.OnStateChangedUiEventHandler onStateChangedUiEvent = this.OnStateChangedUiEvent;
  347. if (onStateChangedUiEvent != null)
  348. {
  349. onStateChangedUiEvent(this, value, OldState);
  350. }
  351. }, false);
  352. if (this.HasOnStateChangedThread)
  353. {
  354. ModBase.RunInThread(delegate
  355. {
  356. ModLoader.LoaderBase.OnStateChangedThreadEventHandler onStateChangedThreadEvent = this.OnStateChangedThreadEvent;
  357. if (onStateChangedThreadEvent != null)
  358. {
  359. onStateChangedThreadEvent(this, value, OldState);
  360. }
  361. });
  362. }
  363. }
  364. }
  365. }
  366. // Token: 0x17000202 RID: 514
  367. // (get) Token: 0x06000CA5 RID: 3237 RVA: 0x000085EF File Offset: 0x000067EF
  368. // (set) Token: 0x06000CA6 RID: 3238 RVA: 0x00054C98 File Offset: 0x00052E98
  369. public MyLoading.MyLoadingState LoadingState
  370. {
  371. get
  372. {
  373. return this._LoadingState;
  374. }
  375. set
  376. {
  377. if (this._LoadingState != value)
  378. {
  379. MyLoading.MyLoadingState loadingState = this._LoadingState;
  380. this._LoadingState = value;
  381. ILoadingTrigger.LoadingStateChangedEventHandler loadingStateChangedEvent = this.LoadingStateChangedEvent;
  382. if (loadingStateChangedEvent != null)
  383. {
  384. loadingStateChangedEvent(value, loadingState);
  385. }
  386. }
  387. }
  388. }
  389. // Token: 0x14000010 RID: 16
  390. // (add) Token: 0x06000CA7 RID: 3239 RVA: 0x00054CD0 File Offset: 0x00052ED0
  391. // (remove) Token: 0x06000CA8 RID: 3240 RVA: 0x00054D08 File Offset: 0x00052F08
  392. public event ILoadingTrigger.LoadingStateChangedEventHandler LoadingStateChanged;
  393. // Token: 0x17000203 RID: 515
  394. // (get) Token: 0x06000CA9 RID: 3241 RVA: 0x000085F7 File Offset: 0x000067F7
  395. // (set) Token: 0x06000CAA RID: 3242 RVA: 0x000085FF File Offset: 0x000067FF
  396. public Exception Error { get; set; }
  397. // Token: 0x17000204 RID: 516
  398. // (get) Token: 0x06000CAB RID: 3243 RVA: 0x00054D40 File Offset: 0x00052F40
  399. // (set) Token: 0x06000CAC RID: 3244 RVA: 0x00054D98 File Offset: 0x00052F98
  400. public virtual double Progress
  401. {
  402. get
  403. {
  404. ModBase.LoadState state = this.State;
  405. double result;
  406. if (state != ModBase.LoadState.Waiting)
  407. {
  408. if (state != ModBase.LoadState.Loading)
  409. {
  410. result = 1.0;
  411. }
  412. else
  413. {
  414. result = ((this._Progress == -1.0) ? 0.02 : this._Progress);
  415. }
  416. }
  417. else
  418. {
  419. result = 0.0;
  420. }
  421. return result;
  422. }
  423. set
  424. {
  425. if (this._Progress != value)
  426. {
  427. double progress = this._Progress;
  428. this._Progress = value;
  429. ILoadingTrigger.ProgressChangedEventHandler progressChangedEvent = this.ProgressChangedEvent;
  430. if (progressChangedEvent != null)
  431. {
  432. progressChangedEvent(value, progress);
  433. }
  434. }
  435. }
  436. }
  437. // Token: 0x14000011 RID: 17
  438. // (add) Token: 0x06000CAD RID: 3245 RVA: 0x00054DD0 File Offset: 0x00052FD0
  439. // (remove) Token: 0x06000CAE RID: 3246 RVA: 0x00054E08 File Offset: 0x00053008
  440. public event ILoadingTrigger.ProgressChangedEventHandler ProgressChanged;
  441. // Token: 0x17000205 RID: 517
  442. // (get) Token: 0x06000CAF RID: 3247 RVA: 0x00008608 File Offset: 0x00006808
  443. // (set) Token: 0x06000CB0 RID: 3248 RVA: 0x00008610 File Offset: 0x00006810
  444. public double ProgressWeight { get; set; }
  445. // Token: 0x06000CB1 RID: 3249
  446. public abstract void Start(object Input = null, bool IsForceRestart = false);
  447. // Token: 0x06000CB2 RID: 3250
  448. public abstract void Abort();
  449. // Token: 0x06000CB3 RID: 3251 RVA: 0x00054E40 File Offset: 0x00053040
  450. public void WaitForExit(object Input = null, ModLoader.LoaderBase LoaderToSyncProgress = null, bool IsForceRestart = false)
  451. {
  452. this.Start(RuntimeHelpers.GetObjectValue(Input), IsForceRestart);
  453. while (this.State == ModBase.LoadState.Loading)
  454. {
  455. if (LoaderToSyncProgress != null)
  456. {
  457. LoaderToSyncProgress.Progress = this.Progress;
  458. }
  459. Thread.Sleep(10);
  460. }
  461. if (this.State == ModBase.LoadState.Finished)
  462. {
  463. return;
  464. }
  465. if (this.State == ModBase.LoadState.Aborted)
  466. {
  467. throw new ThreadInterruptedException("加载器执行已中断。");
  468. }
  469. if (Information.IsNothing(this.Error))
  470. {
  471. throw new Exception("未知错误!");
  472. }
  473. throw new Exception(this.Error.Message, this.Error);
  474. }
  475. // Token: 0x06000CB4 RID: 3252 RVA: 0x00054EC8 File Offset: 0x000530C8
  476. public void WaitForExitTime(int Timeout, object Input = null, string TimeoutMessage = "等待加载器执行超时。", object LoaderToSyncProgress = null, bool IsForceRestart = false)
  477. {
  478. this.Start(RuntimeHelpers.GetObjectValue(Input), IsForceRestart);
  479. checked
  480. {
  481. while (this.State == ModBase.LoadState.Loading)
  482. {
  483. if (LoaderToSyncProgress != null)
  484. {
  485. NewLateBinding.LateSet(LoaderToSyncProgress, null, "Progress", new object[]
  486. {
  487. this.Progress
  488. }, null, null);
  489. }
  490. Thread.Sleep(10);
  491. Timeout -= 10;
  492. if (Timeout < 0)
  493. {
  494. throw new TimeoutException(TimeoutMessage);
  495. }
  496. }
  497. if (this.State == ModBase.LoadState.Finished)
  498. {
  499. return;
  500. }
  501. if (this.State == ModBase.LoadState.Aborted)
  502. {
  503. throw new ThreadInterruptedException("加载器执行已中断。");
  504. }
  505. if (Information.IsNothing(this.Error))
  506. {
  507. throw new Exception("未知错误!");
  508. }
  509. throw this.Error;
  510. }
  511. }
  512. // Token: 0x06000CB5 RID: 3253 RVA: 0x00054F6C File Offset: 0x0005316C
  513. public override bool Equals(object obj)
  514. {
  515. ModLoader.LoaderBase loaderBase = obj as ModLoader.LoaderBase;
  516. return loaderBase != null && this.Uuid == loaderBase.Uuid;
  517. }
  518. // Token: 0x0400065D RID: 1629
  519. public int Uuid;
  520. // Token: 0x0400065E RID: 1630
  521. public string Name;
  522. // Token: 0x0400065F RID: 1631
  523. public readonly object LockState;
  524. // Token: 0x04000660 RID: 1632
  525. public ModLoader.LoaderBase Parent;
  526. // Token: 0x04000662 RID: 1634
  527. public bool HasOnStateChangedThread;
  528. // Token: 0x04000665 RID: 1637
  529. private ModBase.LoadState _State;
  530. // Token: 0x04000666 RID: 1638
  531. private MyLoading.MyLoadingState _LoadingState;
  532. // Token: 0x04000669 RID: 1641
  533. public bool Block;
  534. // Token: 0x0400066A RID: 1642
  535. public bool Show;
  536. // Token: 0x0400066B RID: 1643
  537. public bool IsForceRestarting;
  538. // Token: 0x0400066C RID: 1644
  539. private double _Progress;
  540. // Token: 0x02000123 RID: 291
  541. // (Invoke) Token: 0x06000CBA RID: 3258
  542. public delegate void OnStateChangedThreadEventHandler(ModLoader.LoaderBase Loader, ModBase.LoadState NewState, ModBase.LoadState OldState);
  543. // Token: 0x02000124 RID: 292
  544. // (Invoke) Token: 0x06000CBF RID: 3263
  545. public delegate void OnStateChangedUiEventHandler(ModLoader.LoaderBase Loader, ModBase.LoadState NewState, ModBase.LoadState OldState);
  546. // Token: 0x02000125 RID: 293
  547. // (Invoke) Token: 0x06000CC4 RID: 3268
  548. public delegate void PreviewFinishEventHandler(ModLoader.LoaderBase Loader);
  549. }
  550. // Token: 0x02000128 RID: 296
  551. public class LoaderTask<InputType, OutputType> : ModLoader.LoaderBase
  552. {
  553. // Token: 0x17000206 RID: 518
  554. // (get) Token: 0x06000CCD RID: 3277 RVA: 0x00008627 File Offset: 0x00006827
  555. public bool IsAborted
  556. {
  557. get
  558. {
  559. return this.IsAbortedWithThread(Thread.CurrentThread);
  560. }
  561. }
  562. // Token: 0x06000CCE RID: 3278 RVA: 0x00008634 File Offset: 0x00006834
  563. public bool IsAbortedWithThread(Thread Thread)
  564. {
  565. return this.LastRunningThread == null || !object.ReferenceEquals(Thread, this.LastRunningThread) || base.State == ModBase.LoadState.Aborted;
  566. }
  567. // Token: 0x06000CCF RID: 3279 RVA: 0x00055034 File Offset: 0x00053234
  568. public InputType StartGetInput(InputType Input = default(InputType), Func<object> InputDelegate = null)
  569. {
  570. ModLoader.LoaderTask<InputType, OutputType>._Closure$__11-0 CS$<>8__locals1 = new ModLoader.LoaderTask<!0, !1>._Closure$__11-0();
  571. CS$<>8__locals1.$VB$Local_Input = Input;
  572. CS$<>8__locals1.$VB$Local_InputDelegate = InputDelegate;
  573. if (CS$<>8__locals1.$VB$Local_InputDelegate == null)
  574. {
  575. CS$<>8__locals1.$VB$Local_InputDelegate = this.InputDelegate;
  576. }
  577. InputType inputType = default(!0);
  578. if (CS$<>8__locals1.$VB$Local_Input != null)
  579. {
  580. if (inputType == null)
  581. {
  582. goto IL_8F;
  583. }
  584. ModLoader.LoaderTask<InputType, OutputType>._Closure$__11-0 CS$<>8__locals2 = CS$<>8__locals1;
  585. ref !0 ptr = ref CS$<>8__locals2.$VB$Local_Input;
  586. if (default(!0) == null)
  587. {
  588. InputType $VB$Local_Input = CS$<>8__locals2.$VB$Local_Input;
  589. ptr = ref $VB$Local_Input;
  590. }
  591. if (!ptr.Equals(inputType))
  592. {
  593. goto IL_8F;
  594. }
  595. }
  596. if (CS$<>8__locals1.$VB$Local_InputDelegate != null)
  597. {
  598. ModBase.RunInUiWait(delegate()
  599. {
  600. CS$<>8__locals1.$VB$Local_Input = Conversions.ToGenericParameter<InputType>(CS$<>8__locals1.$VB$Local_InputDelegate());
  601. });
  602. }
  603. IL_8F:
  604. return CS$<>8__locals1.$VB$Local_Input;
  605. }
  606. // Token: 0x06000CD0 RID: 3280 RVA: 0x000550D8 File Offset: 0x000532D8
  607. public bool ShouldStart(ref object Input, bool IsForceRestart = false, bool IgnoreReloadTimeout = false)
  608. {
  609. try
  610. {
  611. Input = this.StartGetInput(Conversions.ToGenericParameter<InputType>(Input), null);
  612. }
  613. catch (Exception ex)
  614. {
  615. ModBase.Log(ex, "加载输入获取失败(" + this.Name + ")", ModBase.LogLevel.Hint, "出现错误");
  616. base.Error = ex;
  617. object lockState = this.LockState;
  618. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  619. lock (lockState)
  620. {
  621. base.State = ModBase.LoadState.Failed;
  622. }
  623. }
  624. return IsForceRestart || Input == null != (this.Input == null) || (Input != null && !Input.Equals(this.Input)) || ((base.State != ModBase.LoadState.Loading && base.State != ModBase.LoadState.Finished) || (!IgnoreReloadTimeout && this.ReloadTimeout != -1 && this.LastFinishedTime != 0L && checked(ModBase.GetTimeTick() - this.LastFinishedTime) >= (long)this.ReloadTimeout));
  625. }
  626. // Token: 0x06000CD1 RID: 3281 RVA: 0x000551F4 File Offset: 0x000533F4
  627. public override void Start(object Input = null, bool IsForceRestart = false)
  628. {
  629. if (this.ShouldStart(ref Input, IsForceRestart, false))
  630. {
  631. if (base.State == ModBase.LoadState.Loading)
  632. {
  633. this.TriggerThreadAbort();
  634. }
  635. this.Input = Conversions.ToGenericParameter<InputType>(Input);
  636. object lockState = this.LockState;
  637. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  638. lock (lockState)
  639. {
  640. base.State = ModBase.LoadState.Loading;
  641. this.Progress = -1.0;
  642. }
  643. this.LastRunningThread = new Thread(delegate()
  644. {
  645. try
  646. {
  647. this.IsForceRestarting = IsForceRestart;
  648. if (ModBase._TokenRepository)
  649. {
  650. ModBase.Log(string.Concat(new string[]
  651. {
  652. "[Loader] 加载线程 ",
  653. this.Name,
  654. " (",
  655. Conversions.ToString(Thread.CurrentThread.ManagedThreadId),
  656. ") 已",
  657. this.IsForceRestarting ? "强制" : "",
  658. "启动"
  659. }), ModBase.LogLevel.Normal, "出现错误");
  660. }
  661. this.LoadDelegate(this);
  662. if (this.IsAborted)
  663. {
  664. ModBase.Log(string.Concat(new string[]
  665. {
  666. "[Loader] 加载线程 ",
  667. this.Name,
  668. " (",
  669. Conversions.ToString(Thread.CurrentThread.ManagedThreadId),
  670. ") 已中断但线程正常运行至结束,输出被弃用(最新线程:",
  671. Conversions.ToString((this.LastRunningThread == null) ? -1 : this.LastRunningThread.ManagedThreadId),
  672. ")"
  673. }), ModBase.LogLevel.Developer, "出现错误");
  674. }
  675. else
  676. {
  677. this.RaisePreviewFinish();
  678. this.State = ModBase.LoadState.Finished;
  679. this.LastFinishedTime = ModBase.GetTimeTick();
  680. }
  681. }
  682. catch (ThreadInterruptedException ex)
  683. {
  684. if (ModBase._TokenRepository)
  685. {
  686. ModBase.Log(ex, string.Concat(new string[]
  687. {
  688. "加载线程 ",
  689. this.Name,
  690. " (",
  691. Conversions.ToString(Thread.CurrentThread.ManagedThreadId),
  692. ") 已触发线程中断"
  693. }), ModBase.LogLevel.Debug, "出现错误");
  694. }
  695. if (!this.IsAborted)
  696. {
  697. this.State = ModBase.LoadState.Aborted;
  698. }
  699. }
  700. catch (Exception ex2)
  701. {
  702. if (!this.IsAborted)
  703. {
  704. ModBase.Log(ex2, string.Concat(new string[]
  705. {
  706. "加载线程 ",
  707. this.Name,
  708. " (",
  709. Conversions.ToString(Thread.CurrentThread.ManagedThreadId),
  710. ") 发生运行时错误"
  711. }), ModBase.LogLevel.Developer, "出现错误");
  712. this.Error = ex2;
  713. this.State = ModBase.LoadState.Failed;
  714. }
  715. }
  716. })
  717. {
  718. Name = this.Name,
  719. Priority = this.ThreadPriority
  720. };
  721. this.LastRunningThread.Start();
  722. }
  723. }
  724. // Token: 0x06000CD2 RID: 3282 RVA: 0x000552C8 File Offset: 0x000534C8
  725. public override void Abort()
  726. {
  727. if (base.State == ModBase.LoadState.Loading)
  728. {
  729. object lockState = this.LockState;
  730. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  731. lock (lockState)
  732. {
  733. base.State = ModBase.LoadState.Aborted;
  734. }
  735. this.TriggerThreadAbort();
  736. }
  737. }
  738. // Token: 0x06000CD3 RID: 3283 RVA: 0x00055320 File Offset: 0x00053520
  739. private void TriggerThreadAbort()
  740. {
  741. if (this.LastRunningThread != null)
  742. {
  743. if (ModBase._TokenRepository)
  744. {
  745. ModBase.Log(string.Concat(new string[]
  746. {
  747. "[Loader] 加载线程 ",
  748. this.Name,
  749. " (",
  750. Conversions.ToString(this.LastRunningThread.ManagedThreadId),
  751. ") 已中断"
  752. }), ModBase.LogLevel.Normal, "出现错误");
  753. }
  754. if (this.LastRunningThread.IsAlive)
  755. {
  756. this.LastRunningThread.Interrupt();
  757. }
  758. this.LastRunningThread = null;
  759. }
  760. }
  761. // Token: 0x06000CD4 RID: 3284 RVA: 0x00008657 File Offset: 0x00006857
  762. public LoaderTask()
  763. {
  764. this.ReloadTimeout = -1;
  765. this.LastFinishedTime = 0L;
  766. this.LastRunningThread = null;
  767. this.Input = default(!0);
  768. this.Output = default(!1);
  769. }
  770. // Token: 0x06000CD5 RID: 3285 RVA: 0x000553A8 File Offset: 0x000535A8
  771. public LoaderTask(string Name, Action<ModLoader.LoaderTask<InputType, OutputType>> LoadDelegate, Func<InputType> InputDelegate = null, ThreadPriority Priority = ThreadPriority.Normal)
  772. {
  773. this.ReloadTimeout = -1;
  774. this.LastFinishedTime = 0L;
  775. this.LastRunningThread = null;
  776. this.Input = default(!0);
  777. this.Output = default(!1);
  778. this.Name = Name;
  779. this.LoadDelegate = LoadDelegate;
  780. this.InputDelegate = InputDelegate;
  781. this.ThreadPriority = Priority;
  782. }
  783. // Token: 0x04000673 RID: 1651
  784. protected internal ThreadPriority ThreadPriority;
  785. // Token: 0x04000674 RID: 1652
  786. protected internal Action<ModLoader.LoaderTask<InputType, OutputType>> LoadDelegate;
  787. // Token: 0x04000675 RID: 1653
  788. protected internal Func<object> InputDelegate;
  789. // Token: 0x04000676 RID: 1654
  790. public int ReloadTimeout;
  791. // Token: 0x04000677 RID: 1655
  792. public long LastFinishedTime;
  793. // Token: 0x04000678 RID: 1656
  794. public Thread LastRunningThread;
  795. // Token: 0x04000679 RID: 1657
  796. public InputType Input;
  797. // Token: 0x0400067A RID: 1658
  798. public OutputType Output;
  799. }
  800. // Token: 0x0200012B RID: 299
  801. public class LoaderCombo<InputType> : ModLoader.LoaderBase
  802. {
  803. // Token: 0x17000207 RID: 519
  804. // (get) Token: 0x06000CDD RID: 3293 RVA: 0x000556B8 File Offset: 0x000538B8
  805. // (set) Token: 0x06000CDE RID: 3294 RVA: 0x000086AD File Offset: 0x000068AD
  806. public override double Progress
  807. {
  808. get
  809. {
  810. ModBase.LoadState state = base.State;
  811. double result;
  812. if (state != ModBase.LoadState.Waiting)
  813. {
  814. if (state != ModBase.LoadState.Loading)
  815. {
  816. result = 1.0;
  817. }
  818. else
  819. {
  820. double num = 0.0;
  821. double num2 = 0.0;
  822. try
  823. {
  824. foreach (ModLoader.LoaderBase loaderBase in this.Loaders)
  825. {
  826. num += loaderBase.ProgressWeight;
  827. num2 += loaderBase.ProgressWeight * loaderBase.Progress;
  828. }
  829. }
  830. finally
  831. {
  832. List<ModLoader.LoaderBase>.Enumerator enumerator;
  833. ((IDisposable)enumerator).Dispose();
  834. }
  835. if (num == 0.0)
  836. {
  837. result = 0.0;
  838. }
  839. else
  840. {
  841. result = num2 / num;
  842. }
  843. }
  844. }
  845. else
  846. {
  847. result = 0.0;
  848. }
  849. return result;
  850. }
  851. set
  852. {
  853. throw new Exception("多重加载器不支持设置进度");
  854. }
  855. }
  856. // Token: 0x06000CDF RID: 3295 RVA: 0x00055780 File Offset: 0x00053980
  857. public LoaderCombo(string Name, IEnumerable<ModLoader.LoaderBase> Loaders)
  858. {
  859. this.Loaders = new List<ModLoader.LoaderBase>();
  860. this.Loaders.Clear();
  861. try
  862. {
  863. foreach (ModLoader.LoaderBase loaderBase in Loaders)
  864. {
  865. if (loaderBase != null)
  866. {
  867. this.Loaders.Add(loaderBase);
  868. loaderBase.OnStateChangedThread += this.SubTaskStateChanged;
  869. loaderBase.HasOnStateChangedThread = true;
  870. }
  871. }
  872. }
  873. finally
  874. {
  875. IEnumerator<ModLoader.LoaderBase> enumerator;
  876. if (enumerator != null)
  877. {
  878. enumerator.Dispose();
  879. }
  880. }
  881. this.InitParent(null);
  882. this.Name = Name;
  883. }
  884. // Token: 0x06000CE0 RID: 3296 RVA: 0x00055814 File Offset: 0x00053A14
  885. public override void InitParent(ModLoader.LoaderBase Parent)
  886. {
  887. this.Parent = Parent;
  888. try
  889. {
  890. foreach (ModLoader.LoaderBase loaderBase in this.Loaders)
  891. {
  892. loaderBase.InitParent(this);
  893. }
  894. }
  895. finally
  896. {
  897. List<ModLoader.LoaderBase>.Enumerator enumerator;
  898. ((IDisposable)enumerator).Dispose();
  899. }
  900. }
  901. // Token: 0x06000CE1 RID: 3297 RVA: 0x0005586C File Offset: 0x00053A6C
  902. public override void Start(object Input = null, bool IsForceRestart = false)
  903. {
  904. this.IsForceRestarting = IsForceRestart;
  905. object lockState = this.LockState;
  906. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  907. lock (lockState)
  908. {
  909. if (base.State == ModBase.LoadState.Loading)
  910. {
  911. return;
  912. }
  913. base.State = ModBase.LoadState.Loading;
  914. }
  915. this.Input = Conversions.ToGenericParameter<InputType>(Input);
  916. if (IsForceRestart)
  917. {
  918. try
  919. {
  920. foreach (ModLoader.LoaderBase loaderBase in this.Loaders)
  921. {
  922. loaderBase.State = ModBase.LoadState.Waiting;
  923. }
  924. }
  925. finally
  926. {
  927. List<ModLoader.LoaderBase>.Enumerator enumerator;
  928. ((IDisposable)enumerator).Dispose();
  929. }
  930. }
  931. ModBase.RunInThread(new Action(this.Update));
  932. }
  933. // Token: 0x06000CE2 RID: 3298 RVA: 0x00055928 File Offset: 0x00053B28
  934. public override void Abort()
  935. {
  936. object lockState = this.LockState;
  937. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  938. lock (lockState)
  939. {
  940. if (base.State != ModBase.LoadState.Loading && base.State != ModBase.LoadState.Waiting)
  941. {
  942. return;
  943. }
  944. base.State = ModBase.LoadState.Aborted;
  945. }
  946. ModBase.RunInThread(delegate
  947. {
  948. try
  949. {
  950. foreach (ModLoader.LoaderBase loaderBase in this.Loaders)
  951. {
  952. loaderBase.Abort();
  953. }
  954. }
  955. finally
  956. {
  957. List<ModLoader.LoaderBase>.Enumerator enumerator;
  958. ((IDisposable)enumerator).Dispose();
  959. }
  960. });
  961. }
  962. // Token: 0x06000CE3 RID: 3299 RVA: 0x00055994 File Offset: 0x00053B94
  963. private void SubTaskStateChanged(ModLoader.LoaderBase Loader, ModBase.LoadState NewState, ModBase.LoadState OldState)
  964. {
  965. switch (NewState)
  966. {
  967. case ModBase.LoadState.Waiting:
  968. case ModBase.LoadState.Loading:
  969. return;
  970. case ModBase.LoadState.Finished:
  971. this.Update();
  972. return;
  973. case ModBase.LoadState.Aborted:
  974. this.Abort();
  975. return;
  976. }
  977. object lockState = this.LockState;
  978. ObjectFlowControl.CheckForSyncLockOnValueType(lockState);
  979. lock (lockState)
  980. {
  981. if (base.State >= ModBase.LoadState.Finished)
  982. {
  983. return;
  984. }
  985. base.Error = new Exception(Loader.Name + "失败", Loader.Error);
  986. base.State = Loader.State;
  987. }
  988. try
  989. {
  990. List<ModLoader.LoaderBase>.Enumerator enumerator = this.Loaders.GetEnumerator();
  991. while (enumerator.MoveNext())
  992. {
  993. Loader = enumerator.Current;
  994. Loader.Abort();
  995. }
  996. }
  997. finally
  998. {
  999. List<ModLoader.LoaderBase>.Enumerator enumerator;
  1000. ((IDisposable)enumerator).Dispose();
  1001. }
  1002. ModMain._ProcessIterator.BtnExtraDownload.ShowRefresh();
  1003. }
  1004. // Token: 0x06000CE4 RID: 3300 RVA: 0x00055A8C File Offset: 0x00053C8C
  1005. private void Update()
  1006. {
  1007. if (base.State != ModBase.LoadState.Finished && base.State != ModBase.LoadState.Failed && base.State != ModBase.LoadState.Aborted)
  1008. {
  1009. bool flag = true;
  1010. bool flag2 = false;
  1011. object obj = this.Input;
  1012. try
  1013. {
  1014. foreach (ModLoader.LoaderBase loaderBase in this.Loaders)
  1015. {
  1016. ModBase.LoadState state = loaderBase.State;
  1017. if (state == ModBase.LoadState.Loading)
  1018. {
  1019. if (loaderBase.GetType().Name.StartsWithF("LoaderTask", false))
  1020. {
  1021. object instance = loaderBase;
  1022. Type type = null;
  1023. string memberName = "ShouldStart";
  1024. object[] array = new object[2];
  1025. int num = 1;
  1026. if (obj == null)
  1027. {
  1028. goto IL_180;
  1029. }
  1030. if (Enumerable.First<Type>(loaderBase.GetType().GenericTypeArguments) != obj.GetType())
  1031. {
  1032. goto IL_180;
  1033. }
  1034. object obj2 = obj;
  1035. IL_181:
  1036. array[num] = obj2;
  1037. array[0] = true;
  1038. if (Conversions.ToBoolean(NewLateBinding.LateGet(instance, type, memberName, array, new string[]
  1039. {
  1040. "IgnoreReloadTimeout"
  1041. }, null, null)))
  1042. {
  1043. ModBase.Log("[Loader] 由于输入条件变更,重启进行中的加载器 " + loaderBase.Name, ModBase.LogLevel.Developer, "出现错误");
  1044. goto IL_1C6;
  1045. }
  1046. goto IL_27B;
  1047. IL_180:
  1048. obj2 = null;
  1049. goto IL_181;
  1050. }
  1051. IL_27B:
  1052. flag = false;
  1053. flag2 = true;
  1054. continue;
  1055. }
  1056. if (state == ModBase.LoadState.Finished)
  1057. {
  1058. if (loaderBase.GetType().Name.StartsWithF("LoaderTask", false))
  1059. {
  1060. object instance2 = loaderBase;
  1061. Type type2 = null;
  1062. string memberName2 = "ShouldStart";
  1063. object[] array2 = new object[2];
  1064. int num2 = 1;
  1065. if (obj == null)
  1066. {
  1067. goto IL_B5;
  1068. }
  1069. if (Enumerable.First<Type>(loaderBase.GetType().GenericTypeArguments) != obj.GetType())
  1070. {
  1071. goto IL_B5;
  1072. }
  1073. object obj3 = obj;
  1074. IL_B6:
  1075. array2[num2] = obj3;
  1076. array2[0] = true;
  1077. if (Conversions.ToBoolean(NewLateBinding.LateGet(instance2, type2, memberName2, array2, new string[]
  1078. {
  1079. "IgnoreReloadTimeout"
  1080. }, null, null)))
  1081. {
  1082. ModBase.Log("[Loader] 由于输入条件变更,重启已完成的加载器 " + loaderBase.Name, ModBase.LogLevel.Normal, "出现错误");
  1083. goto IL_1C6;
  1084. }
  1085. obj = RuntimeHelpers.GetObjectValue(NewLateBinding.LateGet(loaderBase, null, "Output", new object[0], null, null, null));
  1086. goto IL_119;
  1087. IL_B5:
  1088. obj3 = null;
  1089. goto IL_B6;
  1090. }
  1091. IL_119:
  1092. if (loaderBase.Block && !flag)
  1093. {
  1094. flag2 = true;
  1095. continue;
  1096. }
  1097. continue;
  1098. }
  1099. IL_1C6:
  1100. flag = false;
  1101. if (!flag2)
  1102. {
  1103. if (obj != null)
  1104. {
  1105. string name = loaderBase.GetType().Name;
  1106. if (!name.StartsWithF("LoaderTask", false) && !name.StartsWithF("LoaderCombo", false))
  1107. {
  1108. if (!name.StartsWithF("LoaderDownload", false))
  1109. {
  1110. throw new Exception("未知的加载器类型(" + name + ")");
  1111. }
  1112. loaderBase.Start(RuntimeHelpers.GetObjectValue((obj is List<ModNet.NetFile>) ? obj : null), this.IsForceRestarting);
  1113. }
  1114. else
  1115. {
  1116. loaderBase.Start(RuntimeHelpers.GetObjectValue((Enumerable.First<Type>(loaderBase.GetType().GenericTypeArguments) == obj.GetType()) ? obj : null), this.IsForceRestarting);
  1117. }
  1118. }
  1119. else
  1120. {
  1121. loaderBase.Start(null, this.IsForceRestarting);
  1122. }
  1123. if (loaderBase.Block)
  1124. {
  1125. flag2 = true;
  1126. }
  1127. }
  1128. }
  1129. }
  1130. finally
  1131. {
  1132. List<ModLoader.LoaderBase>.Enumerator enumerator;
  1133. ((IDisposable)enumerator).Dispose();
  1134. }
  1135. if (flag)
  1136. {
  1137. base.RaisePreviewFinish();
  1138. base.State = ModBase.LoadState.Finished;
  1139. ModMain._ProcessIterator.BtnExtraDownload.ShowRefresh();
  1140. }
  1141. }
  1142. }
  1143. // Token: 0x06000CE5 RID: 3301 RVA: 0x00055D8C File Offset: 0x00053F8C
  1144. public static void GetLoaderList(object Loader, ref List<ModLoader.LoaderBase> List, bool RequireShow = true)
  1145. {
  1146. try
  1147. {
  1148. foreach (object obj in ((IEnumerable)NewLateBinding.LateGet(Loader, null, "Loaders", new object[0], null, null, null)))
  1149. {
  1150. object objectValue = RuntimeHelpers.GetObjectValue(obj);
  1151. if (Conversions.ToBoolean(Conversions.ToBoolean(NewLateBinding.LateGet(objectValue, null, "Show", new object[0], null, null, null)) || !RequireShow))
  1152. {
  1153. List.Add((ModLoader.LoaderBase)objectValue);
  1154. }
  1155. if (objectValue.GetType().Name.StartsWithF("LoaderCombo", false))
  1156. {
  1157. ModLoader.LoaderCombo<!0>.GetLoaderList(RuntimeHelpers.GetObjectValue(objectValue), ref List, true);
  1158. }
  1159. }
  1160. }
  1161. finally
  1162. {
  1163. IEnumerator enumerator;
  1164. if (enumerator is IDisposable)
  1165. {
  1166. (enumerator as IDisposable).Dispose();
  1167. }
  1168. }
  1169. }
  1170. // Token: 0x06000CE6 RID: 3302 RVA: 0x000086B9 File Offset: 0x000068B9
  1171. public void GetLoaderList(ref List<ModLoader.LoaderBase> List, bool RequireShow = true)
  1172. {
  1173. ModLoader.LoaderCombo<!0>.GetLoaderList(this, ref List, RequireShow);
  1174. }
  1175. // Token: 0x06000CE7 RID: 3303 RVA: 0x00055E58 File Offset: 0x00054058
  1176. public List<ModLoader.LoaderBase> GetLoaderList(bool RequireShow = true)
  1177. {
  1178. List<ModLoader.LoaderBase> result = new List<ModLoader.LoaderBase>();
  1179. this.GetLoaderList(ref result, RequireShow);
  1180. return result;
  1181. }
  1182. // Token: 0x0400067F RID: 1663
  1183. public List<ModLoader.LoaderBase> Loaders;
  1184. // Token: 0x04000680 RID: 1664
  1185. public InputType Input;
  1186. }
  1187. // Token: 0x0200012C RID: 300
  1188. private struct LoaderFolderDictionaryEntry
  1189. {
  1190. // Token: 0x06000CEA RID: 3306 RVA: 0x00055EC8 File Offset: 0x000540C8
  1191. public override bool Equals(object obj)
  1192. {
  1193. bool result;
  1194. if (!(obj is ModLoader.LoaderFolderDictionaryEntry))
  1195. {
  1196. result = false;
  1197. }
  1198. else
  1199. {
  1200. ModLoader.LoaderFolderDictionaryEntry loaderFolderDictionaryEntry = (ModLoader.LoaderFolderDictionaryEntry)obj;
  1201. result = (EqualityComparer<DateTime?>.Default.Equals(this.LastCheckTime, loaderFolderDictionaryEntry.LastCheckTime) && Operators.CompareString(this.FolderPath, loaderFolderDictionaryEntry.FolderPath, false) == 0);
  1202. }
  1203. return result;
  1204. }
  1205. // Token: 0x04000681 RID: 1665
  1206. public DateTime? LastCheckTime;
  1207. // Token: 0x04000682 RID: 1666
  1208. public string FolderPath;
  1209. }
  1210. // Token: 0x0200012D RID: 301
  1211. public enum LoaderFolderRunType
  1212. {
  1213. // Token: 0x04000684 RID: 1668
  1214. RunOnUpdated,
  1215. // Token: 0x04000685 RID: 1669
  1216. ForceRun,
  1217. // Token: 0x04000686 RID: 1670
  1218. UpdateOnly
  1219. }
  1220. }
  1221. }