154 bool isLoadSucceed =
true;
155 Exception exception =
null;
176 Dictionary<string, Assembly[]> assemblies = [];
179 assemblies[modEntity.modInfo.PackageName] = modEntity.GetAssemblies();
180 foreach (Assembly assembly
in assemblies[modEntity.modInfo.PackageName]) {
182 Log.
Information($
"[{modEntity.modInfo.Name}] Getting assemblies.");
185 AssemblyName assemblyName = assembly.GetName();
186 string fullName = assemblyName.FullName;
187 if (
ModsManager.
Dlls.TryGetValue(fullName, out Assembly existingAssembly)) {
188 if (existingAssembly.GetName().Version < assemblyName.Version) {
201 if (!isLoadSucceed) {
204 foreach (Assembly
asm in assemblies[modEntity.modInfo.PackageName]) {
205 Log.
Information($
"[{modEntity.modInfo.Name}] Handling assembly [{asm.FullName}]");
207 modEntity.HandleAssembly(
asm);
209 catch (Exception e) {
211 string separator =
new(
'-', 10);
212 Log.
Error($
"{separator}Handle assembly failed{separator}");
214 $
"Loaded assembly:\n{string.Join("\n
", AppDomain.CurrentDomain.GetAssemblies().Select(x => x.FullName ?? x.GetName().FullName))}"
217 Log.
Error($
"Error assembly: {asm.FullName}");
218#pragma warning disable IL2026
219 Log.
Error($
"Dependencies:\n{string.Join("\n
", asm.GetReferencedAssemblies().Select(x => x.FullName))}");
220#pragma warning restore IL2026
223 isLoadSucceed =
false;
229 if (!isLoadSucceed) {
235 "Loading failed 加载失败",
236 [
"Exceptions: 异常信息:", ..exception?.ToString().Split(
'\n') ?? []],
238 $
"Check the API version required by mod is equal to the current API version ({ModsManager.APIVersionString}). Check and add missing mods. If not solved, please contact the developer of the mods or API with Game.log in the path below.",
239 $
"检查模组是否缺失,并添加所缺失的模组。查看模组所需插件版版本与当前插件版版本({ModsManager.APIVersionString})是否一致。若以上方式都无法解决,请联系模组、插件版开发者,并发送下面路径中的 Game.log",
241 "And you can enable Safe Mode to prevent loading any mod.",
242 "你还可以启用安全模式,防止加载任何模组。"
255 string fileName = Path.GetFileNameWithoutExtension(contentInfo.
Filename);
256 if (
string.IsNullOrEmpty(fileName)) {
263 CultureInfo cultureInfo =
new(fileName.EndsWith(
"-old") ? fileName.Substring(0, fileName.Length - 4) : fileName,
false);
279 if (
string.IsNullOrEmpty(systemLanguage)) {
282 Log.
Information(
"Language is not specified, and system language is not detected, en-US is loaded instead.");
286 Log.
Information($
"Language is not specified, system language ({systemLanguage}) is successfully loaded.");
289 bool languageNotLoaded =
true;
290 string[] systemLanguageArray = systemLanguage.Split(
'-');
291 switch (systemLanguageArray.Length) {
294 string[] cultureNameArray = cultureName.Split(
'-');
295 if (systemLanguage == cultureNameArray[0]) {
298 $
"Language is not specified, a language ({cultureName}) closest to system language ({systemLanguage}) is successfully loaded."
300 languageNotLoaded =
false;
308 string[] cultureNameArray = cultureName.Split(
'-');
309 if (systemLanguageArray[0] == cultureNameArray[0]) {
312 $
"Language is not specified, a language ({cultureName}) closest to system language ({systemLanguage}) is successfully loaded."
314 languageNotLoaded =
false;
320 if (languageNotLoaded) {
323 $
"Language is not specified, and system language ({systemLanguage}) is not supported yet, en-US is loaded instead."
335 if (
string.IsNullOrEmpty(systemLanguage)) {
338 Log.
Information(
"Language is not specified, and system language is not detected, en-US is loaded instead.");
342 Log.
Information($
"Language is not specified, system language ({systemLanguage}) is successfully loaded.");
345 bool languageNotLoaded =
true;
346 CultureInfo systemCultureInfoParent =
new CultureInfo(systemLanguage).Parent;
348 bool similar =
false;
349 CultureInfo parentCulture = cultureInfo.Parent;
350 string parentCultureName = cultureInfo.Name;
351 if (parentCultureName == systemLanguage
352 || parentCultureName == systemCultureInfoParent.Name
353 || parentCultureName == systemCultureInfoParent.Parent.Name) {
357 string rootCultureName = parentCulture.Parent.Name;
358 if (rootCultureName.Length > 0
359 && (rootCultureName == systemCultureInfoParent.Name
360 || rootCultureName == systemCultureInfoParent.Parent.Name)) {
367 $
"Language is not specified, a language ({cultureName}) closest to system language ({systemLanguage}) is successfully loaded."
369 languageNotLoaded =
false;
372 if (languageNotLoaded) {
375 $
"Language is not specified, and system language ({systemLanguage}) is not supported yet, en-US is loaded instead."
385 $
"{(SettingsManager.SafeMode ? $"[{
LanguageControl.
Get(
"Usual",
"safeMode")}]
" : "")}{LanguageControl.Get("Usual
", "gameName
")} {ModsManager.ShortGameVersion} - {LanguageControl.Get("Usual
", "api
")} {ModsManager.APIVersionString}";
387 title = $
"[{LanguageControl.Get("Usual
", "debug
")}]{title}";
405 List<Action> actions = [];
409 loader.OnLoadingStart(actions);
413 foreach (Action ac
in actions) {
433 catch (Exception e) {
440 Stopwatch stopwatch = Stopwatch.StartNew();
444 catch (Exception e) {
448 Info($
"{LanguageControl.Get(fName, "3
")}({stopwatch.ElapsedMilliseconds}ms)");
453 Stopwatch stopwatch = Stopwatch.StartNew();
456 Info($
"{LanguageControl.Get(fName, "4
")}({stopwatch.ElapsedMilliseconds}ms)");
484 if (modEntity.Loader !=
null) {
485 Info($
"[{modEntity.modInfo?.Name}] {LanguageControl.Get(fName, "6
")}");