-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlugin.cs
More file actions
96 lines (85 loc) · 2.91 KB
/
Plugin.cs
File metadata and controls
96 lines (85 loc) · 2.91 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
89
90
91
92
93
94
95
96
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Sandbox;
using VRage.Utils;
using VRage.Plugins;
using HarmonyLib;
using Sandbox.Graphics.GUI;
using WootingAnalogSDKNET;
using WootingPlugin.Gui;
namespace WootingPlugin
{
public class Plugin : IPlugin
{
public static Plugin Instance { get; private set; }
public void OpenConfigDialog()
{
MyGuiSandbox.AddScreen(new MyGuiScreenPluginConfig());
}
public void Init(object gameInstance = null)
{
Instance = this;
MyLogExtensions.Info(MySandboxGame.Log, "WootingPlugin: Patching methods");
try
{
var harmony = new Harmony("WootingPlugin");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
catch (Exception e)
{
MyLogExtensions.Error(MySandboxGame.Log, $"WootingPlugin: Caught {e}:{e.Message} while patching methods.\nDisabling plugin");
return;
}
try
{
var (numDev, result) = WootingAnalogSDK.Initialise();
if (result == WootingAnalogResult.Ok)
{
MyLogExtensions.Info(MySandboxGame.Log, $"WootingPlugin initialized successfully, {numDev} device(s)");
}
else
{
MyLogExtensions.Error(MySandboxGame.Log, $"Failed to initialize WootingPlugin: {result}");
return;
}
if (numDev < 1)
{
DeviceFailed();
}
else
{
Patch_GetGameControlAnalogState.ReadAnalog = true;
}
}
catch (SEHException)
{
MyLogExtensions.Error(MySandboxGame.Log, "WootingPlugin: WootingAnalogSDK failed to initialize due to an internal error");
return;
}
WootingAnalogSDK.SetKeycodeMode(KeycodeType.VirtualKey);
}
public void DeviceFailed()
{
MyLogExtensions.Error(MySandboxGame.Log, "WootingPlugin: No keyboard detected");
WootingAnalogSDK.DeviceEvent += DeviceEvent;
Patch_GetGameControlAnalogState.ReadAnalog = false;
}
public void DeviceEvent(DeviceEventType type, DeviceInfo info)
{
if (type == DeviceEventType.Connected)
{
WootingAnalogSDK.DeviceEvent -= DeviceEvent;
Patch_GetGameControlAnalogState.ReadAnalog = true;
MyLogExtensions.Info(MySandboxGame.Log, "WootingPlugin: Keyboard detected");
}
}
public void Update() { }
public void Dispose()
{
WootingAnalogSDK.UnInitialise();
}
}
}