- Fixed stack ovewrflow from ServicesProvider (???).

This commit is contained in:
MapleWheels
2026-02-02 16:26:38 -05:00
committed by Maplewheels
parent 024b07d5f4
commit 36bed09bde
5 changed files with 24 additions and 24 deletions

View File

@@ -330,7 +330,11 @@ namespace Barotrauma
if (!PackageManagementService.IsAnyPackageRunning())
{
Logger.LogResults(PackageManagementService.ExecuteLoadedPackages(ContentPackageManager.EnabledPackages.All.ToImmutableArray()));
#if DEBUG
Logger.LogResults(PackageManagementService.ExecuteLoadedPackages(ContentPackageManager.EnabledPackages.All.ToImmutableArray(), true));
#else
Logger.LogResults(PackageManagementService.ExecuteLoadedPackages(ContentPackageManager.EnabledPackages.All.ToImmutableArray(), IsCsEnabled));
#endif
}
CurrentRunState = RunState.Running;

View File

@@ -189,7 +189,7 @@ public sealed class PackageManagementService : IPackageManagementService
}
}
public FluentResults.Result ExecuteLoadedPackages(ImmutableArray<ContentPackage> executionOrder)
public FluentResults.Result ExecuteLoadedPackages(ImmutableArray<ContentPackage> executionOrder, bool executeCsAssemblies)
{
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
using var executeLock = _executionLock.AcquireWriterLock().ConfigureAwait(false).GetAwaiter().GetResult();
@@ -237,7 +237,7 @@ public sealed class PackageManagementService : IPackageManagementService
result.WithReasons(_luaScriptManagementService.ExecuteLoadedScripts(luaScripts).Reasons);
}
if (_runConfig.IsCsEnabled)
if (executeCsAssemblies)
{
var plugins = SelectCompatible(loadingOrderedPackages
.SelectMany(pkg => pkg.Value.Assemblies)

View File

@@ -99,13 +99,12 @@ public class PluginManagementService : IAssemblyManagementService
#endregion
private IServicesProvider _serviceProvider;
private IAssemblyLoaderService.IFactory _assemblyLoaderFactory;
private IStorageService _storageService;
private ILoggerService _logger;
private IEventService _eventService;
private IConfigService _configService;
private ILuaScriptManagementService _luaScriptManagementService;
private Lazy<IEventService> _eventService;
private Lazy<IConfigService> _configService;
private Lazy<ILuaScriptManagementService> _luaScriptManagementService;
private readonly ConcurrentDictionary<ContentPackage, IAssemblyLoaderService> _assemblyLoaders = new();
private readonly ConcurrentDictionary<ContentPackage, ImmutableArray<IAssemblyPlugin>> _pluginInstances = new();
private readonly ConditionalWeakTable<IAssemblyLoaderService, ContentPackage> _unloadingAssemblyLoaders = new();
@@ -113,16 +112,13 @@ public class PluginManagementService : IAssemblyManagementService
private ServiceContainer _pluginInjectorContainer;
public PluginManagementService(
IServicesProvider serviceProvider,
IAssemblyLoaderService.IFactory assemblyLoaderFactory,
IStorageService storageService,
ILoggerService logger,
IEventService eventService,
ILuaScriptManagementService luaScriptManagementService,
IConfigService configService)
Lazy<IEventService> eventService,
Lazy<ILuaScriptManagementService> luaScriptManagementService,
Lazy<IConfigService> configService)
{
Guard.IsNotNull(serviceProvider, nameof(serviceProvider));
_serviceProvider = serviceProvider;
_assemblyLoaderFactory = assemblyLoaderFactory;
_storageService = storageService;
_logger = logger;
@@ -139,11 +135,11 @@ public class PluginManagementService : IAssemblyManagementService
});
container.Register<ILoggerService>(fac => _logger, new PerContainerLifetime());
container.Register<IStorageService>(fac => _storageService, new PerContainerLifetime());
container.Register<IEventService>(fac => _eventService, new PerContainerLifetime());
container.Register<ILuaScriptManagementService>(fac => _luaScriptManagementService, new PerContainerLifetime());
container.Register<IConfigService>(fac => _configService, new PerContainerLifetime());
container.Register<ILoggerService>(fac => _logger);
container.Register<IStorageService>(fac => _storageService);
container.Register<IEventService>(fac => _eventService.Value);
container.Register<ILuaScriptManagementService>(fac => _luaScriptManagementService.Value);
container.Register<IConfigService>(fac => _configService.Value);
return container;
}
@@ -268,21 +264,21 @@ public class PluginManagementService : IAssemblyManagementService
results.WithReasons(PluginInitRunner(plugin, p => p.PreInitPatching()).Reasons);
}
_eventService.PublishEvent<IEventPluginPreInitialize>(sub => sub.PreInitPatching());
_eventService.Value.PublishEvent<IEventPluginPreInitialize>(sub => sub.PreInitPatching());
foreach (var plugin in pluginsToInit)
{
results.WithReasons(PluginInitRunner(plugin, p => p.Initialize()).Reasons);
}
_eventService.PublishEvent<IEventPluginInitialize>(sub => sub.Initialize());
_eventService.Value.PublishEvent<IEventPluginInitialize>(sub => sub.Initialize());
foreach (var plugin in pluginsToInit)
{
results.WithReasons(PluginInitRunner(plugin, p => p.OnLoadCompleted()).Reasons);
}
_eventService.PublishEvent<IEventPluginLoadCompleted>(sub => sub.OnLoadCompleted());
_eventService.Value.PublishEvent<IEventPluginLoadCompleted>(sub => sub.OnLoadCompleted());
return results;
@@ -527,7 +523,7 @@ public class PluginManagementService : IAssemblyManagementService
foreach (var assembly in loader.Assemblies)
{
_eventService.PublishEvent<IEventAssemblyUnloading>(sub => sub.OnAssemblyUnloading(assembly));
_eventService.Value.PublishEvent<IEventAssemblyUnloading>(sub => sub.OnAssemblyUnloading(assembly));
}
}

View File

@@ -22,7 +22,7 @@ public class ServicesProvider : IServicesProvider
EnablePropertyInjection = false
});
_serviceContainerInst.Register<IServicesProvider>((f) => this);
//_serviceContainerInst.Register<IServicesProvider>((f) => this);
}
public void RegisterServiceType<TSvcInterface, TService>(ServiceLifetime lifetime, ILifetime lifetimeInstance = null) where TSvcInterface : class, IService where TService : class, IService, TSvcInterface

View File

@@ -14,7 +14,7 @@ public interface IPackageManagementService : IReusableService
{
public FluentResults.Result LoadPackageInfo(ContentPackage package);
public FluentResults.Result LoadPackagesInfo(ImmutableArray<ContentPackage> packages);
public FluentResults.Result ExecuteLoadedPackages(ImmutableArray<ContentPackage> executionOrder);
public FluentResults.Result ExecuteLoadedPackages(ImmutableArray<ContentPackage> executionOrder, bool executeCsAssemblies);
public FluentResults.Result SyncLoadedPackagesList(ImmutableArray<ContentPackage> packages);
public FluentResults.Result StopRunningPackages();
public FluentResults.Result UnloadPackage(ContentPackage package);