Elin Decompiled Documentation EA 23.317 Nightly
Loading...
Searching...
No Matches
ModManager Class Reference
Inheritance diagram for ModManager:

Public Member Functions

override void Init (string path, string defaultPackage="_Elona")
 
void SaveLoadOrder ()
 
void LoadLoadOrder ()
 
IEnumerator RefreshMods (Action onComplete, bool syncMods)
 
ModPackage AddPackage (DirectoryInfo dir, bool isInPackages=false)
 
ModPackage AddWorkshopPackage (WorkshopItem item, bool isInPackages=false)
 
int CountUserMod ()
 
void LoadLocalPackages ()
 
void LoadCustomPackage ()
 
IEnumerator LoadWorkshopPackages ()
 
void InitPackagesMeta ()
 
void ActivatePackages ()
 
override void ParseExtra (DirectoryInfo dir, BaseModPackage package)
 

Public Attributes

List< FileInfo > replaceFiles = new List<FileInfo>()
 

Static Public Attributes

static List< object > ListPluginObject = new List<object>()
 
static bool disableMod
 

Properties

static List< string > ListChainLoad [get]
 
static DirectoryInfo DirWorkshop [get]
 
static new ModManager Instance [get]
 
static bool IsInitialized [get]
 

Private Member Functions

IEnumerator UpdateWorkshopPackages ()
 

Private Attributes

LoadingScreen _loading
 

Detailed Description

Definition at line 13 of file ModManager.cs.

Member Function Documentation

◆ ActivatePackages()

void ModManager.ActivatePackages ( )
inline

Definition at line 327 of file ModManager.cs.

328 {
330 ListPluginObject.Clear();
331 foreach (ModPackage package in packages)
332 {
333 if ((disableMod && !package.builtin) || !package.IsValidVersion())
334 {
335 continue;
336 }
337 try
338 {
339 package.Activate();
340 if (package.activated)
341 {
342 BaseModManager.listChainLoad.Add(package.dirInfo.FullName);
343 }
344 }
345 catch (Exception ex)
346 {
347 _loading.Log("Failed to activate mod: " + package.title + ", reason: " + ex.Message);
348 }
349 }
350 ModUtil.OnModsActivated();
351 ModUtil.LoadTypeFallback();
352 }
static List< string > listChainLoad
Text Log(string s)
LoadingScreen _loading
Definition: ModManager.cs:19
static bool disableMod
Definition: ModManager.cs:17
static List< object > ListPluginObject
Definition: ModManager.cs:15

References _loading, disableMod, BaseModManager.listChainLoad, ListPluginObject, and LoadingScreen.Log().

Referenced by RefreshMods().

◆ AddPackage()

ModPackage ModManager.AddPackage ( DirectoryInfo  dir,
bool  isInPackages = false 
)
inline

Definition at line 159 of file ModManager.cs.

160 {
161 ModPackage modPackage = new ModPackage
162 {
163 dirInfo = new DirectoryInfo(dir.FullName.NormalizePath()),
164 installed = true,
165 isInPackages = isInPackages,
166 loadPriority = priorityIndex,
167 Mapping = new FileMapping(dir)
168 };
169 packages.Add(modPackage);
170 priorityIndex++;
171 return modPackage;
172 }

References installed.

Referenced by AddWorkshopPackage(), LoadLocalPackages(), LayerMod.OnInit(), and RefreshMods().

◆ AddWorkshopPackage()

ModPackage ModManager.AddWorkshopPackage ( WorkshopItem  item,
bool  isInPackages = false 
)
inline

Definition at line 174 of file ModManager.cs.

175 {
176 ulong sizeOnDisk;
177 string folderPath;
178 DateTime timeStamp;
179 bool itemInstallInfo = UserGeneratedContent.Client.GetItemInstallInfo(item.FileId, out sizeOnDisk, out folderPath, out timeStamp);
180 DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
181 if (!directoryInfo.Exists)
182 {
183 return null;
184 }
185 ModPackage modPackage = AddPackage(directoryInfo, isInPackages);
186 modPackage.installed = itemInstallInfo;
187 modPackage.banned = item.IsBanned;
188 modPackage.workshopId = item.FileId.ToString();
189 return modPackage;
190 }
ModPackage AddPackage(DirectoryInfo dir, bool isInPackages=false)
Definition: ModManager.cs:159

