diff --git a/Barotrauma/BarotraumaClient/LinuxClient.csproj b/Barotrauma/BarotraumaClient/LinuxClient.csproj
index d51ae3431..01106d746 100644
--- a/Barotrauma/BarotraumaClient/LinuxClient.csproj
+++ b/Barotrauma/BarotraumaClient/LinuxClient.csproj
@@ -142,6 +142,7 @@
+
@@ -222,4 +223,4 @@
-
\ No newline at end of file
+
diff --git a/Barotrauma/BarotraumaClient/MacClient.csproj b/Barotrauma/BarotraumaClient/MacClient.csproj
index fb9a8c51f..97be07204 100644
--- a/Barotrauma/BarotraumaClient/MacClient.csproj
+++ b/Barotrauma/BarotraumaClient/MacClient.csproj
@@ -134,6 +134,7 @@
+
@@ -224,4 +225,4 @@
-
\ No newline at end of file
+
diff --git a/Barotrauma/BarotraumaClient/WindowsClient.csproj b/Barotrauma/BarotraumaClient/WindowsClient.csproj
index 1c96d533e..2114560b0 100644
--- a/Barotrauma/BarotraumaClient/WindowsClient.csproj
+++ b/Barotrauma/BarotraumaClient/WindowsClient.csproj
@@ -141,6 +141,7 @@
+
diff --git a/Barotrauma/BarotraumaServer/LinuxServer.csproj b/Barotrauma/BarotraumaServer/LinuxServer.csproj
index 0828ce53f..9d7662827 100644
--- a/Barotrauma/BarotraumaServer/LinuxServer.csproj
+++ b/Barotrauma/BarotraumaServer/LinuxServer.csproj
@@ -89,6 +89,7 @@
+
diff --git a/Barotrauma/BarotraumaServer/MacServer.csproj b/Barotrauma/BarotraumaServer/MacServer.csproj
index 731599318..518422501 100644
--- a/Barotrauma/BarotraumaServer/MacServer.csproj
+++ b/Barotrauma/BarotraumaServer/MacServer.csproj
@@ -86,6 +86,7 @@
+
diff --git a/Barotrauma/BarotraumaServer/WindowsServer.csproj b/Barotrauma/BarotraumaServer/WindowsServer.csproj
index d1e747e39..b4e15a59c 100644
--- a/Barotrauma/BarotraumaServer/WindowsServer.csproj
+++ b/Barotrauma/BarotraumaServer/WindowsServer.csproj
@@ -88,6 +88,7 @@
+
diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaCustomConverters.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaCustomConverters.cs
index 581becdc0..a0a4fd308 100644
--- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaCustomConverters.cs
+++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Lua/LuaCustomConverters.cs
@@ -4,10 +4,10 @@ using System.Text;
using MoonSharp.Interpreter;
using Microsoft.Xna.Framework;
using FarseerPhysics.Dynamics;
+using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch;
namespace Barotrauma
{
-
public static class LuaCustomConverters
{
public static void RegisterAll()
@@ -31,8 +31,12 @@ namespace Barotrauma
v => (LuaCsFunc)(args => GameMain.LuaCs.CallLuaFunction(v.Function, args)));
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
DataType.Function,
- typeof(LuaCsPatch),
- v => (LuaCsPatch)((self, args) => GameMain.LuaCs.CallLuaFunction(v.Function, self, args)));
+ typeof(LuaCsCompatPatchFunc),
+ v => (LuaCsCompatPatchFunc)((self, args) => GameMain.LuaCs.CallLuaFunction(v.Function, self, args)));
+ Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(
+ DataType.Function,
+ typeof(LuaCsPatchFunc),
+ v => (LuaCsPatchFunc)((self, args) => GameMain.LuaCs.CallLuaFunction(v.Function, self, args)));
#if CLIENT
RegisterAction();
diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs
index 4558c8afa..1d6f53405 100644
--- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs
+++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs
@@ -1,61 +1,524 @@
using System;
-using System.Linq;
-using System.Reflection;
-using MoonSharp.Interpreter;
-using HarmonyLib;
+using System.Collections;
using System.Collections.Generic;
-using System.Text;
-using MoonSharp.Interpreter.Interop;
-using static Barotrauma.LuaCsSetup;
-using System.Threading;
using System.Diagnostics;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Text;
+using System.Text.RegularExpressions;
+using HarmonyLib;
+using Microsoft.Xna.Framework;
+using MoonSharp.Interpreter;
+using MoonSharp.Interpreter.Interop;
+using Sigil;
+using Sigil.NonGeneric;
+using static Barotrauma.LuaCsSetup;
namespace Barotrauma
{
- public delegate void LuaCsAction(params object[] args);
- public delegate DynValue LuaCsFunc(params object[] args);
- public delegate object LuaCsPatch(object self, Dictionary args);
+ public delegate void LuaCsAction(params object[] args);
+ public delegate DynValue LuaCsFunc(params object[] args);
+ public delegate DynValue LuaCsPatchFunc(object instance, LuaCsHook.ParameterTable ptable);
- public partial class LuaCsHook
- {
- public enum HookMethodType
- {
- Before, After
- }
+ internal static class SigilExtensions
+ {
+ ///
+ /// Puts a type on the stack, as a object instead of a
+ /// runtime type token.
+ ///
+ /// The IL emitter.
+ /// The type to put on the stack.
+ public static void LoadType(this Emit il, Type type)
+ {
+ if (type == null) throw new ArgumentNullException(nameof(type));
+ il.LoadConstant(type); // ldtoken
+ // This converts the type token into a Type object
+ il.Call(typeof(Type).GetMethod(
+ name: nameof(Type.GetTypeFromHandle),
+ bindingAttr: BindingFlags.Public | BindingFlags.Static,
+ binder: null,
+ types: new Type[] { typeof(RuntimeTypeHandle) },
+ modifiers: null));
+ }
- private class LuaHookFunction
- {
- public string name;
- public string hookName;
- public object function;
+ ///
+ /// Converts the value on the stack to .
+ ///
+ /// The IL emitter.
+ /// The type of the value on the stack.
+ public static void ToObject(this Emit il, Type type)
+ {
+ if (type == null) throw new ArgumentNullException(nameof(type));
+ il.DerefIfByRef(ref type);
+ if (type.IsValueType)
+ {
+ il.Box(type);
+ }
+ else if (type != typeof(object))
+ {
+ il.CastClass