diff --git a/Barotrauma/BarotraumaShared/Lua/PostSetup.lua b/Barotrauma/BarotraumaShared/Lua/PostSetup.lua index 0ac5ec464..920cd6769 100644 --- a/Barotrauma/BarotraumaShared/Lua/PostSetup.lua +++ b/Barotrauma/BarotraumaShared/Lua/PostSetup.lua @@ -21,9 +21,17 @@ local function IsAllowed(typeName) return false end +local function CanBeReRegistered(typeName) + if string.startsWith(typeName, "Barotrauma.Lua") or string.startsWith(typeName, "Barotrauma.Cs") or string.startsWith(typeName, "Barotrauma.LuaCs") then + return false + end + + return true +end + local originalRegisterType = LuaUserData.RegisterType LuaUserData.RegisterType = function (typeName) - if not LuaUserData.IsRegistered(typeName) and not IsAllowed(typeName) then + if not (CanBeReRegistered(typeName) and LuaUserData.IsRegistered(typeName)) and not IsAllowed(typeName) then error("Couldn't register type " .. typeName .. ".", 2) end @@ -38,7 +46,7 @@ end local originalCreateStatic = LuaUserData.CreateStatic LuaUserData.CreateStatic = function (typeName, addCallMethod) - if not LuaUserData.IsRegistered(typeName) and not IsAllowed(typeName) then + if not (CanBeReRegistered(typeName) and LuaUserData.IsRegistered(typeName)) and not IsAllowed(typeName) then error("Couldn't create static type " .. typeName .. ".", 2) end diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs index 8ed35e2d4..c0bfcba2b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaClasses/LuaUserData.cs @@ -23,16 +23,16 @@ namespace Barotrauma return UserData.RegisterType(type); } - public static IUserDataDescriptor IsRegistered(string typeName) + public static bool IsRegistered(string typeName) { Type type = GetType(typeName); if (type == null) { - return null; + return false; } - return UserData.GetDescriptorForType(type, true); + return UserData.GetDescriptorForType(type, true) != null; } public static void UnregisterType(string typeName, bool deleteHistory = false)