From 80832459b9b3fc36285dd46821a70724f7bc2e6b Mon Sep 17 00:00:00 2001 From: Maplewheels Date: Sat, 14 Mar 2026 23:47:44 -0400 Subject: [PATCH] Added api for getting content package associatged with a plugin type. --- .../LuaCs/_Services/PluginManagementService.cs | 10 ++++++++++ .../_Services/_Interfaces/IPluginManagementService.cs | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs index dd348ff0c..c102bcae1 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs @@ -145,6 +145,7 @@ public class PluginManagementService : IAssemblyManagementService } } _pluginInstances.Clear(); + _pluginPackageLookup.Clear(); _pluginInjectorContainer?.Dispose(); _pluginInjectorContainer = null; @@ -194,6 +195,7 @@ public class PluginManagementService : IAssemblyManagementService private Lazy _configService; private Lazy _luaScriptManagementService; private readonly ConcurrentDictionary _assemblyLoaders = new(); + private readonly ConcurrentDictionary _pluginPackageLookup = new(); private readonly ConcurrentDictionary> _pluginInstances = new(); private readonly ConditionalWeakTable _unloadingAssemblyLoaders = new(); private readonly AsyncReaderWriterLock _operationsLock = new(); @@ -226,6 +228,7 @@ public class PluginManagementService : IAssemblyManagementService container.Register(fac => _logger); container.Register(fac => _storageService); container.Register(fac => _eventService.Value); + container.Register(fac => this); container.Register(fac => _luaScriptManagementService.Value); container.Register(fac => _configService.Value); @@ -275,6 +278,11 @@ public class PluginManagementService : IAssemblyManagementService } } + public bool TryGetPackageForPlugin(out ContentPackage ownerPackage) + { + return _pluginPackageLookup.TryGetValue(typeof(TPlugin), out ownerPackage); + } + public Type GetType(string typeName, bool isByRefType = false, bool includeInterfaces = false, bool includeDefaultContext = true) { @@ -375,6 +383,7 @@ public class PluginManagementService : IAssemblyManagementService _pluginInjectorContainer.InjectProperties(plugin); _pluginInjectorContainer.Register(pluginType, fac => plugin); loadedTypes.Add(plugin); + _pluginPackageLookup.TryAdd(pluginType, packageTypes.Key); } catch (Exception e) { @@ -724,6 +733,7 @@ public class PluginManagementService : IAssemblyManagementService } _pluginInstances.Clear(); + _pluginPackageLookup.Clear(); return results; } diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/IPluginManagementService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/IPluginManagementService.cs index 51453255f..a26c49ff6 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/IPluginManagementService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/IPluginManagementService.cs @@ -21,6 +21,14 @@ public interface IPluginManagementService : IReusableService bool includeInterfaces = false, bool includeAbstractTypes = false, bool includeDefaultContext = true); + + /// + /// Gets the that contains the plugin type. + /// + /// + /// + /// + bool TryGetPackageForPlugin(out ContentPackage ownerPackage); /// /// Tries to find the type given the fully qualified name and filters.