From 4113b1ca2d10663c7c95540c01e77397e3ddf2ea Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Sat, 2 Apr 2022 16:09:01 -0300 Subject: [PATCH] improve HookMethod errors --- .../SharedSource/Lua/LuaClasses/LuaHook.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses/LuaHook.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses/LuaHook.cs index f646c0414..ced9ef980 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses/LuaHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses/LuaHook.cs @@ -147,6 +147,13 @@ namespace Barotrauma public void HookMethod(string identifier, string className, string methodName, string[] parameterNames, object hookMethod, HookMethodType hookMethodType = HookMethodType.Before) { var classType = LuaUserData.GetType(className); + + if (classType == null) + { + GameMain.Lua.HandleLuaException(new Exception($"Tried to use HookMethod with an invalid class name '{className}'.")); + return; + } + MethodInfo methodInfo = null; if (parameterNames != null) @@ -161,7 +168,8 @@ namespace Barotrauma if (methodInfo == null) { - GameMain.Lua.PrintError($"Method '{methodName}' with parameter '{string.Join(", ", parameterNames)}' not found from Class '{className}'"); + string parameterNamesStr = parameterNames == null ? "" : string.Join(", ", parameterNames == null); + GameMain.Lua.HandleLuaException(new Exception($"Method '{methodName}' with parameters '{parameterNamesStr}' not found in class '{className}'")); return; }