Change Hook.Patch exceptions to lua errors
This commit is contained in:
@@ -817,11 +817,14 @@ namespace Barotrauma
|
|||||||
private static MethodBase ResolveMethod(string className, string methodName, string[] parameters)
|
private static MethodBase ResolveMethod(string className, string methodName, string[] parameters)
|
||||||
{
|
{
|
||||||
var classType = LuaUserData.GetType(className);
|
var classType = LuaUserData.GetType(className);
|
||||||
if (classType == null) throw new InvalidOperationException($"Invalid class name '{className}'");
|
if (classType == null) throw new ScriptRuntimeException($"invalid class name '{className}'");
|
||||||
|
|
||||||
const BindingFlags BINDING_FLAGS = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
const BindingFlags BINDING_FLAGS = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
|
||||||
MethodBase method = null;
|
MethodBase method = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (parameters != null)
|
if (parameters != null)
|
||||||
{
|
{
|
||||||
var parameterTypes = parameters.Select(x => LuaUserData.GetType(x)).ToArray();
|
var parameterTypes = parameters.Select(x => LuaUserData.GetType(x)).ToArray();
|
||||||
@@ -852,16 +855,21 @@ namespace Barotrauma
|
|||||||
|
|
||||||
method = methodName switch
|
method = methodName switch
|
||||||
{
|
{
|
||||||
".cctor" => throw new InvalidOperationException("Type initializers can't have parameters."),
|
".cctor" => throw new ScriptRuntimeException("type initializers can't have parameters"),
|
||||||
".ctor" => GetCtor(),
|
".ctor" => GetCtor(),
|
||||||
_ => classType.GetMethod(methodName, BINDING_FLAGS),
|
_ => classType.GetMethod(methodName, BINDING_FLAGS),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (AmbiguousMatchException)
|
||||||
|
{
|
||||||
|
throw new ScriptRuntimeException("ambiguous method signature");
|
||||||
|
}
|
||||||
|
|
||||||
if (method == null)
|
if (method == null)
|
||||||
{
|
{
|
||||||
var parameterNamesStr = parameters == null ? "" : string.Join(", ", parameters);
|
var parameterNamesStr = parameters == null ? "" : string.Join(", ", parameters);
|
||||||
throw new InvalidOperationException($"Method '{methodName}({parameterNamesStr})' not found in class '{className}'");
|
throw new ScriptRuntimeException($"method '{methodName}({parameterNamesStr})' not found in class '{className}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
|
|||||||
Reference in New Issue
Block a user