-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
181 lines (154 loc) · 8.53 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
179
180
181
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using LocalizationManager;
using StatusEffectManager;
using ServerSync;
using UnityEngine;
namespace StatusEffectManagerModTemplate
{
[BepInPlugin(ModGUID, ModName, ModVersion)]
public class StatusEffectManagerModTemplatePlugin : BaseUnityPlugin
{
internal const string ModName = "StatusEffectManagerModTemplate";
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 StatusEffectManagerModTemplateLogger =
BepInEx.Logging.Logger.CreateLogSource(ModName);
private static readonly ConfigSync ConfigSync = new(ModGUID)
{ DisplayName = ModName, CurrentVersion = ModVersion, MinimumRequiredVersion = ModVersion };
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("General", "Force Server Config", true, "Force Server Config");
_ = ConfigSync.AddLockingConfigEntry(_serverConfigLocked);
CustomSE mycooleffect = new("Toxicity");
mycooleffect.Name.English("Toxicity");
mycooleffect.Type = EffectType.Consume;
mycooleffect.IconSprite = null;
mycooleffect.Name.German("Toxizität");
mycooleffect.Effect.m_startMessageType = MessageHud.MessageType.TopLeft;
mycooleffect.Effect.m_startMessage = "My Cool Status Effect Started";
mycooleffect.Effect.m_stopMessageType = MessageHud.MessageType.TopLeft;
mycooleffect.Effect.m_stopMessage = "Not cool anymore, ending effect.";
mycooleffect.Effect.m_tooltip = "<color=orange>Toxic damage over time</color>";
mycooleffect.AddSEToPrefab(mycooleffect, "SwordIron");
CustomSE drunkeffect = new("se_drunk", "se_drunk_effect");
drunkeffect.Name.English("Drunk"); // You can use this to fix the display name in code
drunkeffect.Icon = "DrunkIcon.png"; // Use this to add an icon (64x64) for the status effect. Put your icon in an "icons" folder
drunkeffect.Name.German("Betrunken"); // Or add translations for other languages
drunkeffect.Effect.m_startMessageType = MessageHud.MessageType.Center; // Specify where the start effect message shows
drunkeffect.Effect.m_startMessage = "I'm drunk!"; // What the start message says
drunkeffect.Effect.m_stopMessageType = MessageHud.MessageType.Center; // Specify where the stop effect message shows
drunkeffect.Effect.m_stopMessage = "Sober...again."; // What the stop message says
drunkeffect.Effect.m_tooltip = "<color=red>Your vision is blurry</color>"; // Tooltip that will describe the effect applied to the player
drunkeffect.AddSEToPrefab(drunkeffect, "TankardAnniversary"); // Adds the status effect to the Anniversary Tankard. Applies when equipped.
// Create a new status effect in code and apply it to a prefab.
CustomSE codeSE = new("CodeStatusEffect");
codeSE.Name.English("New Effect");
codeSE.Type = EffectType.Consume; // Set the type of status effect this should be.
codeSE.Icon = "ModDevPower.png";
codeSE.Name.German("Betrunken"); // Or add translations for other languages
codeSE.Effect.m_startMessageType = MessageHud.MessageType.Center; // Specify where the start effect message shows
codeSE.Effect.m_startMessage = "Mod Dev power, granted."; // What the start message says
codeSE.Effect.m_stopMessageType = MessageHud.MessageType.Center; // Specify where the stop effect message shows
codeSE.Effect.m_stopMessage = "Mod Dev power, removed."; // What the stop message says
codeSE.Effect.m_tooltip = "<color=green>You now have Mod Dev POWER!</color>"; // Tooltip that will describe the effect applied to the player
codeSE.AddSEToPrefab(codeSE, "SwordCheat"); // Adds the status effect to the Cheat Sword. Applies when equipped.
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
{
StatusEffectManagerModTemplateLogger.LogDebug("ReadConfigValues called");
Config.Reload();
}
catch
{
StatusEffectManagerModTemplateLogger.LogError($"There was an issue loading your {ConfigFileName}");
StatusEffectManagerModTemplateLogger.LogError(
"Please check your config entries for spelling and format!");
}
}
#region ConfigOptions
private static ConfigEntry<bool>? _serverConfigLocked;
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
{
[UsedImplicitly] public int? Order = null!;
[UsedImplicitly] public bool? Browsable = null!;
[UsedImplicitly] public string? Category = null!;
[UsedImplicitly] public Action<ConfigEntryBase>? CustomDrawer = null!;
}
class AcceptableShortcuts : AcceptableValueBase
{
public AcceptableShortcuts() : base(typeof(KeyboardShortcut))
{
}
public override object Clamp(object value) => value;
public override bool IsValid(object value) => true;
public override string ToDescriptionString() =>
"# Acceptable values: " + string.Join(", ", UnityInput.Current.SupportedKeyCodes);
}
#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);
}
}
}