From 9ccf157193d8ee4a79f1d6fee2df013053cb1a08 Mon Sep 17 00:00:00 2001 From: MapleWheels Date: Fri, 29 Sep 2023 03:51:05 -0400 Subject: [PATCH] Changed publicized assembly discovery to fallback to the alternate option if the /Pubicized folder cannot be found. IE. Workshop Lua folder if Game folder is missing and vice versa. --- .../LuaCs/Plugins/CsPackageManager.cs | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs index 005f557510..28179429c4 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/CsPackageManager.cs @@ -298,28 +298,61 @@ public AssemblyLoadingSuccessState LoadAssemblyPackages() } ImmutableList publicizedAssemblies = ImmutableList.Empty; - if (Directory.Exists(publicizedDir)) + ImmutableList list; + + try { // search for assemblies - var list = Directory.GetFiles(publicizedDir, "*.dll") + list = Directory.GetFiles(publicizedDir, "*.dll") #if CLIENT - .Where(s => !s.ToLowerInvariant().EndsWith("dedicatedserver.dll")); + .Where(s => !s.ToLowerInvariant().EndsWith("dedicatedserver.dll")) #elif SERVER - .Where(s => !s.ToLowerInvariant().EndsWith("barotrauma.dll")); + .Where(s => !s.ToLowerInvariant().EndsWith("barotrauma.dll")) #endif - - // try load them into an acl - var loadState = _assemblyManager.LoadAssembliesFromLocations(list, ref _publicizedAssemblyLoader); + .ToImmutableList(); - // loaded - if (loadState is AssemblyLoadingSuccessState.Success) + if (list.Count < 1) + throw new DirectoryNotFoundException("No publicized assemblies found."); + } + // no directory found, use the other one + catch (DirectoryNotFoundException dne) + { + if (_luaCsSetup.Config.PreferToUseWorkshopLuaSetup) { - if (_assemblyManager.TryGetACL(_publicizedAssemblyLoader, out var acl)) + 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) { - publicizedAssemblies = acl.Acl.Assemblies.ToImmutableList(); - _assemblyManager.SetACLToTemplateMode(_publicizedAssemblyLoader); + publicizedDir = Path.Combine(pck.Dir, "Binary", "Publicized"); } } + + // 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 load them into an acl + var loadState = _assemblyManager.LoadAssembliesFromLocations(list, ref _publicizedAssemblyLoader); + + // loaded + if (loadState is AssemblyLoadingSuccessState.Success) + { + if (_assemblyManager.TryGetACL(_publicizedAssemblyLoader, out var acl)) + { + publicizedAssemblies = acl.Acl.Assemblies.ToImmutableList(); + _assemblyManager.SetACLToTemplateMode(_publicizedAssemblyLoader); + } }