diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs index 9a67bddf3..343a73856 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs @@ -1,4 +1,6 @@ using System; +using System.Reflection; +using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch; namespace Barotrauma.LuaCs.Services.Compatibility; @@ -21,4 +23,12 @@ public interface ILuaCsHook : ILuaCsShim string Patch(string className, string methodName, LuaCsPatchFunc patch, EventService.HookMethodType hookType = EventService.HookMethodType.Before); bool RemovePatch(string identifier, string className, string methodName, string[] parameterTypes, EventService.HookMethodType hookType); bool RemovePatch(string identifier, string className, string methodName, EventService.HookMethodType hookType); + + void HookMethod(string identifier, MethodBase method, LuaCsCompatPatchFunc patch, HookMethodType hookType = HookMethodType.Before, IAssemblyPlugin owner = null); + + + public enum HookMethodType + { + Before, After + } } diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/PluginManagementService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/PluginManagementService.cs index 85b3e35c5..75fe54d4d 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/PluginManagementService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/PluginManagementService.cs @@ -70,8 +70,12 @@ public class PluginManagementService : IAssemblyManagementService private static readonly SyntaxTree BaseAssemblyImports = CSharpSyntaxTree.ParseText( new StringBuilder() + .AppendLine("global using LuaCsHook = Barotrauma.LuaCs.Services.Compatibility.ILuaCsHook;") .AppendLine("using System.Reflection;") .AppendLine("using Barotrauma;") + .AppendLine("using Barotrauma.LuaCs;") + .AppendLine("using Barotrauma.LuaCs.Services;") + .AppendLine("using Barotrauma.LuaCs.Services.Compatibility;") .AppendLine("using System.Runtime.CompilerServices;") .AppendLine("[assembly: IgnoresAccessChecksTo(\"BarotraumaCore\")]") #if CLIENT diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs index 8b59b830e..be821e83f 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs @@ -1,10 +1,12 @@ -global using LuaCsHook = Barotrauma.LuaCs.Services.EventService; +//global using LuaCsHook = Barotrauma.LuaCs.Services.EventService; +global using LuaCsHook = Barotrauma.LuaCs.Services.Compatibility.ILuaCsHook; using System; using System.Linq; using System.Reflection; using HarmonyLib; using System.Collections.Generic; +using Barotrauma.LuaCs.Services.Compatibility; using MoonSharp.Interpreter; using LuaCsCompatPatchFunc = Barotrauma.LuaCsPatch; @@ -126,6 +128,11 @@ namespace Barotrauma.LuaCs.Services private static MethodInfo _miHookLuaCsPatchRetPostfix = typeof(EventService).GetMethod("HookLuaCsPatchRetPostfix", BindingFlags.NonPublic | BindingFlags.Static); // TODO: deprecate this + + public void HookMethod(string identifier, MethodBase method, LuaCsCompatPatchFunc patch, ILuaCsHook.HookMethodType hookType = ILuaCsHook.HookMethodType.Before, IAssemblyPlugin owner = null) + { + throw new NotImplementedException(); + } public void HookMethod(string identifier, MethodBase method, LuaCsCompatPatchFunc patch, HookMethodType hookType = HookMethodType.Before, IAssemblyPlugin owner = null) { if (identifier == null || method == null || patch == null)