-
Notifications
You must be signed in to change notification settings - Fork 2
/
MouseFix.cs
75 lines (63 loc) · 1.72 KB
/
MouseFix.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
using BepInEx;
using HarmonyLib;
using MouseFix.Patches;
namespace MouseFix {
[BepInPlugin("com.sauler.cms.mousefix", "MouseFix", "2.0.0.0")]
[BepInProcess("cms2018.exe")]
public class MouseFix : BaseUnityPlugin {
#region Unity events
private void Awake() {
LoadConfig();
Patch();
}
private void OnDestroy() {
Unpatch();
}
#endregion
#region Patching
private Harmony harmonyInstance;
private bool patched;
private void Patch() {
if (patched)
return;
harmonyInstance = new Harmony("com.sauler.cms.mousefix");
PatchBackgroundExecution();
PatchMouseMovementAndMouseLock();
patched = true;
Logger.LogInfo("Patching done!");
}
private void PatchBackgroundExecution() {
if (Settings.backgroundExecution.Value) {
harmonyInstance.PatchAll(typeof(BackgroundExecution));
Logger.LogInfo("Applying BackgroundExecution patch");
}
}
private void PatchMouseMovementAndMouseLock() {
if (Settings.mouseEnhancements.Value) {
harmonyInstance.PatchAll(typeof(MouseLock));
harmonyInstance.PatchAll(typeof(MouseMovement));
Logger.LogInfo("Applying MouseMovement and MouseLock patches");
}
}
private void Unpatch() {
if (!patched)
return;
harmonyInstance.UnpatchAll();
patched = false;
}
#endregion
#region Config
private void LoadConfig() {
Settings.backgroundExecution = Config.Bind("General",
"BackgroundExecution",
true,
"Enables or disables background execution.");
Settings.mouseEnhancements = Config.Bind("General",
"MouseEnhancements",
true,
"Enables or disables mouse enhancements.\nCursor movement is fixed and cursor is not locked " +
"in game window when in UI mode");
}
#endregion
}
}