-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModInit.cs
More file actions
44 lines (40 loc) · 1.15 KB
/
ModInit.cs
File metadata and controls
44 lines (40 loc) · 1.15 KB
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
using System;
using HarmonyLib;
using MegaCrit.Sts2.Core.Modding;
using DisplayTheSpire.Logging;
namespace DisplayTheSpire;
[ModInitializer(nameof(Init))]
public static class ModInit
{
private static Harmony? _harmony;
public static void Init()
{
_harmony = new Harmony(DtsConst.HarmonyId);
try
{
_harmony.PatchAll(typeof(ModInit).Assembly);
ModLog.Info("Initialized");
}
catch (Exception e)
{
ModLog.Error("Harmony PatchAll failed", e);
}
}
// The game has no mod-shutdown hook, so this is never invoked in
// normal operation. Kept for hot-reload harnesses and debug tooling.
// UnpatchAll scoped by HarmonyId only removes patches owned by this
// mod, so other mods patching the same targets are not affected.
public static void Shutdown()
{
try
{
_harmony?.UnpatchAll(DtsConst.HarmonyId);
_harmony = null;
ModLog.Info("Shutdown - Harmony patches removed");
}
catch (Exception e)
{
ModLog.Error("Harmony UnpatchAll failed", e);
}
}
}