This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginMain.cs
68 lines (58 loc) · 1.94 KB
/
PluginMain.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
using System;
using System.Collections.Generic;
using HarmonyLib;
using Exiled.API.Features;
using Exiled.Loader;
using ItemUtils.API.Modifiers;
using ItemUtils.API;
namespace ItemUtils
{
public class PluginMain : Plugin<Config>
{
private static PluginMain Singleton;
public static PluginMain Instance => Singleton;
public override Version Version => new Version(1, 2, 3);
public override Version RequiredExiledVersion => new Version(5, 0, 0);
public override string Author => "rayzer";
public override string Name => "ItemUtils";
private List<ItemModifier> loadedModifiers;
private Harmony harmony;
public override void OnEnabled()
{
Singleton = this;
harmony = new Harmony(Name);
harmony.PatchAll();
LoadModifiers();
base.OnEnabled();
}
public override void OnDisabled()
{
UnloadModifiers();
harmony.UnpatchAll();
harmony = null;
Singleton = null;
base.OnDisabled();
}
//add all the user defined modifiers with their type
public void LoadModifiers()
{
loadedModifiers = new List<ItemModifier>();
SubtypeDeserializer<ItemModifier> sd = new SubtypeDeserializer<ItemModifier>();
List<Type> types = new List<Type>(Assembly.GetTypes());
foreach (KeyValuePair<string, object> map in Config.ItemModifiers)
{
ItemModifier mod = sd.FindValidSubtype(Loader.Serializer.Serialize(map.Value), types);
mod.RegisterEvents();
loadedModifiers.Add(mod);
}
}
public void UnloadModifiers()
{
foreach (ItemModifier mod in loadedModifiers)
{
mod.UnregisterEvents();
}
loadedModifiers = null;
}
}
}