diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-08-25 20:01:59 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-08-25 20:01:59 -0400 |
commit | 0b29eb3bc37553aa2e9776e17727ba07018606ea (patch) | |
tree | bb16cc4f680d04fda9db53ea22b818c2858e616f /src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | |
parent | e3b38a70f8d710af07732b325a6013ed18aa0fb0 (diff) | |
download | SMAPI-0b29eb3bc37553aa2e9776e17727ba07018606ea.tar.gz SMAPI-0b29eb3bc37553aa2e9776e17727ba07018606ea.tar.bz2 SMAPI-0b29eb3bc37553aa2e9776e17727ba07018606ea.zip |
minor refactoring in new symbol code
Diffstat (limited to 'src/SMAPI/Framework/ModLoading/AssemblyLoader.cs')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index 72cfd119..5180f072 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -35,8 +35,11 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>A minimal assembly definition resolver which resolves references to known loaded assemblies.</summary> private readonly AssemblyDefinitionResolver AssemblyDefinitionResolver; - private readonly SymbolReaderProvider SymbolReaderProvider; - private readonly SymbolWriterProvider SymbolWriterProvider; + /// <summary>Provides assembly symbol readers for Mono.Cecil.</summary> + private readonly SymbolReaderProvider SymbolReaderProvider = new SymbolReaderProvider(); + + /// <summary>Provides assembly symbol writers for Mono.Cecil.</summary> + private readonly SymbolWriterProvider SymbolWriterProvider = new SymbolWriterProvider(); /// <summary>The objects to dispose as part of this instance.</summary> private readonly HashSet<IDisposable> Disposables = new HashSet<IDisposable>(); @@ -65,9 +68,6 @@ namespace StardewModdingAPI.Framework.ModLoading this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver()); Constants.ConfigureAssemblyResolver(this.AssemblyDefinitionResolver); - this.SymbolReaderProvider = new SymbolReaderProvider(); - this.SymbolWriterProvider = new SymbolWriterProvider(); - // generate type => assembly lookup for types which should be rewritten this.TypeAssemblies = new Dictionary<string, Assembly>(); foreach (Assembly assembly in this.AssemblyMap.Targets) @@ -121,7 +121,7 @@ namespace StardewModdingAPI.Framework.ModLoading // rewrite assembly bool changed = this.RewriteAssembly(mod, assembly.Definition, loggedMessages, logPrefix: " "); - + // detect broken assembly reference foreach (AssemblyNameReference reference in assembly.Definition.MainModule.AssemblyReferences) { @@ -142,10 +142,10 @@ namespace StardewModdingAPI.Framework.ModLoading this.Monitor.Log($" Loading {assembly.File.Name} (rewritten)...", LogLevel.Trace); // load assembly - using MemoryStream outStream = new MemoryStream(); + using MemoryStream outAssemblyStream = new MemoryStream(); using MemoryStream outSymbolStream = new MemoryStream(); - assembly.Definition.Write(outStream, new WriterParameters() { WriteSymbols = true, SymbolStream = outSymbolStream, SymbolWriterProvider = this.SymbolWriterProvider } ); - byte[] bytes = outStream.ToArray(); + assembly.Definition.Write(outAssemblyStream, new WriterParameters { WriteSymbols = true, SymbolStream = outSymbolStream, SymbolWriterProvider = this.SymbolWriterProvider }); + byte[] bytes = outAssemblyStream.ToArray(); lastAssembly = Assembly.Load(bytes, outSymbolStream.ToArray()); } else @@ -233,13 +233,13 @@ namespace StardewModdingAPI.Framework.ModLoading if (!file.Exists) yield break; // not a local assembly - // read assembly and PDB (if present) + // read assembly and symbols byte[] assemblyBytes = File.ReadAllBytes(file.FullName); Stream readStream = this.TrackForDisposal(new MemoryStream(assemblyBytes)); { - string symbolsPath = Path.Combine(Path.GetDirectoryName(file.FullName), Path.GetFileNameWithoutExtension(file.FullName)) + ".pdb"; - if ( File.Exists( symbolsPath ) ) - this.SymbolReaderProvider.AddSymbolMapping( Path.GetFileName( file.FullName ), this.TrackForDisposal( new MemoryStream( File.ReadAllBytes( symbolsPath ) ) ) ); + FileInfo symbolsFile = new FileInfo(Path.Combine(Path.GetDirectoryName(file.FullName)!, Path.GetFileNameWithoutExtension(file.FullName)) + ".pdb"); + if (symbolsFile.Exists) + this.SymbolReaderProvider.TryAddSymbolData(file.Name, this.TrackForDisposal(symbolsFile.OpenRead())); } AssemblyDefinition assembly = this.TrackForDisposal(AssemblyDefinition.ReadAssembly(readStream, new ReaderParameters(ReadingMode.Immediate) { AssemblyResolver = assemblyResolver, InMemory = true, ReadSymbols = true, SymbolReaderProvider = this.SymbolReaderProvider })); |