Skip to content

Commit 590fdee

Browse files
committed
- EventService work for use of Hook()/Detour.
1 parent 621f844 commit 590fdee

File tree

5 files changed

+113
-12
lines changed

5 files changed

+113
-12
lines changed
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
namespace Barotrauma.LuaCs.Services.Compatibility;
1+
using System;
2+
3+
namespace Barotrauma.LuaCs.Services.Compatibility;
24

35
public interface ILuaCsHook : ILuaCsShim
46
{
5-
7+
[Obsolete("Use ILuaEventService.Add() instead.")]
8+
void Add(string methodId, string identifier, LuaCsFunc callback, ACsMod mod = null);
9+
[Obsolete("Use ILuaEventService.Add() instead.")]
10+
void Add(string methodId, LuaCsFunc callback, ACsMod mod = null);
11+
bool Exists(string methodId, string identifier);
12+
[Obsolete("Use ILuaEventService.RemoveAll() instead.")]
13+
void Remove(string methodId, string identifier);
14+
T Call<T>(string eventName, params object[] args);
615
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using Barotrauma.LuaCs.Services.Compatibility;
3+
using Barotrauma.LuaCs.Services.Safe;
4+
5+
namespace Barotrauma.LuaCs.Services;
6+
7+
public class EventService : IEventService
8+
{
9+
#region PublicAPI
10+
11+
#region Compatibility
12+
13+
[Obsolete("Use ILuaEventService.Add() instead.")]
14+
void ILuaCsHook.Add(string methodId, string identifier, LuaCsFunc callback, ACsMod mod = null)
15+
{
16+
Add(methodId, identifier, callback);
17+
}
18+
[Obsolete("Use ILuaEventService.Add() instead.")]
19+
void ILuaCsHook.Add(string methodId, LuaCsFunc callback, ACsMod mod = null)
20+
{
21+
Add(methodId, callback);
22+
}
23+
[Obsolete("Use ILuaEventService.RemoveAll() instead.")]
24+
void ILuaCsHook.Remove(string methodId, string identifier)
25+
{
26+
RemoveAll(methodId, identifier);
27+
}
28+
29+
#endregion
30+
31+
public Guid Add(string methodId, string identifier, LuaCsFunc callback)
32+
{
33+
throw new NotImplementedException();
34+
}
35+
36+
public Guid Add(string methodId, LuaCsFunc callback)
37+
{
38+
throw new NotImplementedException();
39+
}
40+
41+
public bool Exists(string methodId, string identifier)
42+
{
43+
throw new NotImplementedException();
44+
}
45+
46+
public void RemoveAll(string methodId, string identifier)
47+
{
48+
throw new NotImplementedException();
49+
}
50+
51+
public T Call<T>(string eventName, params object[] args)
52+
{
53+
throw new NotImplementedException();
54+
}
55+
56+
#endregion
57+
58+
#region InternalAPI
59+
60+
public void Dispose()
61+
{
62+
// TODO release managed resources here
63+
throw new NotImplementedException();
64+
}
65+
66+
public FluentResults.Result Reset()
67+
{
68+
throw new NotImplementedException();
69+
}
70+
71+
#endregion
72+
73+
#region ClassFunctions
74+
75+
private sealed record LuaDetour
76+
{
77+
/// <summary>
78+
/// Unique id for the given hook.
79+
/// </summary>
80+
public Guid CallbackHookId { get; init; }
81+
/// <summary>
82+
/// Lua Function callback for the given event.
83+
/// </summary>
84+
public LuaCsFunc Callback { get; init; }
85+
/// <summary>
86+
/// String identifier given by the hook caller, if available. Not guaranteed to be unique.
87+
/// </summary>
88+
public string Identifier { get; init; }
89+
}
90+
91+
#endregion
92+
}

Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IEventService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Barotrauma.LuaCs.Services.Safe;
1+
using Barotrauma.LuaCs.Services.Compatibility;
2+
using Barotrauma.LuaCs.Services.Safe;
23

34
namespace Barotrauma.LuaCs.Services;
45

Barotrauma/BarotraumaShared/SharedSource/LuaCs/Services/IHookManagementService.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
namespace Barotrauma.LuaCs.Services.Safe;
1+
using System;
2+
using Barotrauma.LuaCs.Services.Compatibility;
23

3-
public interface ILuaEventService : ILuaService
4+
namespace Barotrauma.LuaCs.Services.Safe;
5+
6+
public interface ILuaEventService : ILuaService, ILuaCsHook
47
{
5-
8+
Guid Add(string methodId, string identifier, LuaCsFunc callback);
9+
Guid Add(string methodId, LuaCsFunc callback);
10+
void RemoveAll(string methodId, string identifier);
611
}

0 commit comments

Comments
 (0)