From 29338c9cf9ef898aeb58633b11528070eff980d3 Mon Sep 17 00:00:00 2001 From: MapleWheels Date: Wed, 25 Oct 2023 01:47:18 -0400 Subject: [PATCH] - Added the option to have in-memory compiled assembly to gain access to internals. --- .../SharedSource/LuaCs/Plugins/CsPackageManager.cs | 6 ++++-- .../LuaCs/Plugins/MemoryFileAssemblyContextLoader.cs | 3 +++ .../SharedSource/LuaCs/Plugins/RunConfig.cs | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs index 6b9397e3bc..8b77c6e598 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs @@ -574,11 +574,13 @@ public AssemblyLoadingSuccessState LoadAssemblyPackages() // try compile successState = _assemblyManager.LoadAssemblyFromMemory( - pair.Key.Name.Replace(" ",""), + pair.Value.config.UseInternalAssemblyName ? "CompiledAssembly" : pair.Key.Name.Replace(" ",""), syntaxTrees, null, CompilationOptions, - pair.Key.Name, ref id, pair.Value.config.UseNonPublicizedAssemblies ? null : publicizedAssemblies); + pair.Key.Name, + ref id, + pair.Value.config.UseNonPublicizedAssemblies ? null : publicizedAssemblies); if (successState is not AssemblyLoadingSuccessState.Success) { diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/MemoryFileAssemblyContextLoader.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/MemoryFileAssemblyContextLoader.cs index 368b86e655..66d3bd0040 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/MemoryFileAssemblyContextLoader.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/MemoryFileAssemblyContextLoader.cs @@ -5,11 +5,14 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.Loader; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; // ReSharper disable ConditionIsAlwaysTrueOrFalse +[assembly: InternalsVisibleTo("CompiledAssembly")] + namespace Barotrauma; /// diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/RunConfig.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/RunConfig.cs index 079d3eb047..64bc660061 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/RunConfig.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/RunConfig.cs @@ -35,6 +35,13 @@ public sealed class RunConfig [XmlElement(ElementName = "UseNonPublicizedAssemblies")] public bool UseNonPublicizedAssemblies { get; set; } + /// + /// If the mod includes source files, the compiled assembly will be named "CompiledAssembly" and have the [InternalVisibleTo()] attribute applied to it. + /// + [XmlElement(ElementName = "UseInternalAssemblyName")] + [DefaultValue(false)] + public bool UseInternalAssemblyName { get; set; } + [XmlElement(ElementName = "AutoGenerated")] public bool AutoGenerated { get; set; }