From 72b2492f0d9bf1b106ae790d337a08e59ed6e583 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Fri, 29 Apr 2022 12:10:20 -0300 Subject: [PATCH] fix patch hooks not working correctly with void return types --- .../SharedSource/LuaCs/LuaCsHook.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs index 8c56442f4..6b8fd2e2c 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs @@ -125,7 +125,9 @@ namespace Barotrauma foreach (var tuple in methodSet) { if (tuple.Item3 != null && tuple.Item3.IsDisposed) + { outOfSocpe.Add(tuple); + } else { var _result = tuple.Item2(__instance, args); @@ -135,15 +137,24 @@ namespace Barotrauma { if (!res.IsNull()) { - if (__originalMethod is MethodInfo mi) result = res.DynValue().ToObject(mi.ReturnType); - else result = res.DynValue().ToObject(); + if (__originalMethod is MethodInfo mi && mi.ReturnType != typeof(void)) + { + result = res.DynValue().ToObject(mi.ReturnType); + } + else + { + result = res.DynValue().ToObject(); + } } } - else result = _result; + else + { + result = _result; + } } } } - foreach (var tuple in outOfSocpe) methodSet.Remove(tuple); + foreach (var tuple in outOfSocpe) { methodSet.Remove(tuple); } } } catch (Exception ex)