-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModTemplatePlugin.cs
More file actions
59 lines (45 loc) · 2.08 KB
/
ModTemplatePlugin.cs
File metadata and controls
59 lines (45 loc) · 2.08 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
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using ServerSync;
namespace ModTemplate;
[BepInPlugin(ModGuid, ModName, ModVersion)]
public class ModTemplatePlugin : BaseUnityPlugin
{
public const string ModName = "ModTemplate";
public const string ModVersion = "1.0.0";
private const string ModAuthor = "RepaceMe";
private const string ModGuid = ModAuthor + "." + ModName;
private readonly Harmony _harmony = new(ModGuid);
[UsedImplicitly] public static readonly ManualLogSource ModTemplateLogger =
BepInEx.Logging.Logger.CreateLogSource(ModName);
private static readonly ConfigSync ConfigSync = new(ModGuid)
{ DisplayName = ModName, CurrentVersion = ModVersion };
private static ConfigEntry<bool> _configLocked = null!;
private void Awake()
{
_configLocked = CreateConfig("1 - General", "Lock Configuration", true,
"If 'true' and playing on a server, config can only be changed on server-side configuration, " +
"clients cannot override");
ConfigSync.AddLockingConfigEntry(_configLocked);
// Plugin startup logic
Logger.LogInfo($"Plugin {ModGuid} is loaded!");
Assembly assembly = Assembly.GetExecutingAssembly();
_harmony.PatchAll(assembly);
}
private ConfigEntry<T> CreateConfig<T>(string group, string parameterName, T value,
ConfigDescription description,
bool synchronizedSetting = true)
{
ConfigEntry<T> configEntry = Config.Bind(group, parameterName, value, description);
SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry(configEntry);
syncedConfigEntry.SynchronizedConfig = synchronizedSetting;
return configEntry;
}
private ConfigEntry<T> CreateConfig<T>(string group, string parameterName, T value, string description,
bool synchronizedSetting = true) => CreateConfig(group, parameterName, value,
new ConfigDescription(description), synchronizedSetting);
}