-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
109 lines (93 loc) · 3.65 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
using System.IO;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using System.Reflection;
using HideMUI.Utils;
namespace HideMUI
{
[BepInPlugin("moltenhead.HideMUI", "Hide MUI", "1.0.0")]
[BepInProcess("valheim.exe")]
public class Plugin : BaseUnityPlugin
{
public static readonly ManualLogSource HMUILogger = BepInEx.Logging.Logger.CreateLogSource("HideMUI");
private readonly Harmony _harmony = new Harmony("moltenhead.HideMUI");
private static readonly string configFileName = "moltenhead.HideMUI.cfg";
private static readonly string configFileFullPath = Paths.ConfigPath + Path.DirectorySeparatorChar + configFileName;
public static ConfigEntry<bool> m_crosshairActive;
public static ConfigEntry<bool> m_stealthGUIActive;
void Awake()
{
InitializeConfig();
_harmony.PatchAll(Assembly.GetExecutingAssembly());
ConfigWatcher();
}
private void InitializeConfig()
{
base.Config.SaveOnConfigSet = true;
m_crosshairActive = base.Config.Bind("General", "ActivateCrosshair", false, new ConfigDescription("Activates the main crosshair - default is deactivated (false)."));
m_stealthGUIActive = base.Config.Bind("General", "ActivateStealthGUI", false, new ConfigDescription("Activates the stealth indicator and bar - default is deactivated (false)."));
}
private void ConfigWatcher()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, configFileName);
fileSystemWatcher.Changed += OnConfigChanged;
fileSystemWatcher.Created += OnConfigChanged;
fileSystemWatcher.Renamed += OnConfigChanged;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void OnConfigChanged(object sender, FileSystemEventArgs e)
{
if (!File.Exists(configFileFullPath))
{
return;
}
try
{
HMUILogger.LogDebug("OnConfigChanged called..");
base.Config.Reload();
}
catch
{
HMUILogger.LogError("There was an issue loading your " + configFileName);
HMUILogger.LogError("Please check your config entries for spelling and format!");
}
}
}
[HarmonyPatch]
public static class HudPatch
{
[HarmonyPatch(typeof(Hud), "Awake")]
public static class HudAwake_Patch
{
public static void Postfix(Hud __instance)
{
UI.UpdateHud(__instance);
}
}
[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
public static class HudUpdateCrosshair_Patch
{
public static void Postfix(Hud __instance, Player player)
{
if (player != Player.m_localPlayer) { return; }
UI.setActiveCrosshair(__instance, Plugin.m_crosshairActive.Value);
}
}
[HarmonyPatch(typeof(Hud), "UpdateStealth")]
public static class HudUpdateStealth_Patch
{
public static bool Prefix(Hud __instance, Player player)
{
if (player != Player.m_localPlayer || Plugin.m_stealthGUIActive.Value) {
return true;
}
UI.setActiveStealthHud(__instance, false);
return false;
}
}
}
}