Skip to content

Commit

Permalink
- saving changes before repo reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
TBN-MapleWheels committed Oct 26, 2023
1 parent e2695db commit 09ed9d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ public void Update()

public void Stop()
{

PluginPackageManager.UnloadPlugins();

// unregister types
foreach (Type type in AssemblyManager.GetAllLoadedACLs().SelectMany(
acl => acl.AssembliesTypes.Select(kvp => kvp.Value)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public IEnumerable<LoadedACL> GetAllLoadedACLs()
OpsLockLoaded.EnterReadLock();
try
{
if (LoadedACLs.IsEmpty)
if (!LoadedACLs.Any())
{
return ImmutableList<LoadedACL>.Empty;
}
Expand Down Expand Up @@ -422,7 +422,7 @@ public AssemblyLoadingSuccessState LoadAssemblyFromMemory([NotNull] string compi
}
catch (Exception e)
{
ModUtils.Logging.PrintError($"{nameof(AssemblyManager)}::{nameof(LoadAssemblyFromMemory)}() | Failed to compile and load assemblies for [ {compiledAssemblyName} / {friendlyName} ]! Details: {e.Message}");
ModUtils.Logging.PrintError($"{nameof(AssemblyManager)}::{nameof(LoadAssemblyFromMemory)}() | Failed to compile and load assemblies for [ {compiledAssemblyName} / {friendlyName} ]! Details: {e.Message} | {e.StackTrace}");
return AssemblyLoadingSuccessState.InvalidAssembly;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,29 @@ public AssemblyLoadingSuccessState LoadFromFiles([NotNull] IEnumerable<string> a
LoadFromAssemblyPath(sanitizedFilePath);
}
// on fail of any we're done because we assume that loaded files are related. This ACL needs to be unloaded and collected.
catch (ArgumentNullException)
catch (ArgumentNullException ane)
{
ModUtils.Logging.PrintError($"MemFileACL::{nameof(LoadFromFiles)}() | Error loading file path {sanitizedFilePath}. Details: {ane.Message} | {ane.StackTrace}");
return AssemblyLoadingSuccessState.BadFilePath;
}
catch (ArgumentException)
catch (ArgumentException ae)
{
ModUtils.Logging.PrintError($"MemFileACL::{nameof(LoadFromFiles)}() | Error loading file path {sanitizedFilePath}. Details: {ae.Message} | {ae.StackTrace}");
return AssemblyLoadingSuccessState.BadFilePath;
}
catch (FileLoadException)
catch (FileLoadException fle)
{
ModUtils.Logging.PrintError($"MemFileACL::{nameof(LoadFromFiles)}() | Error loading file path {sanitizedFilePath}. Details: {fle.Message} | {fle.StackTrace}");
return AssemblyLoadingSuccessState.CannotLoadFile;
}
catch (FileNotFoundException)
catch (FileNotFoundException fnfe)
{
ModUtils.Logging.PrintError($"MemFileACL::{nameof(LoadFromFiles)}() | Error loading file path {sanitizedFilePath}. Details: {fnfe.Message} | {fnfe.StackTrace}");
return AssemblyLoadingSuccessState.NoAssemblyFound;
}
catch (BadImageFormatException)
catch (BadImageFormatException bife)
{
ModUtils.Logging.PrintError($"MemFileACL::{nameof(LoadFromFiles)}() | Error loading file path {sanitizedFilePath}. Details: {bife.Message} | {bife.StackTrace}");
return AssemblyLoadingSuccessState.InvalidAssembly;
}
catch (Exception e)
Expand Down Expand Up @@ -143,7 +148,7 @@ public AssemblyLoadingSuccessState CompileAndLoadScriptAssembly(
}

var externAssemblyRefs = externFileAssemblyReferences is not null ? externFileAssemblyReferences.ToImmutableList() : ImmutableList<Assembly>.Empty;
var externAssemblyNames = !externAssemblyRefs.IsEmpty ? externAssemblyRefs
var externAssemblyNames = externAssemblyRefs.Any() ? externAssemblyRefs
.Where(a => a.FullName is not null)
.Select(a => a.FullName).ToImmutableHashSet()
: ImmutableHashSet<string>.Empty;
Expand Down Expand Up @@ -179,7 +184,7 @@ public AssemblyLoadingSuccessState CompileAndLoadScriptAssembly(
).ToList());

ImmutableList<AssemblyManager.LoadedACL> loadedAcls = _assemblyManager.GetAllLoadedACLs().ToImmutableList();
if (!loadedAcls.IsEmpty)
if (loadedAcls.Any())
{
// build metadata refs from ACL assemblies from files/disk.
foreach (AssemblyManager.LoadedACL loadedAcl in loadedAcls)
Expand All @@ -205,7 +210,7 @@ public AssemblyLoadingSuccessState CompileAndLoadScriptAssembly(
// build metadata refs from in-memory images
foreach (var loadedAcl in loadedAcls)
{
if (loadedAcl.Acl.CompiledAssemblyImage is null || loadedAcl.Acl.CompiledAssemblyImage.Length == 0)
if (loadedAcl?.Acl?.CompiledAssemblyImage is null || loadedAcl.Acl.CompiledAssemblyImage.Length == 0)
continue;
metadataReferences.Add(MetadataReference.CreateFromImage(loadedAcl.Acl.CompiledAssemblyImage));
}
Expand Down

0 comments on commit 09ed9d6

Please sign in to comment.