diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs index 5697a51df..9a67bddf3 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Compatibility/ILuaCsHook.cs @@ -12,6 +12,7 @@ public interface ILuaCsHook : ILuaCsShim // Does anyone use this? TODO: Analyze old Lua mods for usage scenarios. //bool Exists(string eventName, string identifier); object Call(string eventName, params object[] args); + T Call(string eventName, params object[] args); // Hook/Method Patching string Patch(string identifier, string className, string methodName, string[] parameterTypes, LuaCsPatchFunc patch, EventService.HookMethodType hookType = EventService.HookMethodType.Before); diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs index 42a025c2c..e583b1501 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/EventService.cs @@ -149,6 +149,11 @@ public partial class EventService : IEventService return returnValue; } + public T Call(string eventName, params object[] args) + { + return (T)Call(eventName, args); + } + public void Subscribe(string identifier, IDictionary callbacks) where T : IEvent { Guard.IsNotNullOrWhiteSpace(identifier, nameof(identifier)); diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs index 99b6bb68f..8b59b830e 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaClasses/LuaPatcherCompat.cs @@ -18,8 +18,8 @@ namespace Barotrauma.LuaCs.Services { partial class EventService { - private Dictionary> compatHookPrefixMethods = new Dictionary>(); - private Dictionary> compatHookPostfixMethods = new Dictionary>(); + private Dictionary> compatHookPrefixMethods = new Dictionary>(); + private Dictionary> compatHookPostfixMethods = new Dictionary>(); private static void _hookLuaCsPatch(MethodBase __originalMethod, object[] __args, object __instance, out object result, HookMethodType hookType) { @@ -28,7 +28,7 @@ namespace Barotrauma.LuaCs.Services try { var funcAddr = ((long)__originalMethod.MethodHandle.GetFunctionPointer()); - HashSet<(string, LuaCsCompatPatchFunc, ACsMod)> methodSet = null; + HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)> methodSet = null; switch (hookType) { case HookMethodType.Before: @@ -50,10 +50,10 @@ namespace Barotrauma.LuaCs.Services args.Add(@params[i].Name, __args[i]); } - var outOfSocpe = new HashSet<(string, LuaCsCompatPatchFunc, ACsMod)>(); + var outOfSocpe = new HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>(); foreach (var tuple in methodSet) { - if (tuple.Item3 != null && tuple.Item3.IsDisposed) + if (tuple.Item3 != null) { outOfSocpe.Add(tuple); } @@ -126,7 +126,7 @@ 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, HookMethodType hookType = HookMethodType.Before, ACsMod owner = null) + public void HookMethod(string identifier, MethodBase method, LuaCsCompatPatchFunc patch, HookMethodType hookType = HookMethodType.Before, IAssemblyPlugin owner = null) { if (identifier == null || method == null || patch == null) { @@ -155,7 +155,7 @@ namespace Barotrauma.LuaCs.Services } } - if (compatHookPrefixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc, ACsMod)> methodSet)) + if (compatHookPrefixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)> methodSet)) { if (identifier != "") { @@ -166,7 +166,7 @@ namespace Barotrauma.LuaCs.Services } else if (patch != null) { - compatHookPrefixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc, ACsMod)>() { (identifier, patch, owner) }); + compatHookPrefixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>() { (identifier, patch, owner) }); } } @@ -187,7 +187,7 @@ namespace Barotrauma.LuaCs.Services } } - if (compatHookPostfixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc, ACsMod)> methodSet)) + if (compatHookPostfixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)> methodSet)) { if (identifier != "") { @@ -198,7 +198,7 @@ namespace Barotrauma.LuaCs.Services } else if (patch != null) { - compatHookPostfixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc, ACsMod)>() { (identifier, patch, owner) }); + compatHookPostfixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>() { (identifier, patch, owner) }); } } } @@ -224,7 +224,7 @@ namespace Barotrauma.LuaCs.Services { var funcAddr = (long)method.MethodHandle.GetFunctionPointer(); - Dictionary> methods; + Dictionary> methods; if (hookType == HookMethodType.Before) methods = compatHookPrefixMethods; else if (hookType == HookMethodType.After) methods = compatHookPostfixMethods; else throw null;