-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModInit.cs
62 lines (52 loc) · 1.59 KB
/
ModInit.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
using System.Collections.Generic;
using System.Reflection;
using ELWS.Core;
using ELWS.Core.Abstractions;
using ELWS.Debugging;
using HarmonyLib;
using PavonisInteractive.TerraInvicta.Debugging;
using PavonisInteractive.TerraInvicta.Systems.Bootstrap;
using UnityModManagerNet;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Local
namespace ELWS;
public class ModInit
{
private static bool _isActive;
private static Harmony _harmonyRef;
private static readonly List<IModClass> ModClasses = new();
private static bool Load(UnityModManager.ModEntry modEntry)
{
modEntry.OnToggle = OnToggle;
_harmonyRef = new Harmony(modEntry.Info.Id);
SetupMod();
return true;
}
private static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
{
_isActive = value;
if (_isActive)
ActivateMod();
else
DeactivateMod();
return true;
}
private static void ActivateMod()
{
ModClasses.ForEach(m => m.SetActive());
_harmonyRef.PatchAll(Assembly.GetExecutingAssembly());
ModState.Load();
UnityModManager.Logger.Log("ELWS Mod Activated.");
}
private static void DeactivateMod()
{
ModClasses.ForEach(m => m.SetActive(false));
_harmonyRef.UnpatchAll(_harmonyRef.Id);
ModState.Reset();
UnityModManager.Logger.Log("ELWS Mod Deactivated.");
}
private static void SetupMod()
{
ModClasses.Add(new TerminalElwsCommands(GlobalInstaller.container.Resolve<Terminal>().controller));
}
}