References AddPackage(), and item.

Referenced by LoadWorkshopPackages().

◆ CountUserMod()

int ModManager.CountUserMod ( )
inline

Definition at line 192 of file ModManager.cs.

193 {
194 return packages.Count((BaseModPackage p) => !p.builtin);
195 }

References BaseModPackage.builtin.

Referenced by LayerTitle.OnClickContinue(), and LayerTitle.OnClickStart().

◆ Init()

override void ModManager.Init ( string  path,
string  defaultPackage = "_Elona" 
)
inline

Definition at line 31 of file ModManager.cs.

32 {
33 base.Init(path, defaultPackage);
34 Debug.Log("IsOffline:" + BaseCore.IsOffline);
35 IniData elinIni = Core.GetElinIni();
36 if (elinIni != null)
37 {
39 {
40 string key = elinIni.GetKey("path_workshop");
41 if (!key.IsEmpty())
42 {
43 dirWorkshop = new DirectoryInfo(key);
44 }
45 }
46 else
47 {
48 string path2 = Path.Combine(App.Client.GetAppInstallDirectory(SteamSettings.behaviour.settings.applicationId), "../../workshop/content/2135150");
49 dirWorkshop = new DirectoryInfo(path2);
50 elinIni.Global["path_workshop"] = dirWorkshop.FullName;
51 Core.SaveElinIni(elinIni);
52 }
53 }
54 if ((!(dirWorkshop?.Exists)) ?? true)
55 {
56 dirWorkshop = null;
57 }
58 Debug.Log("Workshop:" + dirWorkshop);
59 Debug.Log("Packages:" + BaseModManager.rootMod);
60 Debug.Log("Core Mod:" + BaseModManager.rootDefaultPacakge);
61 }
static bool IsOffline
Definition: BaseCore.cs:9
static string rootDefaultPacakge
static string rootMod
Definition: Core.cs:14
static void SaveElinIni(IniData ini)
Definition: Core.cs:814
static IniData GetElinIni()
Definition: Core.cs:780

References Debug, Core.GetElinIni(), BaseCore.IsOffline, BaseModManager.rootDefaultPacakge, BaseModManager.rootMod, and Core.SaveElinIni().

Referenced by CoreDebug.RegenerateNames(), and Core.StartCase().

◆ InitPackagesMeta()

void ModManager.InitPackagesMeta ( )
inline

Definition at line 307 of file ModManager.cs.

308 {
309 foreach (BaseModPackage package in packages)
310 {
311 try
312 {
313 if (package.Init())
314 {
315 mappedPackages[package.id] = package as ModPackage;
316 }
317 _loading?.Log(package.ToString());
318 }
319 catch (Exception ex)
320 {
321 package.willActivate = false;
322 _loading?.Log("Mod " + package.title + "/" + package.id + " has failed to initialize, reason: " + ex.Message);
323 }
324 }
325 }

References _loading, BaseModPackage.id, BaseModPackage.Init(), LoadingScreen.Log(), and BaseModPackage.title.

Referenced by RefreshMods().

◆ LoadCustomPackage()

void ModManager.LoadCustomPackage ( )
inline

Definition at line 219 of file ModManager.cs.

220 {
221 _loading.Log("Loading user Custom...");
222 DirectoryInfo[] directories = new DirectoryInfo(CorePath.custom).GetDirectories();
223 ModPackage package = new ModPackage();
224 DirectoryInfo[] array = directories;
225 foreach (DirectoryInfo dir in array)
226 {
227 ParseExtra(dir, package);
228 }
229 }
static string custom
Definition: CorePath.cs:159

References _loading, CorePath.custom, and LoadingScreen.Log().

Referenced by RefreshMods().

◆ LoadLoadOrder()

void ModManager.LoadLoadOrder ( )
inline

Definition at line 74 of file ModManager.cs.

75 {
76 string path = CorePath.rootExe + "loadorder.txt";
77 if (!File.Exists(path))
78 {
79 return;
80 }
81 Dictionary<string, BaseModPackage> dictionary = new Dictionary<string, BaseModPackage>();
82 foreach (BaseModPackage package in packages)
83 {
84 if (!package.builtin)
85 {
86 dictionary[package.dirInfo.FullName] = package;
87 }
88 }
89 int num = 0;
90 string[] array = File.ReadAllLines(path);
91 for (int i = 0; i < array.Length; i++)
92 {
93 string[] array2 = array[i].Split(',');
94 if (dictionary.TryGetValue(array2[0], out var value))
95 {
96 value.loadPriority = num;
97 value.willActivate = array2[1] == "1";
98 }
99 num++;
100 }
101 }
DirectoryInfo dirInfo

