-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWrapper.cs
More file actions
88 lines (74 loc) · 2.59 KB
/
Wrapper.cs
File metadata and controls
88 lines (74 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#region
using System.Reflection;
using Dalamud.Plugin;
#endregion
namespace WrathCombo.API;
public static partial class WrathIPCWrapper
{
[Flags]
public enum ErrorType
{
None = 0,
APIBehindIPC = 1 << 0,
IPCNotReady = 1 << 1,
GenericIpc = 1 << 2,
Unexpected = 1 << 3,
All = ~0,
}
private static IDalamudPluginInterface? Interface
{
get
{
if (field != null)
return field;
// Try to get the interface from ECommons if possible
try
{
const string assemblyName = "ECommons";
const StringComparison lower = StringComparison.OrdinalIgnoreCase;
var eCommonsAsm = AppDomain.CurrentDomain
.GetAssemblies()
.FirstOrDefault(a =>
a.GetName().Name?.Equals(assemblyName, lower) == true);
if (eCommonsAsm is null) return null;
const string svcFullName = "ECommons.DalamudServices.Svc";
var svcType = eCommonsAsm
.GetType(svcFullName, throwOnError: false, ignoreCase: true);
if (svcType is null) return null;
var isInit = svcType.GetField("IsInitialized",
BindingFlags.NonPublic | BindingFlags.Static)
?.GetValue(null) as bool?;
if (isInit != true) return null;
var raw = svcType.GetProperty("PluginInterface",
BindingFlags.Public | BindingFlags.Static)
?.GetValue(null);
if (raw is null) return null;
return field = raw as IDalamudPluginInterface;
}
catch
{
return null;
}
}
set;
}
private static ErrorType SuppressedErrorTypes { get; set; }
private static bool Suppressing(ErrorType flags) =>
SuppressedErrorTypes.HasFlag(flags);
/// <remarks>
/// Not required if ECommons is present and initialized.
/// </remarks>
public static void Init(IDalamudPluginInterface pluginInterface,
ErrorType suppressedErrorTypes = ErrorType.None)
{
Interface = pluginInterface;
SuppressedErrorTypes = suppressedErrorTypes;
}
/// <remarks>
/// Would require ECommons to be present and initialized.
/// </remarks>
public static void Init(ErrorType suppressedErrorTypes)
{
SuppressedErrorTypes = suppressedErrorTypes;
}
}