-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
114 lines (101 loc) · 4.24 KB
/
Plugin.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
namespace touchscreen;
[BepInPlugin("me.pm.TheDeadSnake", "TouchScreen", "1.1.3")]
[BepInProcess("Lethal Company.exe")]
[BepInDependency("LethalExpansion", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("com.github.lethalmods.lethalexpansioncore", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("ShaosilGaming.GeneralImprovements", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("com.rune580.LethalCompanyInputUtils", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("io.daxcess.lcvr", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("com.github.zehsteam.ToilHead", BepInDependency.DependencyFlags.SoftDependency)]
public class Plugin : BaseUnityPlugin {
internal static ManualLogSource LOGGER;
internal delegate R Func<R, T>(T value);
internal delegate R Supplier<R>();
// GeneralImprovements - support
internal static Func<Bounds, GameObject> CREATE_BOUNDS;
// 3rd party plugin support (to disable/enable this plugin)
private static bool _override = true;
private static bool _onPlanet = false;
public static bool IsActive {
get => _onPlanet && (_override || ConfigUtil.IGNORE_OVERRIDE);
set {
if (_override != value) {
_override = value;
MethodBase prevFrame = (new StackTrace()).GetFrame(1).GetMethod();
Plugin.LOGGER.LogInfo(String.Format("Touchscreen was {0} by {1}.{2}.{3}",
value ? "enabled" : "disabled",
prevFrame.ReflectedType.Namespace,
prevFrame.ReflectedType.Name,
prevFrame.Name
));
}
}
}
/*
Enable / Disable Touchscreen when not on a planet
*/
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
if (PlanetUtil.IsPlanet(scene)) {
GameObject obj = StartOfRound.Instance?.mapScreen?.mesh.gameObject;
if (obj != null && obj.GetComponent<ScreenScript>() == null) {
obj.AddComponent<ScreenScript>();
}
_onPlanet = true;
}
}
private void OnSceneUnloaded(Scene scene) {
if (_onPlanet)
_onPlanet = false;
}
// Plugin Startup
private void Awake() {
Plugin.LOGGER = this.Logger;
string pluginFolder = Path.Combine(Paths.PluginPath, "TheDeadSnake-Touchscreen");
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
// Load config values
ConfigUtil.Setup(this.Config, pluginFolder);
InputUtil.Setup();
// Lethal Expansion / Lethal Expansion (core) support
PlanetUtil.checkPlugins();
// GeneralImprovements support
Supplier<bool> _gi = () => GeneralImprovements.Plugin.UseBetterMonitors.Value;
if (Chainloader.PluginInfos.TryGetValue("ShaosilGaming.GeneralImprovements", out PluginInfo gi) && _gi.Invoke()) {
CREATE_BOUNDS = x => new Bounds(
new Vector3(
x.transform.position.x + -.2f,
x.transform.position.y + -.05f,
x.transform.position.z + .03f
),
new Vector3(0, 1.05f, 1.36f)
);
Plugin.LOGGER.LogInfo($" > Hooked into GeneralImprovements {gi.Metadata.Version}");
} else {
CREATE_BOUNDS = x => new Bounds(
new Vector3(
x.transform.position.x + .06f,
x.transform.position.y + -.05f,
x.transform.position.z + .84f
),
new Vector3(0, 1.05f, 1.36f)
);
}
// ToilHead support
if (Chainloader.PluginInfos.TryGetValue("com.github.zehsteam.ToilHead", out PluginInfo ti)) {
ToilHeadUtil.Setup();
Plugin.LOGGER.LogInfo($" > Hooked into ToilHead {ti.Metadata.Version}");
}
LOGGER.LogInfo("Enabled TouchScreen");
}
}