IT WORKS!!!!!!!!!!!!!!!!!!!!

This commit is contained in:
Evil Factory
2026-02-03 21:06:28 -03:00
committed by Maplewheels
parent cf251451ed
commit 80555ef933
@@ -21,8 +21,8 @@ namespace Barotrauma.LuaCs.Services
{ {
private static LuaPatcherService instance; private static LuaPatcherService instance;
private Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>> compatHookPrefixMethods = new Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>>(); private Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc)>> compatHookPrefixMethods = new Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc)>>();
private Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>> compatHookPostfixMethods = new Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>>(); private Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc)>> compatHookPostfixMethods = new Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc)>>();
private static void _hookLuaCsPatch(MethodBase __originalMethod, object[] __args, object __instance, out object result, ILuaCsHook.HookMethodType hookType) 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 try
{ {
var funcAddr = ((long)__originalMethod.MethodHandle.GetFunctionPointer()); var funcAddr = ((long)__originalMethod.MethodHandle.GetFunctionPointer());
HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)> methodSet = null; HashSet<(string, LuaCsCompatPatchFunc)> methodSet = null;
switch (hookType) switch (hookType)
{ {
case ILuaCsHook.HookMethodType.Before: case ILuaCsHook.HookMethodType.Before:
@@ -53,14 +53,7 @@ namespace Barotrauma.LuaCs.Services
args.Add(@params[i].Name, __args[i]); args.Add(@params[i].Name, __args[i]);
} }
var outOfSocpe = new HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>();
foreach (var tuple in methodSet) foreach (var tuple in methodSet)
{
if (tuple.Item3 != null)
{
outOfSocpe.Add(tuple);
}
else
{ {
var _result = tuple.Item2(__instance, args); var _result = tuple.Item2(__instance, args);
if (_result != null) if (_result != null)
@@ -86,8 +79,6 @@ namespace Barotrauma.LuaCs.Services
} }
} }
} }
foreach (var tuple in outOfSocpe) { methodSet.Remove(tuple); }
}
} }
catch (Exception ex) 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 != "") if (identifier != "")
{ {
methodSet.RemoveWhere(tuple => tuple.Item1 == identifier); methodSet.RemoveWhere(tuple => tuple.Item1 == identifier);
} }
methodSet.Add((identifier, patch, owner)); methodSet.Add((identifier, patch));
} }
else if (patch != null) 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 != "") if (identifier != "")
{ {
methodSet.RemoveWhere(tuple => tuple.Item1 == identifier); methodSet.RemoveWhere(tuple => tuple.Item1 == identifier);
} }
methodSet.Add((identifier, patch, owner)); methodSet.Add((identifier, patch));
} }
else if (patch != null) 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(); var funcAddr = (long)method.MethodHandle.GetFunctionPointer();
Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc, IAssemblyPlugin)>> methods; Dictionary<long, HashSet<(string, LuaCsCompatPatchFunc)>> methods;
if (hookType == ILuaCsHook.HookMethodType.Before) methods = compatHookPrefixMethods; if (hookType == ILuaCsHook.HookMethodType.Before) methods = compatHookPrefixMethods;
else if (hookType == ILuaCsHook.HookMethodType.After) methods = compatHookPostfixMethods; else if (hookType == ILuaCsHook.HookMethodType.After) methods = compatHookPostfixMethods;
else throw null; else throw null;