-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
178 lines (155 loc) · 6.9 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
using System.IO;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using CreatureManager;
using LocalizationManager;
using ServerSync;
using UnityEngine;
namespace CreatureManagerModTemplate
{
[BepInPlugin(ModGUID, ModName, ModVersion)]
public class CreatureManagerModTemplatePlugin : BaseUnityPlugin
{
internal const string ModName = "CreatureManagerModTemplate";
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 = "";
private readonly Harmony _harmony = new(ModGUID);
public static readonly ManualLogSource CreatureManagerModTemplateLogger =
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).
_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);
Creature wereBearBlack = new("werebear", "WereBearBlack")
{
ConfigurationEnabled = false,
CanSpawn = false,
CanBeTamed = false,
FoodItems = "",
SpecificSpawnTime = SpawnTime.Day,
RequiredAltitude = default,
RequiredOceanDepth = default,
RequiredGlobalKey = GlobalKey.None,
Biome = Heightmap.Biome.Meadows,
SpecificSpawnArea = CreatureManager.SpawnArea.Center,
GroupSize = new Range(1, 2),
CheckSpawnInterval = 600,
SpawnChance = 0,
ForestSpawn = Forest.Yes,
RequiredWeather = Weather.Rain | Weather.Fog,
SpawnAltitude = 0,
CanHaveStars = false,
AttackImmediately = false,
Maximum = 2
};
wereBearBlack.Localize()
.English("Black Werebear")
.German("Schwarzer Werbär")
.French("Ours-Garou Noir");
wereBearBlack.Drops["Wood"].Amount = new Range(1, 2);
wereBearBlack.Drops["Wood"].DropChance = 100f;
Creature wereBearRed = new("werebear", "WereBearRed")
{
Biome = Heightmap.Biome.AshLands,
GroupSize = new Range(1, 1),
CheckSpawnInterval = 900,
AttackImmediately = true,
RequiredGlobalKey = GlobalKey.KilledYagluth,
};
wereBearRed.Localize()
.English("Red Werebear")
.German("Roter Werbär")
.French("Ours-Garou Rouge");
wereBearRed.Drops["Coal"].Amount = new Range(1, 2);
wereBearRed.Drops["Coal"].DropChance = 100f;
wereBearRed.Drops["Flametal"].Amount = new Range(1, 1);
wereBearRed.Drops["Flametal"].DropChance = 10f;
Assembly assembly = Assembly.GetExecutingAssembly();
_harmony.PatchAll(assembly);
SetupWatcher();
}
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
{
CreatureManagerModTemplateLogger.LogDebug("ReadConfigValues called");
Config.Reload();
}
catch
{
CreatureManagerModTemplateLogger.LogError($"There was an issue loading your {ConfigFileName}");
CreatureManagerModTemplateLogger.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
{
public static bool IsKeyDown(this KeyboardShortcut shortcut)
{
return shortcut.MainKey != KeyCode.None && Input.GetKeyDown(shortcut.MainKey) && shortcut.Modifiers.All(Input.GetKey);
}
public static bool IsKeyHeld(this KeyboardShortcut shortcut)
{
return shortcut.MainKey != KeyCode.None && Input.GetKey(shortcut.MainKey) && shortcut.Modifiers.All(Input.GetKey);
}
}
}