Remove types that have been registered when unloading

This commit is contained in:
Evil Factory
2026-03-22 12:42:23 -03:00
parent de53b4514e
commit 23e0ff7aa6

View File

@@ -23,10 +23,11 @@ using System.Threading.Tasks;
using Barotrauma.LuaCs;
using Barotrauma.LuaCs.Events;
using System.Diagnostics;
using System.Reflection;
namespace Barotrauma.LuaCs;
class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService, IEventAssemblyUnloading
{
public Script? InternalScript => _script;
@@ -463,8 +464,6 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
_script = null;
// todo unregister everything
return FluentResults.Result.Ok();
}
@@ -509,4 +508,12 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
return _script.Globals[tableName];
}
public void OnAssemblyUnloading(Assembly assembly)
{
foreach (Type type in assembly.SafeGetTypes())
{
UserData.UnregisterType(type, deleteHistory: true);
}
}
}