diff options
Diffstat (limited to 'src/StardewModdingAPI/Program.cs')
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index ec3ccce7..45bf1238 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -13,7 +13,6 @@ using Newtonsoft.Json; using StardewModdingAPI.AssemblyRewriters; using StardewModdingAPI.Events; using StardewModdingAPI.Framework; -using StardewModdingAPI.Framework.AssemblyRewriting; using StardewModdingAPI.Framework.Models; using StardewModdingAPI.Inheritance; using StardewValley; @@ -41,9 +40,6 @@ namespace StardewModdingAPI /// <summary>The full path to the folder containing mods.</summary> private static readonly string ModPath = Path.Combine(Constants.ExecutionPath, "Mods"); - /// <summary>The name of the folder containing a mod's cached assembly data.</summary> - private static readonly string CacheDirName = ".cache"; - /// <summary>The log file to which to write messages.</summary> private static readonly LogFileManager LogFile = new LogFileManager(Constants.LogPath); @@ -319,7 +315,7 @@ namespace StardewModdingAPI Program.Monitor.Log("Loading mods..."); // get assembly loader - ModAssemblyLoader modAssemblyLoader = new ModAssemblyLoader(Program.CacheDirName, Program.TargetPlatform, Program.Monitor); + AssemblyLoader modAssemblyLoader = new AssemblyLoader(Program.TargetPlatform, Program.Monitor); AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => modAssemblyLoader.ResolveAssembly(e.Name); // get known incompatible mods @@ -342,10 +338,6 @@ namespace StardewModdingAPI { string directoryName = new DirectoryInfo(directory).Name; - // ignore internal directory - if (directoryName == ".cache") - continue; - // check for cancellation if (Program.CancellationTokenSource.IsCancellationRequested) { @@ -458,47 +450,29 @@ namespace StardewModdingAPI } } - // preprocess mod assemblies for compatibility - var processedAssemblies = new List<RewriteResult>(); + // validate mod path to simplify errors + string assemblyPath = Path.Combine(directory, manifest.EntryDll); + if (!File.Exists(assemblyPath)) { - bool succeeded = true; - foreach (string assemblyPath in Directory.GetFiles(directory, "*.dll")) - { - try - { - processedAssemblies.Add(modAssemblyLoader.ProcessAssemblyUnlessCached(assemblyPath)); - } - catch (Exception ex) - { - Program.Monitor.Log($"{errorPrefix}: an error occurred while preprocessing '{Path.GetFileName(assemblyPath)}'.\n{ex.GetLogSummary()}", LogLevel.Error); - succeeded = false; - break; - } - } - if (!succeeded) - continue; + Program.Monitor.Log($"{errorPrefix}: the entry DLL '{manifest.EntryDll}' does not exist.", LogLevel.Error); + continue; } - bool forceUseCachedAssembly = processedAssemblies.Any(p => p.UseCachedAssembly); // make sure DLLs are kept together for dependency resolution - if (processedAssemblies.Any(p => p.IsNewerThanCache)) - modAssemblyLoader.WriteCache(processedAssemblies, forceUseCachedAssembly); - // get entry assembly path - string mainAssemblyPath; + // preprocess & load mod assembly + Assembly modAssembly; + try { - RewriteResult mainProcessedAssembly = processedAssemblies.FirstOrDefault(p => p.OriginalAssemblyPath == Path.Combine(directory, manifest.EntryDll)); - if (mainProcessedAssembly == null) - { - Program.Monitor.Log($"{errorPrefix}: the specified mod DLL does not exist.", LogLevel.Error); - continue; - } - mainAssemblyPath = forceUseCachedAssembly ? mainProcessedAssembly.CachePaths.Assembly : mainProcessedAssembly.OriginalAssemblyPath; + modAssembly = modAssemblyLoader.Load(assemblyPath); + } + catch (Exception ex) + { + Program.Monitor.Log($"{errorPrefix}: an error occurred while preprocessing '{manifest.EntryDll}'.\n{ex.GetLogSummary()}", LogLevel.Error); + continue; } - // load entry assembly - Assembly modAssembly; + // validate assembly try { - modAssembly = Assembly.UnsafeLoadFrom(mainAssemblyPath); // unsafe load allows downloaded DLLs if (modAssembly.DefinedTypes.Count(x => x.BaseType == typeof(Mod)) == 0) { Program.Monitor.Log($"{errorPrefix}: the mod DLL does not contain an implementation of the 'Mod' class.", LogLevel.Error); @@ -507,11 +481,11 @@ namespace StardewModdingAPI } catch (Exception ex) { - Program.Monitor.Log($"{errorPrefix}: an error occurred while optimising the target DLL.\n{ex.GetLogSummary()}", LogLevel.Error); + Program.Monitor.Log($"{errorPrefix}: an error occurred while reading the mod DLL.\n{ex.GetLogSummary()}", LogLevel.Error); continue; } - // get mod instance + // initialise mod Mod mod; try { |