References BaseModPackage.builtin, and BaseModPackage.dirInfo.

Referenced by RefreshMods().

◆ LoadLocalPackages()

void ModManager.LoadLocalPackages ( )
inline

Definition at line 197 of file ModManager.cs.

198 {
199 _loading.Log("Loading local Package...");
200 DirectoryInfo[] directories = new DirectoryInfo(BaseModManager.rootMod).GetDirectories();
201 Array.Reverse(directories);
202 DirectoryInfo[] array = directories;
203 foreach (DirectoryInfo directoryInfo in array)
204 {
205 if (!disableMod || !(directoryInfo.Name != "_Elona") || !(directoryInfo.Name != "_Lang_Chinese"))
206 {
207 if (directoryInfo.Name == "Mod_FixedPackageLoader")
208 {
209 IO.DeleteDirectory(directoryInfo.FullName);
210 }
211 else
212 {
213 AddPackage(directoryInfo, isInPackages: true);
214 }
215 }
216 }
217 }
Definition: IO.cs:10
static void DeleteDirectory(string path)
Definition: IO.cs:392

References _loading, AddPackage(), disableMod, LoadingScreen.Log(), and BaseModManager.rootMod.

Referenced by RefreshMods().

◆ LoadWorkshopPackages()

IEnumerator ModManager.LoadWorkshopPackages ( )
inline

Definition at line 231 of file ModManager.cs.

232 {
233 WaitForEndOfFrame awaiter = new WaitForEndOfFrame();
234 UgcQuery activeQuery = UgcQuery.GetSubscribed(withLongDescription: false, withMetadata: false, withKeyValueTags: false, withAdditionalPreviews: false, 0u);
235 activeQuery.Execute(HandleWorkshopQuery);
236 _loading.Log("Fetching subscriptions...(Hit ESC to cancel)");
237 while (activeQuery.handle != UGCQueryHandle_t.Invalid && !UnityEngine.Input.GetKey(KeyCode.Escape))
238 {
239 yield return awaiter;
240 }
241 yield return UpdateWorkshopPackages();
242 void HandleWorkshopQuery(UgcQuery query)
243 {
244 foreach (WorkshopItem results in query.ResultsList)
245 {
246 AddWorkshopPackage(results);
247 }
248 }
249 }
ModPackage AddWorkshopPackage(WorkshopItem item, bool isInPackages=false)
Definition: ModManager.cs:174
IEnumerator UpdateWorkshopPackages()
Definition: ModManager.cs:251

References _loading, AddWorkshopPackage(), LoadingScreen.Log(), and UpdateWorkshopPackages().

Referenced by RefreshMods().

◆ ParseExtra()

override void ModManager.ParseExtra ( DirectoryInfo  dir,
BaseModPackage  package 
)
inline

Definition at line 354 of file ModManager.cs.

355 {
356 ModPackage modPackage = (ModPackage)package;
357 switch (dir.Name)
358 {
359 case "TalkText":
360 modPackage.ParseTalkText(dir);
361 break;
362 case "Map":
363 if (!package.builtin)
364 {
365 modPackage.ParseMap(dir);
366 }
367 break;
368 case "Map Piece":
369 if (!package.builtin)
370 {
371 modPackage.ParseMapPiece(dir);
372 }
373 break;
374 case "Texture Replace":
375 replaceFiles.AddRange(modPackage.ParseTextureReplace(dir));
376 break;
377 case "Texture":
378 modPackage.ParseTexture(dir);
379 break;
380 case "Portrait":
381 modPackage.ParsePortrait(dir);
382 break;
383 case "LangMod":
384 modPackage.ParseLangMod(dir);
385 break;
386 case "Sound":
387 modPackage.ParseSound(dir);
388 break;
389 case "Lang":
390 modPackage.AddOrUpdateLang(dir);
391 break;
392 }
393 }
List< FileInfo > replaceFiles
Definition: ModManager.cs:21
IReadOnlyList< FileInfo > ParseTalkText(DirectoryInfo dir)
Definition: ModPackage.cs:26
void ParseLangMod(DirectoryInfo dir)
Definition: ModPackage.cs:161
IReadOnlyList< FileInfo > ParseTexture(DirectoryInfo dir)
Definition: ModPackage.cs:103
void AddOrUpdateLang(DirectoryInfo dir)
Definition: ModPackage.cs:334
IReadOnlyList< FileInfo > ParseMapPiece(DirectoryInfo dir, bool addToList=true)
Definition: ModPackage.cs:65
IReadOnlyList< FileInfo > ParseTextureReplace(DirectoryInfo dir)
Definition: ModPackage.cs:86
IReadOnlyList< FileInfo > ParsePortrait(DirectoryInfo dir)
Definition: ModPackage.cs:123
IReadOnlyList< FileInfo > ParseMap(DirectoryInfo dir, bool addToList=true)
Definition: ModPackage.cs:44
IReadOnlyList< FileInfo > ParseSound(DirectoryInfo dir)
Definition: ModPackage.cs:176

