Prevent some types from being re-registered

This commit is contained in:
EvilFactory
2023-05-08 13:13:47 -03:00
parent 836e5daca6
commit 886fa9ed80
2 changed files with 13 additions and 5 deletions

View File

@@ -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

View File

@@ -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)