From 80555ef933957c2b040f947733e8a2a514fe2059 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Tue, 3 Feb 2026 21:06:28 -0300 Subject: [PATCH] IT WORKS!!!!!!!!!!!!!!!!!!!! --- .../LuaCs/Services/Safe/LuaPatcherCompat.cs | 57 ++++++++----------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaPatcherCompat.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaPatcherCompat.cs index b41111378..bb5a79331 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaPatcherCompat.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/Safe/LuaPatcherCompat.cs @@ -21,8 +21,8 @@ namespace Barotrauma.LuaCs.Services { private static LuaPatcherService instance; - 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, ILuaCsHook.HookMethodType hookType) { @@ -31,7 +31,7 @@ namespace Barotrauma.LuaCs.Services try { var funcAddr = ((long)__originalMethod.MethodHandle.GetFunctionPointer()); - HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)> methodSet = null; + HashSet<(string, LuaCsCompatPatchFunc)> methodSet = null; switch (hookType) { case ILuaCsHook.HookMethodType.Before: @@ -53,40 +53,31 @@ namespace Barotrauma.LuaCs.Services args.Add(@params[i].Name, __args[i]); } - var outOfSocpe = new HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>(); foreach (var tuple in methodSet) { - if (tuple.Item3 != null) + var _result = tuple.Item2(__instance, args); + if (_result != null) { - outOfSocpe.Add(tuple); - } - else - { - var _result = tuple.Item2(__instance, args); - if (_result != null) + if (_result is DynValue res) { - if (_result is DynValue res) + if (!res.IsNil()) { - if (!res.IsNil()) + if (__originalMethod is MethodInfo mi && mi.ReturnType != typeof(void)) { - if (__originalMethod is MethodInfo mi && mi.ReturnType != typeof(void)) - { - result = res.ToObject(mi.ReturnType); - } - else - { - result = res.ToObject(); - } + result = res.ToObject(mi.ReturnType); + } + else + { + result = res.ToObject(); } } - else - { - result = _result; - } + } + else + { + result = _result; } } } - foreach (var tuple in outOfSocpe) { methodSet.Remove(tuple); } } } catch (Exception ex) @@ -159,18 +150,18 @@ namespace Barotrauma.LuaCs.Services } } - if (compatHookPrefixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)> methodSet)) + if (compatHookPrefixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc)> methodSet)) { if (identifier != "") { methodSet.RemoveWhere(tuple => tuple.Item1 == identifier); } - methodSet.Add((identifier, patch, owner)); + methodSet.Add((identifier, patch)); } else if (patch != null) { - compatHookPrefixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>() { (identifier, patch, owner) }); + compatHookPrefixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc)>() { (identifier, patch) }); } } @@ -191,18 +182,18 @@ namespace Barotrauma.LuaCs.Services } } - if (compatHookPostfixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)> methodSet)) + if (compatHookPostfixMethods.TryGetValue(funcAddr, out HashSet<(string, LuaCsCompatPatchFunc)> methodSet)) { if (identifier != "") { methodSet.RemoveWhere(tuple => tuple.Item1 == identifier); } - methodSet.Add((identifier, patch, owner)); + methodSet.Add((identifier, patch)); } else if (patch != null) { - compatHookPostfixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>() { (identifier, patch, owner) }); + compatHookPostfixMethods.Add(funcAddr, new HashSet<(string, LuaCsCompatPatchFunc)>() { (identifier, patch) }); } } } @@ -228,7 +219,7 @@ namespace Barotrauma.LuaCs.Services { var funcAddr = (long)method.MethodHandle.GetFunctionPointer(); - Dictionary> methods; + Dictionary> methods; if (hookType == ILuaCsHook.HookMethodType.Before) methods = compatHookPrefixMethods; else if (hookType == ILuaCsHook.HookMethodType.After) methods = compatHookPostfixMethods; else throw null;