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
+10 -2
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