It works. Except (HookMethod->Harmony: L189) is throwing NRE.

This commit is contained in:
MapleWheels
2026-02-02 20:45:09 -05:00
committed by Maplewheels
parent 2eb593f461
commit 06348d3ba5
7 changed files with 69 additions and 66 deletions
@@ -1,5 +1,5 @@
extern alias Client;
extern alias Server;
using Client::Barotrauma.LuaCs.Services;
using Client::Barotrauma;
using MoonSharp.Interpreter;
@@ -8,6 +8,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Server::Barotrauma.LuaCs.Services.Compatibility;
using Xunit;
namespace TestProject.LuaCs
@@ -64,14 +65,14 @@ namespace TestProject.LuaCs
string methodName,
string[]? parameters,
string function,
EventService.HookMethodType patchType)
ILuaCsHook.HookMethodType patchType)
{
var args = BuildHookPatchArgsList(patchId, className, methodName, parameters);
args.Add(function);
args.Add(patchType switch
{
EventService.HookMethodType.Before => "Hook.HookMethodType.Before",
EventService.HookMethodType.After => "Hook.HookMethodType.After",
ILuaCsHook.HookMethodType.Before => "Hook.HookMethodType.Before",
ILuaCsHook.HookMethodType.After => "Hook.HookMethodType.After",
_ => throw new NotImplementedException(),
});
throw new NotImplementedException();
@@ -84,13 +85,13 @@ namespace TestProject.LuaCs
string className,
string methodName,
string[]? parameters,
EventService.HookMethodType patchType)
ILuaCsHook.HookMethodType patchType)
{
var args = BuildHookPatchArgsList(patchId, className, methodName, parameters);
args.Add(patchType switch
{
EventService.HookMethodType.Before => "Hook.HookMethodType.Before",
EventService.HookMethodType.After => "Hook.HookMethodType.After",
ILuaCsHook.HookMethodType.Before => "Hook.HookMethodType.Before",
ILuaCsHook.HookMethodType.After => "Hook.HookMethodType.After",
_ => throw new NotImplementedException(),
});
throw new NotImplementedException();
@@ -104,7 +105,7 @@ namespace TestProject.LuaCs
function(instance, ptable)
{body}
end
", EventService.HookMethodType.Before);
", ILuaCsHook.HookMethodType.Before);
Assert.Equal(DataType.String, returnValue.Type);
return new(returnValue.String, () => luaCs.RemovePrefix<T>(returnValue.String, methodName, parameters));
}
@@ -116,7 +117,7 @@ namespace TestProject.LuaCs
function(instance, ptable)
{body}
end
", EventService.HookMethodType.After);
", ILuaCsHook.HookMethodType.After);
Assert.Equal(DataType.String, returnValue.Type);
return new(returnValue.String, () => luaCs.RemovePostfix<T>(returnValue.String, methodName, parameters));
}
@@ -124,7 +125,7 @@ namespace TestProject.LuaCs
public static bool RemovePrefix<T>(this LuaCsSetup luaCs, string patchId, string methodName, string[]? parameters = null)
{
var className = typeof(T).FullName!;
var returnValue = luaCs.DoHookRemovePatch(patchId, className, methodName, parameters, EventService.HookMethodType.Before);
var returnValue = luaCs.DoHookRemovePatch(patchId, className, methodName, parameters, ILuaCsHook.HookMethodType.Before);
Assert.Equal(DataType.Boolean, returnValue.Type);
return returnValue.Boolean;
}
@@ -132,7 +133,7 @@ namespace TestProject.LuaCs
public static bool RemovePostfix<T>(this LuaCsSetup luaCs, string patchId, string methodName, string[]? parameters = null)
{
var className = typeof(T).FullName!;
var returnValue = luaCs.DoHookRemovePatch(patchId, className, methodName, parameters, EventService.HookMethodType.After);
var returnValue = luaCs.DoHookRemovePatch(patchId, className, methodName, parameters, ILuaCsHook.HookMethodType.After);
Assert.Equal(DataType.Boolean, returnValue.Type);
return returnValue.Boolean;
}