From 9bd23efd3cca42b7c5af86f02ea6505098050f9e Mon Sep 17 00:00:00 2001 From: MapleWheels Date: Fri, 22 Sep 2023 11:52:54 -0400 Subject: [PATCH] - Added additional validation to type name and added AppDomain-wide fallback search using Type.GetType if a type with the given name cannot be found in the cache. --- .../LuaCs/Plugins/AssemblyManager.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/AssemblyManager.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/AssemblyManager.cs index 64f12bf68..13fccff71 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/AssemblyManager.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Plugins/AssemblyManager.cs @@ -210,9 +210,13 @@ public partial class AssemblyManager /// Note: Will return the by-reference equivalent type if the type name is prefixed with "out " or "ref ". /// /// The string name of the type to search for. - /// An Enumerator for matching types. + /// An Enumerator for matching types. List will be empty if bad params are supplied. public IEnumerable GetTypesByName(string typeName) { + List types = new(); + if (typeName.IsNullOrWhiteSpace()) + return types; + bool byRef = false; if (typeName.StartsWith("out ") || typeName.StartsWith("ref ")) { @@ -220,7 +224,6 @@ public partial class AssemblyManager byRef = true; } - List types = new(); TypesListHelper(); if (types.Count > 0) @@ -229,6 +232,18 @@ public partial class AssemblyManager // we couldn't find it, rebuild and try one more time RebuildTypesList(); TypesListHelper(); + + if (types.Count > 0) + return types; + + // fallback to Type.GetType + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + Type t = assembly.GetType(typeName); + if (t is not null) + types.Add(byRef ? t.MakeByRefType() : t); + } + return types; void TypesListHelper()