-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathVoiceAttackPluginWrapper.cs
95 lines (76 loc) · 3.37 KB
/
VoiceAttackPluginWrapper.cs
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
89
90
91
92
93
94
95
using EliteVA.Logging;
namespace EliteVA;
public class VoiceAttackPluginWrapper
{
public static Guid VA_Id() => new("189a4e44-caf1-459b-b62e-fabc60a12986");
public static string VA_DisplayName() => "EliteAPI";
public static string VA_DisplayInfo() => "EliteAPI is a VoiceAttack plugin for Elite Dangerous made by Somfic";
public static void VA_Init1(dynamic vaProxy)
{
// Find type that implements VoiceAttackPlugin
var pluginType = typeof(VoiceAttackPluginWrapper).Assembly
.GetTypes()
.FirstOrDefault(t => t.IsSubclassOf(typeof(VoiceAttackPlugin)));
if(pluginType == null)
throw new InvalidOperationException("No class found that inherits VoiceAttackPlugin.");
VoiceAttackPlugin.Instance = (VoiceAttackPlugin) Activator.CreateInstance(pluginType)!;
if(VoiceAttackPlugin.Instance == null)
throw new InvalidOperationException("No VoiceAttackPlugin instance found.");
VoiceAttackPlugin.Proxy = new VoiceAttackProxy(vaProxy);
try
{
VoiceAttackPlugin.Instance.OnStart(VoiceAttackPlugin.Proxy).GetAwaiter().GetResult();
}
catch (Exception e)
{
VoiceAttackPlugin.Instance.Log(VoiceAttackColor.Red, "Error during plugin initialisation. See logs for further information");
var path = Path.Combine(VoiceAttackPlugin.Dir, "Logs", "STARTUP ERROR.log");
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? VoiceAttackPlugin.Dir);
File.WriteAllText(path, e.ToString());
}
}
public static void VA_Invoke1(dynamic vaProxy)
{
if(VoiceAttackPlugin.Instance == null)
throw new InvalidOperationException("No VoiceAttackPlugin instance found.");
VoiceAttackPlugin.Proxy = new VoiceAttackProxy(vaProxy);
var context = VoiceAttackPlugin.Proxy.Context;
try
{
VoiceAttackPlugin.Instance.OnInvoke(VoiceAttackPlugin.Proxy, context).GetAwaiter().GetResult();
}
catch (Exception e)
{
VoiceAttackPlugin.Instance.Log(VoiceAttackColor.Red, "Error during plugin invocation", e);
}
}
public static void VA_StopCommand()
{
if(VoiceAttackPlugin.Instance == null)
throw new InvalidOperationException("No VoiceAttackPlugin instance found.");
if(VoiceAttackPlugin.Proxy == null)
throw new InvalidOperationException("No VoiceAttackProxy instance found.");
try
{
VoiceAttackPlugin.Instance.OnCommandStopped(VoiceAttackPlugin.Proxy).GetAwaiter().GetResult();
}
catch (Exception e)
{
VoiceAttackPlugin.Instance.Log(VoiceAttackColor.Red, "Error during command stop", e);
}
}
public static void VA_Exit1(dynamic vaProxy)
{
if(VoiceAttackPlugin.Instance == null)
throw new InvalidOperationException("No VoiceAttackPlugin instance found.");
VoiceAttackPlugin.Proxy = new VoiceAttackProxy(vaProxy);
try
{
VoiceAttackPlugin.Instance.OnStop(VoiceAttackPlugin.Proxy).GetAwaiter().GetResult();
}
catch (Exception e)
{
VoiceAttackPlugin.Instance.Log(VoiceAttackColor.Red, "Error during plugin exit", e);
}
}
}