2using System.Collections;
3using System.Collections.Generic;
6using HeathenEngineering.SteamworksIntegration;
7using HeathenEngineering.SteamworksIntegration.API;
34 public override void Init(
string path,
string defaultPackage =
"_Elona")
36 base.Init(path, defaultPackage);
43 string key = elinIni.GetKey(
"path_workshop");
46 dirWorkshop =
new DirectoryInfo(key);
51 string path2 = Path.Combine(App.Client.GetAppInstallDirectory(SteamSettings.behaviour.settings.applicationId),
"../../workshop/content/2135150");
52 dirWorkshop =
new DirectoryInfo(path2);
53 elinIni.Global[
"path_workshop"] = dirWorkshop.FullName;
57 if (!dirWorkshop.Exists)
61 Debug.Log(
"Workshop:" + dirWorkshop);
66 if (ModManagerCore.useLocalizations)
68 ImportSourceLocalizations(lang as string);
78 List<string> contents = (from p in packages
79 where !p.builtin && p.dirInfo.Exists
80 select
$"{p.dirInfo.FullName},{(p.willActivate ? 1 : 0)}").ToList();
87 string path = CorePath.rootExe +
"loadorder.txt";
88 if (!File.Exists(path))
92 Dictionary<string, BaseModPackage> dictionary =
new Dictionary<string, BaseModPackage>();
97 dictionary[package.
dirInfo.FullName] = package;
101 string[] array = File.ReadAllLines(path);
102 for (
int i = 0; i < array.Length; i++)
104 string[] array2 = array[i].Split(
',');
105 if (dictionary.TryGetValue(array2[0], out var value))
107 value.loadPriority = num;
108 value.willActivate = array2[1] ==
"1";
116 string text = lang +
"/SourceLocalization.json";
117 (FileInfo file, EMod package)[] filesEx = PackageIterator.GetFilesEx(text);
118 SortedDictionary<string, string> sortedDictionary =
new SortedDictionary<string, string>();
119 Dictionary<string, SortedDictionary<string, string>> dictionary =
new Dictionary<string, SortedDictionary<string, string>>();
120 (FileInfo, EMod)[] array = filesEx;
123 for (
int i = 0; i < array.Length; i++)
125 var (fileInfo, eMod) = array[i];
128 SortedDictionary<string, string> sortedDictionary2 = IO.LoadFile<SortedDictionary<string, string>>(fileInfo.FullName);
129 foreach (KeyValuePair<string, string>
item in sortedDictionary2)
131 item.Deconstruct(out key, out value);
133 string value2 = value;
134 sortedDictionary[key2] = value2;
136 dictionary[eMod.id] = sortedDictionary2;
138 catch (Exception arg)
140 Debug.LogError(
$"#source localization failed to load {fileInfo.ShortPath()}\n{arg}");
143 JsonSerializerSettings setting =
new JsonSerializerSettings
145 PreserveReferencesHandling = PreserveReferencesHandling.None,
146 NullValueHandling = NullValueHandling.Ignore
148 foreach (EMod value4
in base.MappedPackages.Values)
150 if (!(value4 is
ModPackage modPackage) || value4.builtin || !value4.activated)
155 if (sourceRows ==
null || sourceRows.Count <= 0)
159 modPackage.ImportSourceLocalizations(sortedDictionary);
160 if (!ModManagerCore.generateLocalizations || (!modPackage.isInPackages && !Application.isEditor))
170 SortedDictionary<string, string> sortedDictionary3 = dictionary.GetValueOrDefault(modPackage.id) ??
new SortedDictionary<string, string>();
171 SortedDictionary<string, string> sortedDictionary4 = modPackage.ExportSourceLocalizations();
172 SortedDictionary<string, string>
final =
new SortedDictionary<string, string>();
173 foreach (KeyValuePair<string, string> item2
in sortedDictionary4)
175 item2.Deconstruct(out value, out key);
177 string defaultValue = key;
178 final[key3] = sortedDictionary3.GetValueOrDefault(key3, defaultValue);
180 if (sortedDictionary3.Count !=
final.Count || sortedDictionary3.Any((KeyValuePair<string, string> kv) => !
final.TryGetValue(kv.Key, out var value3) || value3 != kv.Value))
182 IO.SaveFile(Path.Combine(modPackage.dirInfo.FullName,
"LangMod", text),
final, compress:
false, setting);
183 Debug.Log(
$"#source localization updated {text} / {modPackage}");
186 catch (Exception arg2)
188 Debug.LogError(
$"#source localization failed to generate {modPackage}\n{arg2}");
197 SourceCache.InvalidateCacheVersion();
201 EClass.sources.materials
203 List<string> list =
new List<string>();
204 foreach (EMod value
in base.MappedPackages.Values)
206 if (value.builtin || !value.activated)
210 foreach (FileInfo sourceSheet
in value.Mapping.SourceSheets)
212 if (!sourceSheet.Name.StartsWith(
".") && !sourceSheet.Name.Contains(
"~"))
215 list.Add(sourceSheet.FullName);
220 SourceCache.FinalizeCache();
221 SourceCache.InvalidateCacheBlobs();
222 SourceCache.ClearDetail();
224 catch (Exception message)
226 Debug.LogError(message);
228 Debug.Log(
"#source finished importing workbooks");
233 Lang.extraExcelDialogs =
new HashSet<string>(PathComparer.Default);
234 Lang.excelDialog =
null;
235 FileInfo[] files = PackageIterator.GetFiles(
"Dialog/dialog.xlsx");
236 foreach (FileInfo fileInfo
in files)
239 Debug.Log(
"#dialog loaded " + fileInfo.ShortPath());
250 foreach (
ExcelData item in from f
in PackageIterator.GetFiles(
"Data/god_talk.xlsx")
253 foreach (KeyValuePair<
string, Dictionary<string, string>> item2
in map)
255 item2.Deconstruct(out var key, out var _);
261 Dictionary<string, string> valueOrDefault =
item.sheets[
"_default"].map.GetValueOrDefault(text);
262 if (valueOrDefault ==
null)
266 foreach (KeyValuePair<string, string> item3
in valueOrDefault)
268 item3.Deconstruct(out key, out var value2);
270 string value3 = value2;
273 map[text][text2] = value3;
277 Debug.Log(
"#dialog loaded " +
item.path.ShortPath());
283 bool flag = !BaseCore.IsOffline && syncMods && UserGeneratedContent.Client.GetNumSubscribedItems() != 0;
285 WaitForEndOfFrame awaiter =
new WaitForEndOfFrame();
297 else if (dirWorkshop !=
null)
299 DirectoryInfo[] directories = dirWorkshop.GetDirectories();
300 foreach (DirectoryInfo dir
in directories)
311 if (mappedPackages.TryGetValue(
item.id, out var value) && value.isInPackages)
313 value.hasPublishedPackage =
true;
318 yield
return awaiter;
324 mappedPackages[package.
id] =
package as ModPackage;
327 BaseModManager.isInitialized =
true;
328 yield
return awaiter;
329 onComplete?.Invoke();
332 UnityEngine.Object.Destroy(
_loading.gameObject);
343 isInPackages = isInPackages,
344 loadPriority = priorityIndex,
345 Mapping =
new FileMapping(dir)
347 packages.Add(modPackage);
357 bool itemInstallInfo = UserGeneratedContent.Client.GetItemInstallInfo(
item.FileId, out sizeOnDisk, out folderPath, out timeStamp);
358 DirectoryInfo dir =
new DirectoryInfo(folderPath);
360 modPackage.installed = itemInstallInfo;
361 modPackage.banned =
item.IsBanned;
374 Array.Reverse(directories);
375 DirectoryInfo[] array = directories;
376 foreach (DirectoryInfo directoryInfo
in array)
378 if (!
disableMod || !(directoryInfo.Name !=
"_Elona") || !(directoryInfo.Name !=
"_Lang_Chinese"))
380 AddPackage(directoryInfo, isInPackages:
true);
388 DirectoryInfo[] directories =
new DirectoryInfo(
CorePath.
custom).GetDirectories();
390 DirectoryInfo[] array = directories;
391 foreach (DirectoryInfo dir
in array)
393 ParseExtra(dir, package);
399 WaitForEndOfFrame awaiter =
new WaitForEndOfFrame();
400 UgcQuery activeQuery = UgcQuery.GetSubscribed(withLongDescription:
false, withMetadata:
false, withKeyValueTags:
false, withAdditionalPreviews:
false, 0u);
401 activeQuery.Execute(HandleWorkshopQuery);
402 _loading.
Log(
"Fetching subscriptions...(Hit ESC to cancel)");
403 while (activeQuery.handle != UGCQueryHandle_t.Invalid && !UnityEngine.Input.GetKey(KeyCode.Escape))
405 yield
return awaiter;
408 void HandleWorkshopQuery(UgcQuery query)
410 foreach (WorkshopItem results
in query.ResultsList)
420 WaitForEndOfFrame awaiter =
new WaitForEndOfFrame();
426 if (!(
item.item is WorkshopItem { IsBanned: false } workshopItem))
431 string text =
"Downloading " + workshopItem.Title +
": ";
437 if (
item.downloadStarted && workshopItem.DownloadCompletion >= 1f)
439 item.installed =
true;
440 if ((
bool)
item.progressText)
442 item.progressText.text = text +
"Done!";
445 else if (workshopItem.IsDownloading || workshopItem.IsDownloadPending)
447 int num = Mathf.FloorToInt(workshopItem.DownloadCompletion * 100f);
448 if ((
bool)
item.progressText)
450 item.progressText.text = text + num +
"%";
453 else if (!
item.downloadStarted)
455 item.downloadStarted =
true;
456 workshopItem.DownloadItem(highPriority:
true);
457 Debug.Log(
"Start downloading: " + workshopItem.Title +
" | " +
$"Installed={workshopItem.IsInstalled}, " +
$"Downloading={workshopItem.IsDownloading}, " +
$"Pending={workshopItem.IsDownloadPending}");
464 if (UnityEngine.Input.GetKey(KeyCode.Escape))
468 yield
return awaiter;
470 Debug.Log(
"Workshop updating cancelled");
480 mappedPackages[package.
id] =
package as ModPackage;
481 _loading?.
Log(package.ToString());
485 package.willActivate =
false;
486 _loading?.
Log(
"Mod " + package.
title +
"/" + package.
id +
" has failed to initialize, reason: " + ex.Message);
497 if ((
disableMod && !package.builtin) || !package.IsValidVersion())
504 if (package.activated)
511 _loading.
Log(
"Failed to activate mod: " + package.title +
", reason: " + ex.Message);
538 case "Texture Replace":
static bool isInitialized
static string rootDefaultPacakge
static BaseModManager Instance
static List< string > listChainLoad
static void SubscribeEvent(string eventId, Action< object > handler)
static void SaveElinIni(IniData ini)
static IniData GetElinIni()
static SourceManager sources
Dictionary< string, Sheet > sheets
static LangSetting setting
static bool IsBuiltin(string id)
static HashSet< string > extraExcelDialogs
void ImportAllModSourceSheets()
static new ModManager Instance
override void ParseExtra(DirectoryInfo dir, BaseModPackage package)
void ImportAllModDialogs()
static bool IsInitialized
void ImportSourceLocalizations(string lang)
static List< string > ListChainLoad
List< FileInfo > replaceFiles
void ImportAllModGodTalks()
ModPackage AddWorkshopPackage(WorkshopItem item, bool isInPackages=false)
IEnumerator UpdateWorkshopPackages()
override void Init(string path, string defaultPackage="_Elona")
IEnumerator RefreshMods(Action onComplete, bool syncMods)
IEnumerator LoadWorkshopPackages()
ModPackage AddPackage(DirectoryInfo dir, bool isInPackages=false)
static List< object > ListPluginObject
static DirectoryInfo DirWorkshop
IReadOnlyList< FileInfo > ParseTalkText(DirectoryInfo dir)
void ParseLangMod(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParseTexture(DirectoryInfo dir)
void AddOrUpdateLang(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParseMapPiece(DirectoryInfo dir, bool addToList=true)
IReadOnlyList< FileInfo > ParseTextureReplace(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParsePortrait(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParseMap(DirectoryInfo dir, bool addToList=true)
IReadOnlyList< FileInfo > ParseSound(DirectoryInfo dir)
static SourceImporter sourceImporter
static void OnModsActivated()
static void LoadTypeFallback()
IEnumerable< SourceData > ImportFilesCached(IEnumerable< string > imports, bool resetData=true)
static void HotInit(IEnumerable< SourceData > sourceData)
Dictionary< string, EMod > fileProviders