- Fixed NRE in TryBeginDispose
- Made `OnException` event useful. - Added some null checks where expected. - Fixed overridden Unload not being called. - Removed partial from AssemblyManager.cs - Made ClearTypesList() actually work. - Made exception details show in console on release builds. - Made content package name show on plugin load. - Made execution standard instead of none for autogenerated and erroneous RunConfigs.
This commit is contained in:
committed by
Evil Factory
parent
ac068aa3f9
commit
e984633ca5
@@ -11,6 +11,7 @@ using Barotrauma.Steam;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using MonoMod.Utils;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace Barotrauma;
|
||||
|
||||
@@ -147,12 +148,12 @@ public sealed class CsPackageManager : IDisposable
|
||||
/// <summary>
|
||||
/// Whether or not plugins' types have been instantiated.
|
||||
/// </summary>
|
||||
public bool PluginsInitialized { get; private set; } = false;
|
||||
public bool PluginsInitialized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not plugins are fully loaded.
|
||||
/// </summary>
|
||||
public bool PluginsLoaded { get; private set; } = false;
|
||||
public bool PluginsLoaded { get; private set; }
|
||||
|
||||
public IEnumerable<ContentPackage> GetCurrentPackagesByLoadOrder() => _currentPackagesByLoadOrder;
|
||||
|
||||
@@ -333,7 +334,7 @@ public sealed class CsPackageManager : IDisposable
|
||||
throw new DirectoryNotFoundException("No publicized assemblies found.");
|
||||
}
|
||||
// no directory found, use the other one
|
||||
catch (DirectoryNotFoundException dne)
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
if (_luaCsSetup.Config.PreferToUseWorkshopLuaSetup)
|
||||
{
|
||||
@@ -454,8 +455,7 @@ public sealed class CsPackageManager : IDisposable
|
||||
if (reliableMap && OrderAndFilterPackagesByDependencies(
|
||||
_packagesDependencies,
|
||||
out var readyToLoad,
|
||||
out var cannotLoadPackages,
|
||||
null))
|
||||
out var cannotLoadPackages))
|
||||
{
|
||||
packagesToLoadInOrder.AddRange(readyToLoad);
|
||||
if (cannotLoadPackages is not null)
|
||||
@@ -611,21 +611,19 @@ public sealed class CsPackageManager : IDisposable
|
||||
|
||||
bool ShouldRunPackage(ContentPackage package, RunConfig config)
|
||||
{
|
||||
if (config.AutoGenerated)
|
||||
return false;
|
||||
return (!_luaCsSetup.Config.TreatForcedModsAsNormal && config.IsForced())
|
||||
|| (ContentPackageManager.EnabledPackages.All.Contains(package) && config.IsForcedOrStandard());
|
||||
}
|
||||
|
||||
void UpdatePackagesToDisable(ref HashSet<ContentPackage> list,
|
||||
void UpdatePackagesToDisable(ref HashSet<ContentPackage> set,
|
||||
ContentPackage newDisabledPackage,
|
||||
IEnumerable<KeyValuePair<ContentPackage, ImmutableList<ContentPackage>>> dependenciesMap)
|
||||
{
|
||||
list.Add(newDisabledPackage);
|
||||
set.Add(newDisabledPackage);
|
||||
foreach (var package in dependenciesMap)
|
||||
{
|
||||
if (package.Value.Contains(newDisabledPackage))
|
||||
list.Add(newDisabledPackage);
|
||||
set.Add(newDisabledPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -655,7 +653,7 @@ public sealed class CsPackageManager : IDisposable
|
||||
// init
|
||||
foreach (var plugin in contentPlugins.Value)
|
||||
{
|
||||
TryRun(() => plugin.Initialize(), $"{nameof(IAssemblyPlugin.Initialize)}", plugin.GetType().Name);
|
||||
TryRun(() => plugin.Initialize(), $"{nameof(IAssemblyPlugin.Initialize)}", $"CP: {_reverseLookupGuidList[contentPlugins.Key].Name} Plugin: {plugin.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,7 +662,7 @@ public sealed class CsPackageManager : IDisposable
|
||||
// load complete
|
||||
foreach (var plugin in contentPlugins.Value)
|
||||
{
|
||||
TryRun(() => plugin.OnLoadCompleted(), $"{nameof(IAssemblyPlugin.OnLoadCompleted)}", plugin.GetType().Name);
|
||||
TryRun(() => plugin.OnLoadCompleted(), $"{nameof(IAssemblyPlugin.OnLoadCompleted)}", $"CP: {_reverseLookupGuidList[contentPlugins.Key].Name} Plugin: {plugin.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,7 +696,7 @@ public sealed class CsPackageManager : IDisposable
|
||||
// init
|
||||
foreach (var plugin in contentPlugins.Value)
|
||||
{
|
||||
TryRun(() => plugin.PreInitPatching(), $"{nameof(IAssemblyPlugin.PreInitPatching)}", plugin.GetType().Name);
|
||||
TryRun(() => plugin.PreInitPatching(), $"{nameof(IAssemblyPlugin.PreInitPatching)}", $"CP: {_reverseLookupGuidList[contentPlugins.Key].Name} Plugin: {plugin.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,21 +739,20 @@ public sealed class CsPackageManager : IDisposable
|
||||
try
|
||||
{
|
||||
plugin = (IAssemblyPlugin)Activator.CreateInstance(type);
|
||||
_loadedPlugins[pair.Key].Add(plugin);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ModUtils.Logging.PrintError($"{nameof(CsPackageManager)}: Error while instantiating plugin of type {type}. Now disposing...");
|
||||
#if DEBUG
|
||||
ModUtils.Logging.PrintError($"{nameof(CsPackageManager)}: Details: {e.Message} | {e.InnerException}");
|
||||
#endif
|
||||
TryRun(() => plugin?.Dispose(), "Dispose", type.FullName ?? type.Name);
|
||||
|
||||
plugin = null;
|
||||
if (plugin is not null)
|
||||
{
|
||||
// ReSharper disable once AccessToModifiedClosure
|
||||
TryRun(() => plugin?.Dispose(), nameof(IAssemblyPlugin.Dispose), type.FullName ?? type.Name);
|
||||
plugin = null;
|
||||
}
|
||||
}
|
||||
if (plugin is not null)
|
||||
_loadedPlugins[pair.Key].Add(plugin);
|
||||
else
|
||||
ModUtils.Logging.PrintError($"{nameof(CsPackageManager)}: Error while instantiating plugin of type {type}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -772,7 +769,7 @@ public sealed class CsPackageManager : IDisposable
|
||||
{
|
||||
foreach (var plugin in contentPlugins.Value)
|
||||
{
|
||||
TryRun(() => plugin.Dispose(), $"{nameof(IAssemblyPlugin.Dispose)}", plugin.GetType().Name);
|
||||
TryRun(() => plugin.Dispose(), $"{nameof(IAssemblyPlugin.Dispose)}", $"CP: {_reverseLookupGuidList[contentPlugins.Key].Name} Plugin: {plugin.GetType().Name}");
|
||||
}
|
||||
contentPlugins.Value.Clear();
|
||||
}
|
||||
@@ -816,9 +813,7 @@ public sealed class CsPackageManager : IDisposable
|
||||
catch (Exception e)
|
||||
{
|
||||
ModUtils.Logging.PrintError($"{nameof(CsPackageManager)}: Error while running {messageMethodName}() on plugin of type {messageTypeName}");
|
||||
#if DEBUG
|
||||
ModUtils.Logging.PrintError($"{nameof(CsPackageManager)}: Details: {e.Message} | {e.InnerException}");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user