References ModPackage.AddOrUpdateLang(), BaseModPackage.builtin, ModPackage.ParseLangMod(), ModPackage.ParseMap(), ModPackage.ParseMapPiece(), ModPackage.ParsePortrait(), ModPackage.ParseSound(), ModPackage.ParseTalkText(), ModPackage.ParseTexture(), ModPackage.ParseTextureReplace(), and replaceFiles.

◆ RefreshMods()

IEnumerator ModManager.RefreshMods ( Action  onComplete,
bool  syncMods 
)
inline

Definition at line 103 of file ModManager.cs.

104 {
105 bool flag = !BaseCore.IsOffline && syncMods && UserGeneratedContent.Client.GetNumSubscribedItems() != 0;
106 _loading = Util.Instantiate<LoadingScreen>("LoadingScreen");
107 WaitForEndOfFrame awaiter = new WaitForEndOfFrame();
108 packages.Clear();
109 disableMod |= Application.isEditor && EClass.debug.skipMod;
112 if (!disableMod)
113 {
114 _loading.Log("Loading workshop contents...");
115 if (flag)
116 {
117 yield return LoadWorkshopPackages();
118 }
119 else if (dirWorkshop != null)
120 {
121 DirectoryInfo[] directories = dirWorkshop.GetDirectories();
122 foreach (DirectoryInfo dir in directories)
123 {
124 AddPackage(dir);
125 }
126 }
127 }
130 packages.Sort((BaseModPackage a, BaseModPackage b) => a.loadPriority - b.loadPriority);
131 foreach (BaseModPackage item in packages.Where((BaseModPackage p) => !p.isInPackages && p.willActivate && !p.id.IsEmpty()))
132 {
133 if (mappedPackages.TryGetValue(item.id, out var value) && value.isInPackages)
134 {
135 value.hasPublishedPackage = true;
136 }
137 }
138 _loading.Log($"Total number of mods:{packages.Count}");
139 _loading.Log("Activating Mods...");
140 yield return awaiter;
142 foreach (BaseModPackage package in packages)
143 {
144 if (package.activated)
145 {
146 mappedPackages[package.id] = package as ModPackage;
147 }
148 }
149 BaseModManager.isInitialized = true;
150 yield return awaiter;
151 onComplete?.Invoke();
152 if ((bool)_loading)
153 {
154 UnityEngine.Object.Destroy(_loading.gameObject);
155 }
156 yield return null;
157 }
$
Definition: ModManager.cs:74
bool skipMod
Definition: CoreDebug.cs:149
Definition: EClass.cs:6
static CoreDebug debug
Definition: EClass.cs:49
void ActivatePackages()
Definition: ModManager.cs:327
void LoadLoadOrder()
Definition: ModManager.cs:74
void LoadCustomPackage()
Definition: ModManager.cs:219
IEnumerator LoadWorkshopPackages()
Definition: ModManager.cs:231
void LoadLocalPackages()
Definition: ModManager.cs:197
void InitPackagesMeta()
Definition: ModManager.cs:307
Definition: Util.cs:10
static Transform Instantiate(string path, Component parent=null)
Definition: Util.cs:67

