-
Notifications
You must be signed in to change notification settings - Fork 4
/
Main.cs
108 lines (92 loc) · 3.01 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
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
using BlueprintCore.Blueprints.Configurators.Root;
using BlueprintCore.Utils;
using HarmonyLib;
using Kingmaker.Blueprints.JsonSystem;
using System;
using UnityModManagerNet;
using MoreCantrips.Cantrips;
namespace MoreCantrips
{
public static class Main
{
public static bool Enabled;
private static readonly Logging.Logger Logger = Logging.GetLogger(nameof(Main));
public static void Log(string log)
{
Logger.Log(log);
}
public static bool Load(UnityModManager.ModEntry modEntry)
{
try
{
modEntry.OnToggle = OnToggle;
var harmony = new Harmony(modEntry.Info.Id);
harmony.PatchAll();
Logger.Log("Finished patching.");
}
catch (Exception e)
{
Logger.LogException("Failed to patch", e);
}
return true;
}
public static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
{
Enabled = value;
return true;
}
[HarmonyPatch(typeof(BlueprintsCache))]
static class BlueprintsCaches_Patch
{
private static bool Initialized = false;
[HarmonyPriority(Priority.First)]
[HarmonyPatch(nameof(BlueprintsCache.Init)), HarmonyPostfix]
static void Init()
{
try
{
if (Initialized)
{
Logger.Log("Already configured blueprints.");
return;
}
Initialized = true;
Logger.Log("Configuring blueprints for More Cantrips");
Settings.Make();
FireSpells.Make();
SonicSpells.Make();
AcidSpells.Make();
ShockSpells.Make();
IceSpells.Make();
}
catch (Exception e)
{
Logger.LogException("Failed to configure blueprints.", e);
}
}
}
[HarmonyPatch(typeof(StartGameLoader))]
static class StartGameLoader_Patch
{
private static bool Initialized = false;
[HarmonyPatch(nameof(StartGameLoader.LoadPackTOC)), HarmonyPostfix]
static void LoadPackTOC()
{
try
{
if (Initialized)
{
Logger.Log("Already configured delayed blueprints.");
return;
}
Initialized = true;
RootConfigurator.ConfigureDelayedBlueprints();
}
catch (Exception e)
{
Logger.LogException("Failed to configure delayed blueprints.", e);
}
}
}
}
}