Skip to content

Commit

Permalink
- Made it only load the barotrauma or dedicatedserver publicized dll.
Browse files Browse the repository at this point in the history
  • Loading branch information
TBN-MapleWheels committed Oct 26, 2023
1 parent 09ed9d6 commit 17b304a
Showing 1 changed file with 47 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using MonoMod.Utils;

// ReSharper disable InconsistentNaming

namespace Barotrauma;
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -312,67 +323,58 @@ 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<Assembly> publicizedAssemblies = ImmutableList<Assembly>.Empty;
ImmutableList<string> 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<string> 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<string> 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 <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)
{
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
{
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 <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)
{
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)
Expand Down

0 comments on commit 17b304a

Please sign in to comment.