Move prohibitedHooks check to a method

This commit is contained in:
peelz
2022-08-03 21:34:41 -04:00
parent 7ce7e6e763
commit a5bffce33b
2 changed files with 10 additions and 9 deletions

View File

@@ -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<string, Dictionary<string, (LuaCsHookCallback, ACsMod)>> 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);

View File

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