References $, _loading, BaseModPackage.activated, ActivatePackages(), AddPackage(), EClass.debug, disableMod, BaseModPackage.id, InitPackagesMeta(), BaseModPackage.isInPackages, item, LoadCustomPackage(), LoadLoadOrder(), LoadLocalPackages(), BaseModPackage.loadPriority, LoadWorkshopPackages(), LoadingScreen.Log(), CoreDebug.skipMod, Util, and BaseModPackage.willActivate.

Referenced by Core.StartCase().

◆ SaveLoadOrder()

void ModManager.SaveLoadOrder ( )
inline

Definition at line 63 of file ModManager.cs.

64 {
65 if (!disableMod)
66 {
67 List<string> contents = (from p in packages
68 where !p.builtin && p.dirInfo.Exists
69 select $"{p.dirInfo.FullName},{(p.willActivate ? 1 : 0)}").ToList();
70 File.WriteAllLines(CorePath.rootExe + "loadorder.txt", contents);
71 }
72 }
static string rootExe
Definition: CorePath.cs:168

References $, disableMod, and CorePath.rootExe.

Referenced by LayerMod.Move(), LayerMod.OnInit(), and LayerMod.OnKill().

◆ UpdateWorkshopPackages()

IEnumerator ModManager.UpdateWorkshopPackages ( )
inlineprivate

Definition at line 251 of file ModManager.cs.

252 {
253 _loading?.Log("Updating subscriptions...");
254 WaitForEndOfFrame awaiter = new WaitForEndOfFrame();
255 while (true)
256 {
257 bool flag = false;
258 foreach (BaseModPackage item in packages.Where((BaseModPackage p) => !p.installed))
259 {
260 if (!(item.item is WorkshopItem { IsBanned: false } workshopItem))
261 {
262 continue;
263 }
264 flag = true;
265 string text = "Downloading " + workshopItem.Title + ": ";
266 BaseModPackage baseModPackage = item;
267 if ((object)baseModPackage.progressText == null)
268 {
269 baseModPackage.progressText = _loading?.Log(text);
270 }
271 if (item.downloadStarted && workshopItem.DownloadCompletion >= 1f)
272 {
273 item.installed = true;
274 if ((bool)item.progressText)
275 {
276 item.progressText.text = text + "Done!";
277 }
278 }
279 else if (workshopItem.IsDownloading || workshopItem.IsDownloadPending)
280 {
281 int num = Mathf.FloorToInt(workshopItem.DownloadCompletion * 100f);
282 if ((bool)item.progressText)
283 {
284 item.progressText.text = text + num + "%";
285 }
286 }
287 else if (!item.downloadStarted)
288 {
289 item.downloadStarted = true;
290 workshopItem.DownloadItem(highPriority: true);
291 Debug.Log("Start downloading: " + workshopItem.Title + " | " + $"Installed={workshopItem.IsInstalled}, " + $"Downloading={workshopItem.IsDownloading}, " + $"Pending={workshopItem.IsDownloadPending}");
292 }
293 }
294 if (!flag)
295 {
296 yield break;
297 }
298 if (UnityEngine.Input.GetKey(KeyCode.Escape))
299 {
300 break;
301 }
302 yield return awaiter;
303 }
304 Debug.Log("Workshop updating cancelled");
305 }

References $, _loading, Debug, BaseModPackage.installed, item, LoadingScreen.Log(), and BaseModPackage.progressText.

Referenced by LoadWorkshopPackages().

Member Data Documentation

◆ _loading

◆ disableMod

bool ModManager.disableMod
static

◆ ListPluginObject

List<object> ModManager.ListPluginObject = new List<object>()
static

Definition at line 15 of file ModManager.cs.

Referenced by ActivatePackages(), and Core.StartCase().

◆ replaceFiles

List<FileInfo> ModManager.replaceFiles = new List<FileInfo>()

Definition at line 21 of file ModManager.cs.

Referenced by TextureManager.Init(), and ParseExtra().

Property Documentation

◆ DirWorkshop

DirectoryInfo ModManager.DirWorkshop
staticget

Definition at line 25 of file ModManager.cs.

◆ Instance

new ModManager ModManager.Instance
staticget

Definition at line 27 of file ModManager.cs.

◆ IsInitialized

bool ModManager.IsInitialized
staticget

Definition at line 29 of file ModManager.cs.

Referenced by Core.StartCase().

◆ ListChainLoad

List<string> ModManager.ListChainLoad
staticget

Definition at line 23 of file ModManager.cs.


The documentation for this class was generated from the following file: