-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.cs
More file actions
165 lines (136 loc) · 6.45 KB
/
Plugin.cs
File metadata and controls
165 lines (136 loc) · 6.45 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System.IO;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LocalizationManager;
using SkillManager;
using ServerSync;
using UnityEngine;
namespace SkillManagerModTemplate
{
/* Please note, by default this template uses the class and not the DLL load for Skill Manager.
Follow the instructions in the README.md file and the ILRepack.targets file to switch over to using the DLL if you wish. */
[BepInPlugin(ModGUID, ModName, ModVersion)]
public class SkillManagerModTemplatePlugin : BaseUnityPlugin
{
internal const string ModName = "SkillManagerModTemplate";
internal const string ModVersion = "1.0.0";
internal const string Author = "{azumatt}";
private const string ModGUID = Author + "." + ModName;
private static string ConfigFileName = ModGUID + ".cfg";
private static string ConfigFileFullPath = Paths.ConfigPath + Path.DirectorySeparatorChar + ConfigFileName;
internal static string ConnectionError = "";
public static readonly ManualLogSource SkillManagerModTemplateLogger =
BepInEx.Logging.Logger.CreateLogSource(ModName);
private static readonly ConfigSync ConfigSync = new(ModGUID)
{ DisplayName = ModName, CurrentVersion = ModVersion, MinimumRequiredVersion = ModVersion };
public enum Toggle
{
On = 1,
Off = 0
}
public void Awake()
{
// Uncomment the line below to use the LocalizationManager for localizing your mod.
//Localizer.Load(); // Use this to initialize the LocalizationManager (for more information on LocalizationManager, see the LocalizationManager documentation https://github.com/blaxxun-boop/LocalizationManager#example-project).
bool saveOnSet = Config.SaveOnConfigSet;
Config.SaveOnConfigSet = false; // This and the variable above are used to prevent the config from saving on startup for each config entry. This is speeds up the startup process.
_serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On,
"If on, the configuration is locked and can be changed by server admins only.");
_ = ConfigSync.AddLockingConfigEntry(_serverConfigLocked);
Skill
tenacity = new("Tenacity",
"tenacity-icon.png"); // Skill name along with the skill icon. By default the icon is found in the icons folder. Put it there if you wish to load one.
tenacity.Description.English("Reduces damage taken by 0.2% per level.");
tenacity.Name.German("Hartnäckigkeit"); // Use this to localize values for the name
tenacity.Description.German("Reduziert erlittenen Schaden um 0,2% pro Stufe."); // You can do the same for the description
tenacity.Configurable = true;
Assembly assembly = Assembly.GetExecutingAssembly();
Harmony harmony = new(ModGUID);
harmony.PatchAll(assembly);
SetupWatcher();
if (saveOnSet)
{
Config.SaveOnConfigSet = saveOnSet;
Config.Save();
}
// If you want to do something once localization completes, LocalizationManager has a hook for that.
/*Localizer.OnLocalizationComplete += () =>
{
// Do something
ItemManagerModTemplateLogger.LogDebug("OnLocalizationComplete called");
};*/
}
private void OnDestroy()
{
Config.Save();
}
private void SetupWatcher()
{
FileSystemWatcher watcher = new(Paths.ConfigPath, ConfigFileName);
watcher.Changed += ReadConfigValues;
watcher.Created += ReadConfigValues;
watcher.Renamed += ReadConfigValues;
watcher.IncludeSubdirectories = true;
watcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
watcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
if (!File.Exists(ConfigFileFullPath)) return;
try
{
SkillManagerModTemplateLogger.LogDebug("ReadConfigValues called");
Config.Reload();
}
catch
{
SkillManagerModTemplateLogger.LogError($"There was an issue loading your {ConfigFileName}");
SkillManagerModTemplateLogger.LogError("Please check your config entries for spelling and format!");
}
}
#region ConfigOptions
private static ConfigEntry<Toggle> _serverConfigLocked = null!;
private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description,
bool synchronizedSetting = true)
{
ConfigDescription extendedDescription =
new(
description.Description +
(synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"),
description.AcceptableValues, description.Tags);
ConfigEntry<T> configEntry = Config.Bind(group, name, value, extendedDescription);
//var configEntry = Config.Bind(group, name, value, description);
SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry(configEntry);
syncedConfigEntry.SynchronizedConfig = synchronizedSetting;
return configEntry;
}
private ConfigEntry<T> config<T>(string group, string name, T value, string description,
bool synchronizedSetting = true)
{
return config(group, name, value, new ConfigDescription(description), synchronizedSetting);
}
private class ConfigurationManagerAttributes
{
public bool? Browsable = false;
}
#endregion
}
public static class KeyboardExtensions
{
extension(KeyboardShortcut shortcut)
{
public bool IsKeyDown()
{
return shortcut.MainKey != KeyCode.None && Input.GetKeyDown(shortcut.MainKey) && shortcut.Modifiers.All(Input.GetKey);
}
public bool IsKeyHeld()
{
return shortcut.MainKey != KeyCode.None && Input.GetKey(shortcut.MainKey) && shortcut.Modifiers.All(Input.GetKey);
}
}
}
}