-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
70 lines (64 loc) · 1.82 KB
/
Main.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
using ModMaker;
using ModMaker.Utility;
using System;
using System.Reflection;
using UnityModManagerNet;
namespace QuickCast
{
#if (DEBUG)
[EnableReloading]
#endif
internal static class Main
{
public static LocalizationManager<DefaultLanguage> Local;
public static ModManager<Core, Settings> Mod;
public static MenuManager Menu;
public static string ModPath;
private static bool Load(UnityModManager.ModEntry modEntry)
{
Local = new LocalizationManager<DefaultLanguage>();
Mod = new ModManager<Core, Settings>();
Menu = new MenuManager();
ModPath = modEntry.Path;
modEntry.OnToggle = OnToggle;
#if (DEBUG)
modEntry.OnUnload = Unload;
return true;
}
private static bool Unload(UnityModManager.ModEntry modEntry)
{
Mod.Disable(modEntry, true);
Menu = null;
Mod = null;
Local = null;
return true;
}
#else
return true;
}
#endif
private static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
{
if (value)
{
Assembly assembly = Assembly.GetExecutingAssembly();
Local.Enable(modEntry);
Mod.Enable(modEntry, assembly);
Menu.Enable(modEntry, assembly);
}
else
{
Menu.Disable(modEntry);
Mod.Disable(modEntry, false);
Local.Disable(modEntry);
ReflectionCache.Clear();
}
return true;
}
internal static Exception Error(string message)
{
Mod.Error(message);
return new InvalidOperationException(message);
}
}
}