diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs index 0516f6344..738425070 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs @@ -57,6 +57,14 @@ namespace Barotrauma "ContentPackageManager", }; + private static void ValidatePatchTarget(MethodInfo methodInfo) + { + if (prohibitedHooks.Any(h => methodInfo.DeclaringType.FullName.StartsWith(h))) + { + throw new ArgumentException("Hooks into the modding environment are prohibited."); + } + } + private Harmony harmony; private Dictionary> hookFunctions; @@ -300,10 +308,7 @@ namespace Barotrauma { throw new ArgumentNullException("Identifier, Method and Patch arguments must not be null."); } - if (prohibitedHooks.Any(h => method.DeclaringType.FullName.StartsWith(h))) - { - throw new ArgumentException("Hooks into Modding Environment are prohibited."); - } + ValidatePatchTarget(method); var funcAddr = (long)method.MethodHandle.GetFunctionPointer(); var patches = Harmony.GetPatchInfo(method); diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHookCompat.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHookCompat.cs index dee8089e3..3aa07f90a 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHookCompat.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHookCompat.cs @@ -157,11 +157,7 @@ namespace Barotrauma GameMain.LuaCs.HandleException(new ArgumentNullException("Identifier, Method and Patch arguments must not be null."), exceptionType: ExceptionType.Both); return; } - if (prohibitedHooks.Any(h => method.DeclaringType.FullName.StartsWith(h))) - { - GameMain.LuaCs.HandleException(new ArgumentException("Hooks into Modding Environment are prohibited."), exceptionType: ExceptionType.Both); - return; - } + ValidatePatchTarget(method); var funcAddr = ((long)method.MethodHandle.GetFunctionPointer()); var patches = Harmony.GetPatchInfo(method);