From 17b304a349ecdad2476d8dba41758de0f0cc9eb9 Mon Sep 17 00:00:00 2001 From: MapleWheels Date: Thu, 26 Oct 2023 19:05:05 -0400 Subject: [PATCH] - Made it only load the barotrauma or dedicatedserver publicized dll. --- .../LuaCs/Plugins/CsPackageManager.cs | 92 ++++++++++--------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs index 77de3a722a..4ae563c26b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs @@ -12,6 +12,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using MonoMod.Utils; + // ReSharper disable InconsistentNaming namespace Barotrauma; @@ -71,6 +72,16 @@ public sealed class CsPackageManager : IDisposable .ToString(), ScriptParseOptions); + private readonly string[] _publicizedAssembliesToLoad = + { +#if CLIENT + "Barotrauma.dll" +#elif SERVER + "DedicatedServer.dll" +#endif + }; + + private const string SCRIPT_FILE_REGEX = "*.cs"; private const string ASSEMBLY_FILE_REGEX = "*.dll"; @@ -312,48 +323,22 @@ public AssemblyLoadingSuccessState LoadAssemblyPackages() } } } - - // load publicized assemblies - var publicizedDir = Path.Combine(Environment.CurrentDirectory, "Publicized"); - - // if using workshop lua setup is checked, try to use the publicized assemblies in the content package there instead. - if (_luaCsSetup.Config.PreferToUseWorkshopLuaSetup) - { - var pck = LuaCsSetup.GetPackage(LuaCsSetup.LuaForBarotraumaId); - if (pck is not null) - { - publicizedDir = Path.Combine(pck.Dir, "Binary", "Publicized"); - } - } - + ImmutableList publicizedAssemblies = ImmutableList.Empty; - ImmutableList list; - - try - { - // search for assemblies - list = Directory.GetFiles(publicizedDir, "*.dll") -#if CLIENT - .Where(s => !s.ToLowerInvariant().EndsWith("dedicatedserver.dll")) -#elif SERVER - .Where(s => !s.ToLowerInvariant().EndsWith("barotrauma.dll")) -#endif - .ToImmutableList(); + List publicizedAssembliesLocList = new(); - if (list.Count < 1) - throw new DirectoryNotFoundException("No publicized assemblies found."); + foreach (string dllName in _publicizedAssembliesToLoad) + { + GetFiles(publicizedAssembliesLocList, dllName); } - // no directory found, use the other one - catch (DirectoryNotFoundException) + + void GetFiles(List list, string searchQuery) { + var publicizedDir = Path.Combine(Environment.CurrentDirectory, "Publicized"); + + // if using workshop lua setup is checked, try to use the publicized assemblies in the content package there instead. if (_luaCsSetup.Config.PreferToUseWorkshopLuaSetup) { - ModUtils.Logging.PrintError($"Unable to find /Binary/Publicized/ . Using Game folder instead."); - publicizedDir = Path.Combine(Environment.CurrentDirectory, "Publicized"); - } - else - { - ModUtils.Logging.PrintError($"Unable to find /Publicized/ . Using LuaCsPackage folder instead."); var pck = LuaCsSetup.GetPackage(LuaCsSetup.LuaForBarotraumaId); if (pck is not null) { @@ -361,18 +346,35 @@ public AssemblyLoadingSuccessState LoadAssemblyPackages() } } - // search for assemblies - list = Directory.GetFiles(publicizedDir, "*.dll") -#if CLIENT - .Where(s => !s.ToLowerInvariant().EndsWith("dedicatedserver.dll")) -#elif SERVER - .Where(s => !s.ToLowerInvariant().EndsWith("barotrauma.dll")) -#endif - .ToImmutableList(); + try + { + list.AddRange(Directory.GetFiles(publicizedDir, searchQuery)); + } + // no directory found, use the other one + catch (DirectoryNotFoundException) + { + if (_luaCsSetup.Config.PreferToUseWorkshopLuaSetup) + { + ModUtils.Logging.PrintError($"Unable to find /Binary/Publicized/ . Using Game folder instead."); + publicizedDir = Path.Combine(Environment.CurrentDirectory, "Publicized"); + } + else + { + ModUtils.Logging.PrintError($"Unable to find /Publicized/ . Using LuaCsPackage folder instead."); + var pck = LuaCsSetup.GetPackage(LuaCsSetup.LuaForBarotraumaId); + if (pck is not null) + { + publicizedDir = Path.Combine(pck.Dir, "Binary", "Publicized"); + } + } + + // search for assemblies + list.AddRange(Directory.GetFiles(publicizedDir, searchQuery)); + } } // try load them into an acl - var loadState = _assemblyManager.LoadAssembliesFromLocations(list, "luacs_publicized_assemblies", ref _publicizedAssemblyLoader); + var loadState = _assemblyManager.LoadAssembliesFromLocations(publicizedAssembliesLocList, "luacs_publicized_assemblies", ref _publicizedAssemblyLoader); // loaded if (loadState is AssemblyLoadingSuccessState.Success)