Skip to content

Commit

Permalink
Changed publicized assembly discovery to fallback to the alternate op…
Browse files Browse the repository at this point in the history
…tion if the /Pubicized folder cannot be found. IE. Workshop Lua folder if Game folder is missing and vice versa.
  • Loading branch information
TBN-MapleWheels committed Sep 29, 2023
1 parent 91ae2ac commit 9ccf157
Showing 1 changed file with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,28 +298,61 @@ public AssemblyLoadingSuccessState LoadAssemblyPackages()
}

ImmutableList<Assembly> publicizedAssemblies = ImmutableList<Assembly>.Empty;
if (Directory.Exists(publicizedDir))
ImmutableList<string> 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 <LuaCsPackage>/Binary/Publicized/ . Using Game folder instead.");
publicizedDir = Path.Combine(Environment.CurrentDirectory, "Publicized");
}
else
{
ModUtils.Logging.PrintError($"Unable to find <GameFolder>/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);
}
}


Expand Down

0 comments on commit 9ccf157

Please sign in to comment.